Skip to content

[Question] Detecting VimTeX Environment with Lua #2501

@evesdropper

Description

@evesdropper

Description

More of a question than an issue, but I couldn't really find a clear answer through other searches previously and I don't really know where else I can ask. I moved to LuaSnip a while earlier and I want to be able to create environment-dependent snippets. There's a way to do this on Python, but the Lua "translation" doesn't seem to work - snippets just activate regardless of environment.

Original Python:

def env(name):
    [x,y] = vim.eval("vimtex#env#is_inside('" + name + "')") 
    return x != '0' and y != '0'

Rough Lua Translation:

 local function env(name) 
     if vim.api.nvim_eval("vimtex#env#is_inside('" .. name .. "')") ~= nil then 
        return 1
     end
     return 0
end

local function tikz()
    return env("tikzpicture")
end

If someone has more information on the syntax command (if I'm using the right one - I did look at the API reference and it seemed to be outdated but still worked on UltiSnips last I checked) and figuring out what it returns so this can be manipulated for Lua, it would be helpful for things like bullet points in enumerate/itemize or TikZ specific snippets in, that would be really helpful. Thanks!

VimtexInfo

System info:
  OS: Linux 5.19.11-arch1-1
  Vim version: NVIM v0.7.2
  Has clientserver: true
  Servername: /tmp/nvimGtE41c/0

VimTeX project: test
  base: test.tex
  root: /home/revise/Documents/test
  tex: /home/revise/Documents/test/test.tex
  main parser: current file verified
  document class: article
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    build_dir: out
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: General
  qf method: LaTeX logfile

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions