1 min
22

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 Baiyuechu@github/baiyuechuz

Install System Packages

terminal
sudo pacman -S $(pacman -Ssq '^texlive-') # Full TeX Live installation
sudo pacman -S zathura zathura-pdf-mupdf # PDF viewer
sudo pacman -S libxcrypt-compat # latexindent dependency

Install VimTeX Plugin

Add to your lazy.nvim config `~/.config/nvim/lua/baiyuechu/plugins/init.lua`:
luaLUA
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 = 0
8    vim.g.vimtex_compiler_autojump = 1
9    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:
luaLUA
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`:
javascriptJAVASCRIPT
1set synctex true
2set synctex-editor-command "nvim --headless -es --cmd \"VimtexInverseSearch %{line} '%{input}'\""

VimTeX Commands

CommandAction
`\ll`Start/stop compilation
`\lv`Open PDF viewer
`\lt`Table of contents
`\lc`Clean auxiliary files
`\lk`Stop compilation

Neovim Commands

vimVIM
1:LspInfo              " Check LSP server status
2:ConformInfo          " Check formatter configuration
3:Mason                " Open Mason package manager

References

Subscribe now

Join Baiyuechu Newsletter!

Get notified when I publish new articles, tutorials, and project updates. Subscribe for insights and actionable content.