-- Source-visible editing by default; toggle with <leader>uc
vim.opt_local.conceallevel = 0

-- Spell-check (tweak languages to your needs)
vim.opt_local.spell = true
vim.opt_local.spelllang = { "en_gb", "de_de", "fr" }

-- Niceties for prose/math
vim.opt_local.wrap = true
vim.opt_local.linebreak = true
vim.opt_local.textwidth = 0 -- don't hard-wrap LaTeX

-- Normalize display-math delimiters: $$ … $$ → \[ … \] on every save.
-- Uses a unique augroup per buffer to avoid double-registration on :edit.
vim.api.nvim_create_autocmd("BufWritePre", {
  buffer = 0,
  group = vim.api.nvim_create_augroup("user_tex_normalize_math_" .. vim.api.nvim_get_current_buf(), { clear = true }),
  callback = function()
    local view = vim.fn.winsaveview()
    vim.cmd([[silent! keeppatterns %s/\v\$\$(\_.{-})\$\$/\\[\1\\]/g]])
    vim.fn.winrestview(view)
  end,
})

