This commit is contained in:
Zelong Kuang
2025-09-21 20:43:38 +10:00
parent 9d1536e5af
commit 46c470d1f7
50 changed files with 5465 additions and 214 deletions

View File

@@ -1,41 +1,137 @@
local ls = require("luasnip")
local c = ls.choice_node
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 d = ls.dynamic_node
local c = ls.choice_node
local fmt = require("luasnip.extras.fmt").fmt
local fmta = require("luasnip.extras.fmt").fmta
local tex = require("util.latex")
local rep = require("luasnip.extras").rep
local get_visual = function(args, parent)
if #parent.snippet.env.SELECT_RAW > 0 then
return sn(nil, i(1, parent.snippet.env.SELECT_RAW))
else -- If SELECT_RAW is empty, return a blank insert node
return sn(nil, i(1))
end
end
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return {
s({ trig = "dps", snippetType = "autosnippet" }, {
t("\\displaystyle"),
}, { condition = tex.in_mathzone }),
s({ trig = "if", snippetType = "autosnippet" }, {
t("\\text{\\ if\\ }"),
}, { condition = tex.in_mathzone }),
s({ trig = "stt", snippetType = "autosnippet" }, {
t("\\text{ s.t. }"),
}, { condition = tex.in_mathzone }),
s({ trig = "as", snippetType = "autosnippet" }, {
t("\\text{\\ as\\ }"),
}, { condition = tex.in_mathzone }),
s({ trig = "or", snippetType = "autosnippet" }, { t("\\text{\\ or\\ }") }, { condition = tex.in_mathzone }),
s({ trig = "otherwise", snippetType = "autosnippet" }, {
t("\\text{\\ otherwise\\ }"),
}, { condition = tex.in_mathzone }),
s({ trig = "then", snippetType = "autosnippet" }, {
t("\\text{\\ then\\ }"),
}, { condition = tex.in_mathzone }),
s({ trig = "since", snippetType = "autosnippet" }, {
t("\\text{\\ since\\ }"),
}, { condition = tex.in_mathzone }),
s({ trig = "by", snippetType = "autosnippet" }, {
t("\\text{\\ by\\ }"),
}, { condition = tex.in_mathzone }),
s({ trig = "and", snippetType = "autosnippet" }, {
t("\\text{\\ and\\ }"),
}, { condition = tex.in_mathzone }),
s({ trig = "qd", snippetType = "autosnippet" }, {
t("\\quad"),
}, { condition = tex.in_mathzone }),
s(
"link",
fmta("[<>](<>)", { i(1), f(function(_, snip)
return snip.env.TM_SELECTED_TEXT[1] or {}
end, {}) })
{ trig = "setc", snippetType = "autosnippet" },
fmta("\\setcounter{<>}{<>}", {
c(1, { t("exercise"), t("theorem") }),
i(2),
}),
{ condition = tex.in_text }
),
s({ trig = ";b", snippetType = "autosnippet" }, fmta("**<>**", i(1))),
s({ trig = ";t", snippetType = "autosnippet" }, fmta("*<>*", i(1))),
s({ trig = "xx", snippetType = "autosnippet" }, fmta("$\\times$", {})),
s({ trig = "wlog", snippetType = "autosnippet" }, {
t("without loss of generality"),
}, { condition = tex.in_text }),
s({ trig = "Wlog", snippetType = "autosnippet" }, {
t("Without loss of generality"),
}, { condition = tex.in_text }),
s({ trig = "thmm", snippetType = "autosnippet" }, {
t("theorem"),
}, { condition = tex.in_text }),
s({ trig = "Thmm", snippetType = "autosnippet" }, {
t("Theorem"),
}, { condition = tex.in_text }),
s({ trig = "propp", snippetType = "autosnippet" }, {
t("proposition"),
}, { condition = tex.in_text }),
s({ trig = "deff", snippetType = "autosnippet" }, {
t("definition"),
}, { condition = tex.in_text }),
s({ trig = "Deff", snippetType = "autosnippet" }, {
t("Definition"),
}, { condition = tex.in_text }),
s({ trig = "exaa", snippetType = "autosnippet" }, {
t("example"),
}, { condition = tex.in_text }),
s({ trig = "iee", snippetType = "autosnippet" }, {
t("i.e."),
}, { condition = tex.in_text }),
s({ trig = "stt", snippetType = "autosnippet" }, {
t("such that"),
}, { condition = tex.in_text }),
s({ trig = "iff", snippetType = "autosnippet" }, {
t("if and only if"),
}, { condition = tex.in_text }),
s({ trig = "iso" }, {
t("isomorphic"),
}, { condition = tex.in_text }),
s({ trig = "iso" }, {
t("isomorphism"),
}, { condition = tex.in_text }),
s({ trig = "homeo" }, {
t("homeomorphism"),
}, { condition = tex.in_text }),
s({ trig = "homeo" }, {
t("homeomorphic"),
}, { condition = tex.in_text }),
s({ trig = "homo" }, {
t("homomorphism"),
}, { condition = tex.in_text }),
s({ trig = "homo" }, {
t("homomorphic"),
}, { condition = tex.in_text }),
s({ trig = "si ", snippetType = "autosnippet" }, {
t("is "),
}, { condition = tex.in_text }),
s({ trig = "=>", snippetType = "autosnippet" }, {
t("$\\implies$"),
}, { condition = tex.in_text }),
s({ trig = "<=", snippetType = "autosnippet" }, {
t("$\\impliedby$"),
}, { condition = tex.in_text }),
s(
{ trig = ";c", snippetType = "autosnippet" },
{ trig = "(%a)ii", regTrig = true, wordTrig = false, snippetType = "autosnippet" },
fmta("$<>$", {
f(function(_, snip)
return snip.captures[1]
end),
}),
{ condition = tex.in_text }
),
s(
{
trig = "#(%d)",
regTrig = true,
wordTrig = false,
snippetType = "autosnippet",
},
fmta(
[[
```<>
<>
```
]],
{ i(1), i(0) }
)
"<> ",
{ f(function(_, snip)
local n = tonumber(snip.captures[1])
return string.rep("#", n)
end) }
),
{ condition = tex.in_text }
),
}