1 min
8.9K
Setup LaTeX for Neovim
A guide to setting up VimTeX, TexLab LSP, and Zathura for LaTeX editing in Neovim on Artix Linux
- #neovim
- #latex
- #vimtex
By Baichu@github/baichuu
Install System Packages
terminal
sudo pacman -S $(pacman -Ssq '^texlive-') # Full TeX Live installationsudo pacman -S zathura zathura-pdf-mupdf # PDF viewersudo pacman -S libxcrypt-compat # latexindent dependencyInstall VimTeX Plugin
Add to your lazy.nvim config
`~/.config/nvim/lua/baichu/plugins/init.lua`:1{2 "lervag/vimtex",3 filetypes = { "tex" },4 init = function()5 vim.g.vimtex_view_method = "zathura"6 vim.g.vimtex_compiler_method = "latexmk"7 vim.g.vimtex_quickfix_mode = 08 vim.g.vimtex_compiler_autojump = 19 vim.g.vimtex_compiler_latexmk = {10 build_dir = "",11 callback = 1,12 continuous = 1,13 executable = "latexmk",14 options = {15 "-xelatex",16 "-interaction=nonstopmode",17 "-synctex=1",18 "-file-line-error",19 "-pdf",20 },21 }22 end,23},1{2 "lervag/vimtex",3 filetypes = { "tex" },4 init = function()5 vim.g.vimtex_view_method = "zathura"6 vim.g.vimtex_compiler_method = "latexmk"7 vim.g.vimtex_quickfix_mode = 08 vim.g.vimtex_compiler_autojump = 19 vim.g.vimtex_compiler_latexmk = {10 build_dir = "",11 callback = 1,12 continuous = 1,13 executable = "latexmk",14 options = {15 "-xelatex",16 "-interaction=nonstopmode",17 "-synctex=1",18 "-file-line-error",19 "-pdf",20 },21 }22 end,23},Install LSP and Formatter
Launch Mason in Neovim (
`:Mason`) and install:`texlab`- LSP server for LaTeX`latexindent`- Code formatter`bibtex-tidy`- BibTeX formatter
Configure Formatter
In your conform.nvim setup:
1require("conform").setup({2 formatters_by_ft = {3 tex = { "latexindent" },4 bib = { "bibtex-tidy" },5 },6})1require("conform").setup({2 formatters_by_ft = {3 tex = { "latexindent" },4 bib = { "bibtex-tidy" },5 },6})Format with
`<leader>fm` (Space + f + m).Configure Zathura
In
`~/.config/zathura/zathurarc`:1set synctex true2set synctex-editor-command "nvim --headless -es --cmd \"VimtexInverseSearch %{line} '%{input}'\""1set synctex true2set synctex-editor-command "nvim --headless -es --cmd \"VimtexInverseSearch %{line} '%{input}'\""VimTeX Commands
| Command | Action |
|---|---|
`\ll` | Start/stop compilation |
`\lv` | Open PDF viewer |
`\lt` | Table of contents |
`\lc` | Clean auxiliary files |
`\lk` | Stop compilation |
Neovim Commands
1:LspInfo " Check LSP server status2:ConformInfo " Check formatter configuration3:Mason " Open Mason package manager1:LspInfo " Check LSP server status2:ConformInfo " Check formatter configuration3:Mason " Open Mason package manager