0 min
12

在 Neovim 中配置 LaTeX

在 Artix Linux 上为 Neovim 配置 VimTeX、TexLab LSP 与 Zathura 的 LaTeX 编辑环境指南

  • #neovim
  • #latex
  • #vimtex

安装系统软件包

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

安装 VimTeX 插件

将以下内容加入 lazy.nvim 配置 `~/.config/nvim/lua/baichu/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 = 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},

安装 LSP 与格式化工具

在 Neovim 中启动 Mason(`:Mason`)并安装:
  • `texlab` — LaTeX 的 LSP 服务器
  • `latexindent` — 代码格式化工具
  • `bibtex-tidy` — BibTeX 格式化工具

配置格式化工具

在 conform.nvim 配置中:
luaLUA
1require("conform").setup({2  formatters_by_ft = {3    tex = { "latexindent" },4    bib = { "bibtex-tidy" },5  },6})
使用 `<leader>fm`(Space + f + m)进行格式化。

配置 Zathura

`~/.config/zathura/zathurarc` 中:
javascriptJavaScript
1set synctex true2set synctex-editor-command "nvim --headless -es --cmd \"VimtexInverseSearch %{line} '%{input}'\""

VimTeX 命令

命令作用
`\ll`开始/停止编译
`\lv`打开 PDF 阅读器
`\lt`目录
`\lc`清理辅助文件
`\lk`停止编译

Neovim 命令

vimVIM
1:LspInfo              " Check LSP server status2:ConformInfo          " Check formatter configuration3:Mason                " Open Mason package manager

参考资料

>Newsletter

Stay Updated

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