return {
  {
    "lervag/vimtex",
    lazy = false,
    init = function()
      -- ==========================================
      -- VIMTEX SETTINGS (must be set BEFORE plugin loads)
      -- ==========================================

      -- PDF viewer
      vim.g.vimtex_view_method = "skim"
      vim.g.vimtex_view_skim_sync = 1
      vim.g.vimtex_view_skim_activate = 1

      -- Completion
      vim.g.vimtex_complete_enabled = 0
      vim.g.vimtex_complete_close_braces = 0

      -- Conceal configuration
      vim.g.vimtex_syntax_conceal = {
        accents = 1,
        ligatures = 1,
        cites = 1,
        fancy = 1,
        spacing = 1,
        greek = 1,
        math_bounds = 1,
        math_delimiters = 1,
        math_fracs = 1,
        math_super_sub = 1,
        math_symbols = 1,
        sections = 0,
        styles = 1,
      }

      -- Custom command conceals for personal macros
      vim.g.vimtex_syntax_custom_cmds = {
        -- Blackboard bold (number sets)
        { name = "RR", mathmode = true, conceal = true, concealchar = "ℝ" },
        { name = "NN", mathmode = true, conceal = true, concealchar = "ℕ" },
        { name = "ZZ", mathmode = true, conceal = true, concealchar = "ℤ" },
        { name = "QQ", mathmode = true, conceal = true, concealchar = "ℚ" },
        { name = "CC", mathmode = true, conceal = true, concealchar = "ℂ" },
        { name = "PP", mathmode = true, conceal = true, concealchar = "ℙ" },
        { name = "HH", mathmode = true, conceal = true, concealchar = "ℍ" },
        { name = "FF", mathmode = true, conceal = true, concealchar = "𝔽" },
        { name = "EE", mathmode = true, conceal = true, concealchar = "𝔼" },

        -- Mathcal shortcuts
        { name = "mcA", mathmode = true, conceal = true, concealchar = "𝒜" },
        { name = "mcB", mathmode = true, conceal = true, concealchar = "ℬ" },
        { name = "mcC", mathmode = true, conceal = true, concealchar = "𝒞" },
        { name = "mcD", mathmode = true, conceal = true, concealchar = "𝒟" },
        { name = "mcE", mathmode = true, conceal = true, concealchar = "ℰ" },
        { name = "mcF", mathmode = true, conceal = true, concealchar = "ℱ" },
        { name = "mcG", mathmode = true, conceal = true, concealchar = "𝒢" },
        { name = "mcH", mathmode = true, conceal = true, concealchar = "ℋ" },
        { name = "mcI", mathmode = true, conceal = true, concealchar = "ℐ" },
        { name = "mcJ", mathmode = true, conceal = true, concealchar = "𝒥" },
        { name = "mcK", mathmode = true, conceal = true, concealchar = "𝒦" },
        { name = "mcL", mathmode = true, conceal = true, concealchar = "ℒ" },
        { name = "mcM", mathmode = true, conceal = true, concealchar = "ℳ" },
        { name = "mcN", mathmode = true, conceal = true, concealchar = "𝒩" },
        { name = "mcO", mathmode = true, conceal = true, concealchar = "𝒪" },
        { name = "mcP", mathmode = true, conceal = true, concealchar = "𝒫" },
        { name = "mcQ", mathmode = true, conceal = true, concealchar = "𝒬" },
        { name = "mcR", mathmode = true, conceal = true, concealchar = "ℛ" },
        { name = "mcS", mathmode = true, conceal = true, concealchar = "𝒮" },
        { name = "mcT", mathmode = true, conceal = true, concealchar = "𝒯" },
        { name = "mcU", mathmode = true, conceal = true, concealchar = "𝒰" },
        { name = "mcV", mathmode = true, conceal = true, concealchar = "𝒱" },
        { name = "mcW", mathmode = true, conceal = true, concealchar = "𝒲" },
        { name = "mcX", mathmode = true, conceal = true, concealchar = "𝒳" },
        { name = "mcY", mathmode = true, conceal = true, concealchar = "𝒴" },
        { name = "mcZ", mathmode = true, conceal = true, concealchar = "𝒵" },

        -- Mathfrak (Lie algebras)
        { name = "kg", mathmode = true, conceal = true, concealchar = "𝔤" },
        { name = "kh", mathmode = true, conceal = true, concealchar = "𝔥" },
        { name = "kn", mathmode = true, conceal = true, concealchar = "𝔫" },
        { name = "kb", mathmode = true, conceal = true, concealchar = "𝔟" },
        { name = "ku", mathmode = true, conceal = true, concealchar = "𝔲" },
        { name = "kz", mathmode = true, conceal = true, concealchar = "𝔷" },
        { name = "kp", mathmode = true, conceal = true, concealchar = "𝔭" },
        { name = "kq", mathmode = true, conceal = true, concealchar = "𝔮" },
        { name = "km", mathmode = true, conceal = true, concealchar = "𝔪" },

        -- Operators
        --        { name = "Hom", mathmode = true, conceal = true, concealchar = "H" },
        --        { name = "End", mathmode = true, conceal = true, concealchar = "E" },
        --        { name = "Aut", mathmode = true, conceal = true, concealchar = "A" },
        --        { name = "Ker", mathmode = true, conceal = true, concealchar = "K" },
        --        { name = "Mor", mathmode = true, conceal = true, concealchar = "M" },
        --        { name = "Ext", mathmode = true, conceal = true, concealchar = "E" },
        --        { name = "Tor", mathmode = true, conceal = true, concealchar = "T" },
        --        { name = "Gal", mathmode = true, conceal = true, concealchar = "G" },
        --        { name = "Spec", mathmode = true, conceal = true, concealchar = "S" },

        -- Arrows
        { name = "injto", mathmode = true, conceal = true, concealchar = "↪" },
        { name = "surjto", mathmode = true, conceal = true, concealchar = "↠" },
        { name = "taking", mathmode = true, conceal = true, concealchar = "→" },

        -- Misc
        { name = "defeq", mathmode = true, conceal = true, concealchar = "≝" },
        { name = "eps", mathmode = true, conceal = true, concealchar = "ε" },
        { name = "veps", mathmode = true, conceal = true, concealchar = "ε" },
        { name = "del", mathmode = true, conceal = true, concealchar = "∂" },
        { name = "lm", mathmode = true, conceal = true, concealchar = "λ" },
        { name = "inv", mathmode = true, conceal = true, concealchar = "⁻" },
        { name = "unlhd", mathmode = true, conceal = true, concealchar = "⊴" },
      }

      -- Compiler settings - uses .latexmkrc (plain pdflatex)
      vim.g.vimtex_compiler_latexmk = {
        callback = 1,
        continuous = 1,
        executable = "latexmk",
        hooks = {},
        options = {
          "-verbose",
          "-file-line-error",
          "-synctex=1",
          "-interaction=nonstopmode",
        },
      }

      -- Quickfix filters
      vim.g.vimtex_quickfix_ignore_filters = {
        "Underfull",
        "Overfull",
        "Package hyperref Warning",
        "Package fancyhdr Warning",
        "headheight is too small",
        "There were undefined references",
        "Label(s) may have changed",
        "Package biblatex Warning",
        "Please (re)run Biber",
      }
    end,

    config = function()
      -- ==========================================
      -- RUNTIME SETTINGS (after plugin loads)
      -- ==========================================

      -- Enable concealment
      vim.opt.conceallevel = 2
      vim.opt.concealcursor = "" -- Don't conceal on current line

      -- Force Skim refresh after successful compilation
      vim.api.nvim_create_autocmd("User", {
        pattern = "VimtexEventCompileSuccess",
        callback = function()
          vim.cmd("VimtexView")
        end,
      })

      -- VimTeX keybindings under <leader>t for TeX
      vim.keymap.set("n", "<leader>tc", "<cmd>VimtexCompile<cr>", { desc = "Compile (toggle)" })
      vim.keymap.set("n", "<leader>tv", "<cmd>VimtexView<cr>", { desc = "View PDF" })
      vim.keymap.set("n", "<leader>ts", "<cmd>VimtexStop<cr>", { desc = "Stop compilation" })
      vim.keymap.set("n", "<leader>tk", "<cmd>VimtexClean<cr>", { desc = "Clean aux files" })
      vim.keymap.set("n", "<leader>tK", "<cmd>VimtexClean!<cr>", { desc = "Clean all (inc PDF)" })
      vim.keymap.set("n", "<leader>te", "<cmd>VimtexErrors<cr>", { desc = "View errors" })
      vim.keymap.set("n", "<leader>to", "<cmd>VimtexLog<cr>", { desc = "View log output" })
      vim.keymap.set("n", "<leader>tt", "<cmd>VimtexTocToggle<cr>", { desc = "Toggle TOC" })
      vim.keymap.set("n", "<leader>ti", "<cmd>VimtexInfo<cr>", { desc = "VimTeX info" })
      vim.keymap.set("n", "<leader>tg", "<cmd>VimtexStatus<cr>", { desc = "Compilation status" })
    end,
  },

  {
    "neovim/nvim-lspconfig",
    config = function()
      local lspconfig = require("lspconfig")

      lspconfig.texlab.setup({
        settings = {
          texlab = {
            build = {
              executable = "latexmk",
              args = { "-pdf", "-interaction=nonstopmode", "-synctex=1", "%f" },
              onSave = true,
            },
            completion = {
              matcher = "fuzzy",
            },
            experimental = {
              followPackageLinks = true,
            },
          },
        },
        root_dir = function(fname)
          return lspconfig.util.root_pattern(".latexmkrc", ".git")(fname) or vim.fn.getcwd()
        end,
      })
    end,
  },
}
