-- Mostly Generated with Antigravity CLI Gemini 3.7 Flash return { "lervag/vimtex", lazy = false, init = function() vim.g.vimtex_compiler_method = "tectonic" vim.g.vimtex_quickfix_mode = 0 vim.g.vimtex_view_enabled = 0 -- Disable external GUI popup end, config = function() local function open_pdf_split() local pdf_path = vim.fn.expand("%:p:r") .. ".pdf" if vim.fn.filereadable(pdf_path) == 1 then vim.cmd("vsplit " .. vim.fn.fnameescape(pdf_path)) else vim.notify("PDF not found: " .. pdf_path .. "\nCompile first with ll", vim.log.levels.WARN) end end -- Provide user command :VimtexPreviewBuffer vim.api.nvim_create_user_command("VimtexPreviewBuffer", open_pdf_split, { desc = "VimTeX: Open PDF in vertical split" }) -- Buffer-local keymaps for TeX files vim.api.nvim_create_autocmd("FileType", { pattern = { "tex", "latex" }, callback = function(ev) local opts = { buffer = ev.buf, desc = "VimTeX: View PDF in Neovim split" } vim.keymap.set("n", "lv", open_pdf_split, opts) vim.keymap.set("n", "lv", open_pdf_split, opts) end, }) -- Helper function to refresh and re-render all open PDF splits with image.nvim local function reload_pdf_buffers() local ok, image_api = pcall(require, "image") for _, win in ipairs(vim.api.nvim_list_wins()) do local buf = vim.api.nvim_win_get_buf(win) local buf_name = vim.api.nvim_buf_get_name(buf) if buf_name:match("%.pdf$") then vim.api.nvim_win_call(win, function() vim.cmd("edit!") end) if ok and image_api then local imgs = image_api.get_images({ window = win, buffer = buf }) if #imgs > 0 then for _, img in ipairs(imgs) do img:clear() img:render() end else image_api.hijack_buffer(buf_name, win, buf) end end end end end -- Automatically trigger compilation on save (:w) vim.api.nvim_create_autocmd("BufWritePost", { pattern = "*.tex", callback = function() if vim.b.vimtex and vim.fn.exists(":VimtexCompileSS") == 2 then vim.cmd("VimtexCompileSS") end end, }) -- Automatically reload and re-render PDF splits when compilation finishes vim.api.nvim_create_autocmd("User", { pattern = { "VimtexEventCompileSuccess", "VimtexEventCompileStopped" }, callback = function() reload_pdf_buffers() end, }) end, }