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

130 lines
2.9 KiB
Lua
Raw Normal View History

-- 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
local opt = vim.opt
2021-11-20 16:04:18 +01:00
opt.formatoptions = "trq1jp"
opt.tabstop = 4
2021-11-20 16:04:18 +01:00
-- Caps
vim.keymap.set("i", "AA", "À")
vim.keymap.set("i", "CC", "Ç")
vim.keymap.set("i", "EE", "É")
-- Unbreakable spaces
vim.keymap.set("i", "<Space>etc", "\\,etc.")
vim.keymap.set("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
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{" }),
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"
})