0

I've been trying to configure vim-tex working on the NvChad configs. I got the :VimtexCompile working and giving me output pdf. But the usual <leader>ll is giving me these errors. Also in vim {{ would expand to \left{ \right}. It's not working with NeoVim. I'm using LuaSnip with friendly-snippets with the default config in NvChad.

This is my vim-tex config. Similar config is working fine in Vim

vim.g.tex_flavor = 'latex'
vim.g.vimtex_view_method = 'sioyek'
vim.g.vimtex_synctex = 1
vim.g.tex_conceal = 'abdmg'
vim.g.vimtex_compile_latexmk = {
  executable = "latexmk",
  OPTIONS = {
    "-xelatex",
    "-fine-line-error",
    "-synctex=1",
    "-interactions=nonstopmode",
  },
}

I need to do the following

  1. Get the <leader>ll compiling my latex
  2. Expand {{, ((, [[ to their respective latex code

Thank you in advance

3
  • Welcome to Vim :-) I'm not a Vim-TeX specialist but I fear that the information you give in your question will not be enough for the expert to reproduce the problem. It would be good if you could simplify your configuration at the maximum and describe it in your question (plugin installed, init.vim and friends). Feb 6 at 15:37
  • It's VimTeX, not vim-tex. :) I just responded to this question on Reddit (reddit.com/r/neovim/comments/10v7s68/…). I'm copying the response here, but I don't really like it when people are asking the same question at multiple sites without linking between them to make it clear! Feb 6 at 22:19
  • 1
    Welcome vi.SE codehumor …It's like NvChad is giving you more trouble than being useful :s
    – gildux
    Feb 8 at 20:23

2 Answers 2

0

The plugin is called VimTeX, not vim-tex.

But the usual <leader>ll is giving me these errors.

These errors are not from VimTeX. For some reason, it seems you have LaTeX-Suite (aka vim-latex) installed as well. You should remove that plugin from your system and try again.

If you do :map <leader>ll in a LaTeX file, you should see that it is mapped to <plug>(vimtex-compile). However, since you are having a plugin conflict, I'm quite confident that you will see something else.

Also in vim {{ would expand to \left{ \right}. It's not working with NeoVim. I'm using LuaSnip with friendly-snippets with the default config in NvChad.

You either 1) used LaTeX-Suite which has this feature built-in, 2) used a snippet plugin like UltiSnips and had this snippet, or 3) something else. To make it work now, you need to add it as a snippet with LuaSnip. I don't use that and can't help with it, sorry.

This is my vim-tex config.

You should remove vim.g.tex_flavor and vim.g.tex_conceal, they are not necessary. vim.g.vimtex_synctex is not a valid VimTeX option and has never been one. Finally, you should fix vim.g.vimtex_compile_latexmk because 1) the name is wrong, and 2) you are using it wrongly. Please read :help vimtex_compiler_latexmk and :help vimtex_compiler_latexmk_engines.

I believe this is the configuration you want:

vim.g.vimtex_view_method = 'sioyek'
vim.g.vimtex_compile_latexmk_engines = {
  ['_'] = '-xelatex',
}
0

2. Expand {{, ((, [[ to their respective LaTeX code with LuaSnip

I assume you have installed LuaSnip and VimTeX and configured them as desired.

For the automatic expansion you need

require("luasnip").config.setup({ enable_autosnippets = true })

Add following LuaSnip snippets e.g. to ~/.config/nvim/luasnippets/tex.lua:

-- Typical Abbreviations
local ls = require("luasnip")
local s = ls.snippet
local i = ls.insert_node
local fmta = require("luasnip.extras.fmt").fmta
-- ...

-- Include this `in_mathzone` function at the start of a snippets file...
local in_mathzone = function()
  -- The `in_mathzone` function requires the VimTeX plugin !!!
  return vim.fn['vimtex#syntax#in_mathzone']() == 1
end

return {
  s({trig = "{{", snippetType="autosnippet"},
    fmta("\\left\\{ <>\\right\\}<>", { i(1), i(2), }), {condition = in_mathzone}
  ),
  s({trig = "((", snippetType="autosnippet"},
    fmta("\\left( <>\\right)<>", { i(1), i(2), }), {condition = in_mathzone}
  ),
  s({trig = "[[", snippetType="autosnippet"},
    fmta("\\left[ <>\\right]<>", { i(1), i(2), }), {condition = in_mathzone}
  ),
}

You can load the LuaSnip snippets in your ~/.config/nvim/init.lua with

require("luasnip.loaders.from_lua").lazy_load({paths = "~/.config/nvim/luasnippets/"})

To learn more about LuaSnip in the context of LaTeX, there is a tutorial on following webpage:

https://www.ejmastnak.com/tutorials/vim-latex/luasnip

For more LuaSnip Snippets for the filetype LaTex, you can see following github repositories

5
  • I added the tex.lua into ~/.config/nvim/lua/custom/LuaSnippets/ and added the path to custom/init.lua as the NvChad configs. But still the autoexpand is not seem to be working! I tried the normal config with require(luasnip.loaders.from_lua). That too is not working. Is there a way in which I can inspect if the variable vim.g.luasnippets_path is set to the correct path? I've my updated configs here
    – codehumor
    Feb 8 at 6:20
  • I have updated the answer that autoexpand must be enabled. Can you trigger the snippets with the configured trigger key by NvChad? And does :LuaSnipListAvailable list them?
    – Hotschke
    Feb 8 at 10:20
  • Can you also add to your git repo the snippets? This makes it clear if the path is correct.
    – Hotschke
    Feb 8 at 10:24
  • I've updated the config enabling autosnippets. Still there's no change in the behaviour and the snippets are not listed in :LuaSnipListAvailable
    – codehumor
    Feb 8 at 17:32
  • I am not using NvChad myself. But I had a look at the source code: vim.g.luasnippets_path is a path to VSCode like snippets. So using vim.g.luasnippets_path does not help. They should improve their documentation. I think you should open two issues in the nvchad repo 1) How to add lua-type snippets? (github.com/NvChad/NvChad/pull/1543) and 2) How to configure enable_autosnippets for LuaSnip? This is the reason why I do not like these configurations which introduce another layer (often incomplete) between the user, the plugins and neovim itself.
    – Hotschke
    Feb 9 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.