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) { 'll', 'VimtexCompile', desc = 'VimTeX: Compile', ft = { 'tex', 'latex' } }, { 'lv', 'VimtexView', desc = 'VimTeX: View PDF', ft = { 'tex', 'latex' } }, { 'ls', 'VimtexStop', desc = 'VimTeX: Stop', ft = { 'tex', 'latex' } }, { 'lS', 'VimtexStopAll', desc = 'VimTeX: Stop All', ft = { 'tex', 'latex' } }, { 'lc', 'VimtexClean', desc = 'VimTeX: Clean', ft = { 'tex', 'latex' } }, { 'lC', 'VimtexClean!', desc = 'VimTeX: Clean All', ft = { 'tex', 'latex' } }, { 'lq', 'VimtexErrors', desc = 'VimTeX: Errors', ft = { 'tex', 'latex' } }, { 'lk', 'VimtexLog', desc = 'VimTeX: Log', ft = { 'tex', 'latex' } }, { 'li', 'VimtexInfo', desc = 'VimTeX: Info', ft = { 'tex', 'latex' } }, { 'lI', 'VimtexInfoFull', desc = 'VimTeX: Info Full', ft = { 'tex', 'latex' } }, { 'lt', 'VimtexTocToggle', desc = 'VimTeX: TOC Toggle', ft = { 'tex', 'latex' } }, { 'lT', 'VimtexTocOpen', desc = 'VimTeX: TOC Open', ft = { 'tex', 'latex' } }, { 'lw', 'VimtexCountWords', desc = 'VimTeX: Count Words', ft = { 'tex', 'latex' } }, { 'lW', 'VimtexCountLetters', desc = 'VimTeX: Count Letters', ft = { 'tex', 'latex' } }, { 'lm', 'VimtexImapsList', desc = 'VimTeX: Imaps List', ft = { 'tex', 'latex' } }, -- Only one custom mapping for continuous compilation toggle { 'lR', function() _G.vimtex_toggle_continuous() end, desc = 'VimTeX: Toggle Continuous', ft = { 'tex', 'latex' }, }, }, }