(very) minimal, opinionated neovim filetype plugin for (La)TeX and Markdown, written in Lua. There is no reason to prefer this plugin to VimTeX.
-- lazy.nvim
{
"mathjiajia/latex.nvim",
init = function()
vim.g.latex_conf = {
conceals = {
enabled = {
"amssymb",
"core",
"delim",
"font",
"greek",
"math",
-- "mleftright",
"script",
},
add = {},
},
imaps = {
enabled = false,
add = {},
default_leader = ";",
},
surrounds = {
enabled = true,
command = "c",
math = "$",
quotation = '"',
},
texlab = {
enabled = true,
build = "<M-b>",
forward = "<M-f>",
cancel_build = "<M-x>",
close_env = "]]",
change_env = "cse",
toggle_star = "tse",
},
}
end
}
To use imaps
, which are based on treesitter,
you must have treesitter parsers for the relevant filetype installed.
For example, latex
for .tex
files
and markdown
and markdown_inline
for .md
files.
To use latex.nvim
you need modify the global variable
vim.g.latex_conf
See below for more about configuring imaps
.
Currently latex.nvim
provides user-configurable, context-aware insert-mode mappings
in .tex
and .md
files.
The mappings are directly inspired by VimTeX.
The imaps.add
table in setup()
expects one of the following formats
{
["rhs"] = "lhs",
-- the above is equivalent to
["rhs"] = {
lhs = "lhs",
leader = nil, -- will be replaced by default_leader
wrap_char = false,
context = nil -- will be replaced by one of require('latex').imaps.tex_math_mode or require('latex').imaps.markdown_math_mode
}
}
Assuming a default_leader
of "`", typing "`lhs" while within math mode
(e.g. between a pair of $
or a \[
, \]
block in a .tex
file,
or between a pair of $$
in a .md
file)
will yield an output of "rhs".
A mapping with wrap_char = true
,
for example the default mapping
{
["\\mathbb"] = {
lhs = "B",
leader = "#",
wrap_char = true
}
}
yields, after inputting "#BZ" in math mode, the output "\mathbb{Z}".
Almost all of the low-hanging fruit is done as far as concealing;
hard things like using tree-sitter for \'e
to é
are not a priority.
You can disable conceals on a per-file basis by redefining conceals.enabled
in the setup
function.
Currently the conceals provided are:
- Delim: things like
\left
and many instances of curly braces. - Font: things like
\mathbb{Z}
toℤ
- Greek: things like
\sigma
toσ
- Math: things like
\amalg
to⨿
- Script: superscripts and subscripts
You can add your own concealed commands to the conceals.add
table in the following format
add = {
["colon"] = ":",
}
The key should be the command name with the leading backslash stripped,
and the value should be the single-character conceal to replace that command with.
The add
table is for concealing generic_command
elements.
Unlike most other conceals, these are not sensitive to the presence or absence of math mode.
Requires nvim-surround.
Provides add
, change
and delete
for commands and environments.
With default settings for nvim-surround
, these are mapped to,
for example, csc
for c
hange s
urrounding c
ommand and
dse
for d
elete s
urrounding e
nvironment.
To enable, set surrounds.enabled
to true
.
- compilation, forward/backward search, completion, linting—use texlab
- highlighting—use treesitter