1 min
0

Cài đặt LaTeX cho Neovim

Hướng dẫn cài đặt VimTeX, TexLab LSP và Zathura để chỉnh sửa LaTeX trong Neovim trên Artix Linux

  • #neovim
  • #latex
  • #vimtex

Cài đặt gói hệ thống

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

Cài đặt plugin VimTeX

Thêm vào cấu hình 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},

Cài đặt LSP và formatter

Mở Mason trong Neovim (`:Mason`) và cài:
  • `texlab` — LSP server cho LaTeX
  • `latexindent` — formatter mã
  • `bibtex-tidy` — formatter BibTeX

Cấu hình formatter

Trong thiết lập conform.nvim:
luaLUA
1require("conform").setup({2  formatters_by_ft = {3    tex = { "latexindent" },4    bib = { "bibtex-tidy" },5  },6})
Định dạng bằng `<leader>fm` (Space + f + m).

Cấu hình Zathura

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

Lệnh VimTeX

LệnhThao tác
`\ll`Bật/tắt biên dịch
`\lv`Mở trình xem PDF
`\lt`Mục lục
`\lc`Xóa file phụ trợ
`\lk`Dừng biên dịch

Lệnh Neovim

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

Tài liệu tham khảo

>Newsletter

Stay Updated

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