2021-10-19 19:02:43 +02:00
|
|
|
-- Author : swytch
|
|
|
|
-- Created : Monday Oct. 04, 2021 16:09:13 CET
|
|
|
|
-- License : GPLv3
|
2021-11-20 16:04:18 +01:00
|
|
|
-- Description : tex filetype config
|
2021-10-19 19:02:43 +02:00
|
|
|
|
|
|
|
|
2022-04-27 21:58:12 +02:00
|
|
|
local opt = vim.opt
|
2021-11-20 16:04:18 +01:00
|
|
|
|
2022-04-27 21:58:12 +02:00
|
|
|
opt.formatoptions = "trq1jp"
|
|
|
|
opt.tabstop = 4
|
2021-11-20 16:04:18 +01:00
|
|
|
|
2021-10-19 19:02:43 +02:00
|
|
|
-- Caps
|
2022-04-29 00:21:30 +02:00
|
|
|
vim.keymap.set("i", "AA", "À")
|
|
|
|
vim.keymap.set("i", "CC", "Ç")
|
|
|
|
vim.keymap.set("i", "EE", "É")
|
2021-10-19 19:02:43 +02:00
|
|
|
|
|
|
|
-- Unbreakable spaces
|
2022-04-29 00:21:30 +02:00
|
|
|
vim.keymap.set("i", "<Space>etc", "\\,etc.")
|
|
|
|
vim.keymap.set("i", "<Space>:", "\\,:")
|
2021-10-19 19:02:43 +02:00
|
|
|
|
2021-12-09 16:30:30 +01:00
|
|
|
-- Snippets
|
|
|
|
local ls = require("luasnip")
|
|
|
|
|
|
|
|
-- some shorthands...
|
2022-04-27 21:58:12 +02:00
|
|
|
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
|
2021-12-09 16:30:30 +01:00
|
|
|
|
2022-04-27 21:58:12 +02:00
|
|
|
local copy = utils.copy
|
2021-12-09 16:30:30 +01:00
|
|
|
|
|
|
|
-- '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
|
|
|
|
|
2022-04-29 00:20:18 +02:00
|
|
|
ls.add_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{" }),
|
2022-04-27 21:58:12 +02:00
|
|
|
i(1),
|
|
|
|
t({ "}"}),
|
2022-04-29 00:20:18 +02:00
|
|
|
}),
|
|
|
|
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({ "}"}),
|
|
|
|
}),
|
|
|
|
}, {
|
|
|
|
key = "tex"
|
|
|
|
})
|