nvim/lua/custom/plugins/vimtex.lua
Jeremie Fraeys 02e26b00b7
Some checks are pending
Check Lua Formatting in MyRepo / Stylua Check (push) Waiting to run
chore(nvim): reinitialize with working config
2026-02-07 21:06:45 -05:00

187 lines
6.4 KiB
Lua
Executable file

return {
'lervag/vimtex',
ft = { 'tex', 'latex', 'cls', 'sty', 'bib' },
lazy = false,
init = function()
-- macOS PDF viewer - Skim is better than Zathura on macOS
vim.g.vimtex_view_method = 'skim'
vim.g.vimtex_view_skim_sync = 1
vim.g.vimtex_view_skim_activate = 1
vim.g.vimtex_view_skim_reading_bar = 0
vim.g.vimtex_view_skim_preserve_state = 1
-- Alternative: use system default PDF viewer
-- vim.g.vimtex_view_method = 'general'
-- vim.g.vimtex_view_general_viewer = 'open'
-- Compiler
vim.g.vimtex_compiler_method = 'latexmk'
vim.g.vimtex_compiler_latexmk_engines = {
_ = '-pdf -xelatex -synctex=1 -interaction=nonstopmode',
}
vim.g.vimtex_compiler_latexmk = {
build_dir = 'output',
aux_dir = 'output',
callback = 1,
continuous = 1,
executable = 'latexmk',
options = {
-- '-pdf',
'-verbose',
'-file-line-error',
-- '-synctex=1',
'-interaction=nonstopmode',
-- '-xelatex',
'-shell-escape',
'-outdir=output',
'-auxdir=output',
},
}
-- Disable problematic default mappings
vim.g.vimtex_mappings_disable = {
['n'] = { 'K' },
['x'] = { 'K' },
}
-- Quickfix
vim.g.vimtex_quickfix_method = vim.fn.executable('pplatex') == 1 and 'pplatex' or 'latexlog'
vim.g.vimtex_quickfix_mode = 2
vim.g.vimtex_quickfix_open_on_warning = 0
vim.g.vimtex_quickfix_ignore_filters = {
'Underfull \\hbox',
'Overfull \\hbox',
'LaTeX Warning: .+ float specifier changed to',
'LaTeX hooks Warning',
'Package hyperref Warning: Token not allowed in a PDF string',
'Package fontspec Warning',
'Package everypage Warning',
'Package microtype Warning',
'LaTeX Warning: Command \\. invalid in math mode',
'Package babel Warning',
'Package biblatex Warning',
}
-- Folding
vim.g.vimtex_fold_enabled = 1
vim.g.vimtex_fold_types = {
envs = { whitelist = { 'figure', 'table', 'equation', 'align' } },
sections = { parse_levels = 1 },
}
-- Syntax
vim.g.vimtex_syntax_enabled = 1
vim.g.vimtex_syntax_conceal = {
accents = 0,
ligatures = 0,
cites = 1,
fancy = 0,
spacing = 0,
greek = 1,
math_bounds = 0,
math_delimiters = 0,
math_fracs = 0,
math_super_sub = 1,
math_symbols = 1,
sections = 0,
}
end,
config = function()
-- Auto-create output dir
vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead' }, {
pattern = { '*.tex', '*.latex' },
callback = function()
if vim.bo.filetype == 'tex' or vim.bo.filetype == 'latex' then
local output_dir = vim.fn.expand('%:p:h') .. '/output'
if vim.fn.isdirectory(output_dir) == 0 then
vim.fn.mkdir(output_dir, 'p')
end
end
end,
})
-- Toggle continuous compilation function
_G.vimtex_toggle_continuous = function()
if vim.g.vimtex_compiler_latexmk.continuous == 1 then
vim.g.vimtex_compiler_latexmk.continuous = 0
print('Continuous compilation OFF')
vim.cmd('VimtexStop')
else
vim.g.vimtex_compiler_latexmk.continuous = 1
print('Continuous compilation ON')
vim.cmd('VimtexCompile')
end
end
-- Function to close Skim for current PDF
local function close_skim()
local file_name = vim.fn.expand('%:t:r')
if file_name ~= '' then
local pdf_name = file_name .. '.pdf'
-- AppleScript to close Skim window for specific PDF
local script = string.format(
[[
tell application "System Events"
if (name of processes) contains "Skim" then
tell application "Skim"
set theWindows to every window whose name contains "%s"
repeat with theWindow in theWindows
close theWindow
end repeat
end tell
end if
end tell
]],
pdf_name
)
vim.fn.system({ 'osascript', '-e', script })
end
end
-- Auto-close Skim when LaTeX buffer is deleted or closed
vim.api.nvim_create_autocmd({ 'BufDelete', 'BufWipeout' }, {
pattern = { '*.tex', '*.latex' },
callback = function()
close_skim()
end,
})
-- Also close when Neovim exits
vim.api.nvim_create_autocmd('VimLeave', {
pattern = { '*.tex', '*.latex' },
callback = function()
close_skim()
end,
})
end,
-- Use VimTeX's standard keymaps - only add minimal custom ones
keys = {
-- Standard VimTeX mappings (these are the defaults, just making them explicit)
{ '<localleader>ll', '<cmd>VimtexCompile<cr>', desc = 'VimTeX: Compile', ft = { 'tex', 'latex' } },
{ '<localleader>lv', '<cmd>VimtexView<cr>', desc = 'VimTeX: View PDF', ft = { 'tex', 'latex' } },
{ '<localleader>ls', '<cmd>VimtexStop<cr>', desc = 'VimTeX: Stop', ft = { 'tex', 'latex' } },
{ '<localleader>lS', '<cmd>VimtexStopAll<cr>', desc = 'VimTeX: Stop All', ft = { 'tex', 'latex' } },
{ '<localleader>lc', '<cmd>VimtexClean<cr>', desc = 'VimTeX: Clean', ft = { 'tex', 'latex' } },
{ '<localleader>lC', '<cmd>VimtexClean!<cr>', desc = 'VimTeX: Clean All', ft = { 'tex', 'latex' } },
{ '<localleader>lq', '<cmd>VimtexErrors<cr>', desc = 'VimTeX: Errors', ft = { 'tex', 'latex' } },
{ '<localleader>lk', '<cmd>VimtexLog<cr>', desc = 'VimTeX: Log', ft = { 'tex', 'latex' } },
{ '<localleader>li', '<cmd>VimtexInfo<cr>', desc = 'VimTeX: Info', ft = { 'tex', 'latex' } },
{ '<localleader>lI', '<cmd>VimtexInfoFull<cr>', desc = 'VimTeX: Info Full', ft = { 'tex', 'latex' } },
{ '<localleader>lt', '<cmd>VimtexTocToggle<cr>', desc = 'VimTeX: TOC Toggle', ft = { 'tex', 'latex' } },
{ '<localleader>lT', '<cmd>VimtexTocOpen<cr>', desc = 'VimTeX: TOC Open', ft = { 'tex', 'latex' } },
{ '<localleader>lw', '<cmd>VimtexCountWords<cr>', desc = 'VimTeX: Count Words', ft = { 'tex', 'latex' } },
{ '<localleader>lW', '<cmd>VimtexCountLetters<cr>', desc = 'VimTeX: Count Letters', ft = { 'tex', 'latex' } },
{ '<localleader>lm', '<cmd>VimtexImapsList<cr>', desc = 'VimTeX: Imaps List', ft = { 'tex', 'latex' } },
-- Only one custom mapping for continuous compilation toggle
{
'<localleader>lR',
function()
_G.vimtex_toggle_continuous()
end,
desc = 'VimTeX: Toggle Continuous',
ft = { 'tex', 'latex' },
},
},
}