This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.config/nvim/after/ftplugin/tex.lua

131 lines
3.7 KiB
Lua

-- Author : swytch
-- Created : Monday Oct. 04, 2021 16:09:13 CET
-- License : GPLv3
-- Description : tex filetype config
local opt = vim.opt
local g = vim.g
opt.formatoptions = "trq1jp"
opt.tabstop = 4
-- Caps
utils.map("i", "AA", "À")
utils.map("i", "CC", "Ç")
utils.map("i", "EE", "É")
-- Unbreakable spaces
utils.map("i", "<Space>etc", "\\,etc.")
utils.map("i", "<Space>:", "\\,:")
-- Snippets
local ls = require("luasnip")
-- some shorthands...
local s = ls.snippet
local sn = ls.snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
local c = ls.choice_node
local d = ls.dynamic_node
local copy = utils.copy
-- 'recursive' dynamic snippet. Expands to some text followed by itself.
local function rec_ls()
return sn(
nil,
c(1, {
-- Order is important, sn(...) first would cause infinite loop of expansion.
t(""),
sn(nil, { t({ "", "", "\t\\item " }), i(1), d(2, rec_ls, {}) }),
})
)
end
ls.snippets = {
tex = {
-- rec_ls is self-referencing. That makes this snippet 'infinite' eg. have as many
-- \item as necessary by utilizing a choiceNode.
s("ls", {
t({ "\\begin{itemize}", "\t\\item " }),
i(1),
t({ "" }),
d(2, rec_ls, {}),
t({ "", "\\end{itemize}", "" }),
}),
s("lsl", {
t({ "\\begin{itemize}[label=" }),
i(1),
t( { "]", "\t\\item " }),
i(2),
t({ "" }),
d(3, rec_ls, {}),
t({ "", "\\end{itemize}", "" }),
}),
s("frm", {
t({ "\\begin{" }),
i(1),
t({ "}[" }),
i(2),
t({ "]{" }),
f(copy, 1),
t({ ":" }),
i(3, "foo"),
t({ "}", "\t" }),
i(0),
t({ "", "\\end{" }),
f(copy, 1),
t({ "}", "" }),
}),
s("env", {
t({ "\\begin{" }),
i(1, "foo"),
t({ "}", "\t" }),
i(2),
t({ "", "\\end{" }),
f(copy,1),
t({ "}", "" }),
}),
s("tikz", {
t({ "\\begin{center}" }),
t({ "", "\t\\begin{tikzpicture}[main/.style = {draw,circle}]", "\t\t" }),
i(1),
t({ "", "\t\\end{tikzpicture}", "\\end{center}" }),
}),
s("ra", { t( "\\rightarrow" )}),
s("Ra", { t("\\Rightarrow" )}),
s("la", { t("\\leftarrow" )}),
s("La", { t("\\Leftarrow" )}),
s("lra", { t("\\leftrightarrow" )}),
s("Lra", { t("\\Leftrightarrow" )}),
s("bb", {
t({ "\\textbf{" }),
i(1),
t({ "}"}),
}),
s("tt", {
t({ "\\texttt{" }),
i(1),
t({ "}"}),
}),
s("ii", {
t({ "\\textit{" }),
i(1),
t({ "}"}),
}),
s("uu", {
t({ "\\underline{" }),
i(1),
t({ "}"}),
}),
s("fsc", {
t({ "\\textsc{" }),
i(1),
t({ "}"}),
}),
},
}