more work on latex snippets
This commit is contained in:
parent
ec9ffe9e92
commit
a0abbe52b1
1 changed files with 47 additions and 19 deletions
|
@ -4,7 +4,7 @@ local ls = require("luasnip")
|
|||
local s = ls.snippet
|
||||
-- local sn = ls.snippet_node
|
||||
-- local isn = ls.indent_snippet_node
|
||||
local t = ls.text_node
|
||||
-- local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
local f = ls.function_node
|
||||
-- local c = ls.choice_node
|
||||
|
@ -19,13 +19,13 @@ local f = ls.function_node
|
|||
-- local m = extras.match
|
||||
-- local n = extras.nonempty
|
||||
-- local dl = extras.dynamic_lambda
|
||||
-- local fmt = require("luasnip.extras.fmt").fmt
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
-- local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local conds = require("luasnip.extras.expand_conditions")
|
||||
-- local postfix = require("luasnip.extras.postfix").postfix
|
||||
-- local types = require("luasnip.util.types")
|
||||
-- local parse = require("luasnip.util.parser").parse_snippet
|
||||
-- local ms = ls.multi_snippet
|
||||
local ms = ls.multi_snippet
|
||||
|
||||
local function has_value(tab, val)
|
||||
for _, value in ipairs(tab) do
|
||||
|
@ -46,20 +46,48 @@ end
|
|||
|
||||
return {
|
||||
}, {
|
||||
s({ trig = "^beg", regTrig = true, wordTrig = false, name = "begin{} / end{}" }, {
|
||||
t "\\begin{", i(1), t({ "}", "\t" }),
|
||||
i(0),
|
||||
t({ "", "\\end{" }), reference(1), t "}"
|
||||
}),
|
||||
s({ trig = "mk", name = "Inline Math" }, {
|
||||
t "$", i(1), t "$", f(cond_space, 2), i(2)
|
||||
}),
|
||||
s({ trig = "dm", name = "Display Math" }, {
|
||||
t({ "\\[", "\t" }),
|
||||
i(1),
|
||||
t({ "", ".\\]" })
|
||||
}),
|
||||
s({ trig = "([A-Za-z])(%d)", regTrig = true, wordTrig = false, name = "Auto-Subscript" }, {
|
||||
capture(1), t "_", capture(2)
|
||||
})
|
||||
s({ trig = "^beg", regTrig = true, wordTrig = false, name = "begin{} / end{}" }, fmt([[
|
||||
\begin{{{}}}
|
||||
{}
|
||||
\end{{{}}}
|
||||
]], { i(1), i(0), reference(1) })),
|
||||
s({ trig = "mk", name = "Inline Math" }, fmt([[
|
||||
${}${}{}
|
||||
]], { i(1), f(cond_space, 2), i(2) })),
|
||||
s({ trig = "dm", name = "Display Math" }, fmt([[
|
||||
\[
|
||||
{}
|
||||
.\]
|
||||
]], { i(1) })),
|
||||
s({ trig = "([A-Za-z])(%d)", regTrig = true, name = "Subscript" }, fmt([[
|
||||
{}_{}
|
||||
]], { capture(1), capture(2) })),
|
||||
s({ trig = "([A-Za-z])_(%d)", regTrig = true, name = "Subscript" }, fmt([[
|
||||
{}_{{{}}}
|
||||
]], { capture(1), capture(2) })),
|
||||
s({ trig = " td", wordTrig = false, name = "Superscript" }, fmt([[
|
||||
^{{{}}}
|
||||
]], { i(1) })),
|
||||
s({ trig = " sr", wordTrig = false, name = "Square" }, fmt([[
|
||||
^2
|
||||
]], {})),
|
||||
s({ trig = " cb", wordTrig = false, name = "Cube" }, fmt([[
|
||||
^3
|
||||
]], {})),
|
||||
s({ trig = " cl", wordTrig = false, name = "Complement" }, fmt([[
|
||||
^{{c}}
|
||||
]], {})),
|
||||
s({ trig = "//", wordTrig = false, name = "Fraction" }, fmt([[
|
||||
\\frac{{{}}}{{{}}}
|
||||
]], { i(1), i(2) })),
|
||||
-- if lua patterns had conditionals this would be less of a mess
|
||||
-- unfortunately this also expands on incomplete ^{} superscripts e.g. 4\pi^2}/
|
||||
ms({
|
||||
{ trig = "(%d+)/" },
|
||||
{ trig = "(%d*\\?[A-Za-z]+[%^_]{?%d+}?)/", priority = 1001 },
|
||||
common = { regTrig = true, name = "Fraction" }
|
||||
}, fmt([[
|
||||
\\frac{{{}}}{{{}}}
|
||||
]], { capture(1), i(1) })),
|
||||
-- TODO: continue porting these snippets: https://castel.dev/post/lecture-notes-1/#fractions
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue