@@ -35,38 +35,83 @@ local autosnippet = ls.extend_decorator.apply(s, { snippetType = "autosnippet" }
3535local tex = require (" luasnip-latex-snippets.luasnippets.tex.utils.conditions" )
3636local auto_backslash_snippet = require (" luasnip-latex-snippets.luasnippets.tex.utils.scaffolding" ).auto_backslash_snippet
3737local symbol_snippet = require (" luasnip-latex-snippets.luasnippets.tex.utils.scaffolding" ).symbol_snippet
38+ local single_command_snippet = require (" luasnip-latex-snippets.luasnippets.tex.utils.scaffolding" ).single_command_snippet
3839
3940M = {
41+ -- superscripts
42+ autosnippet ({ trig = " sr" , wordTrig = false },
43+ { t (" ^2" ) },
44+ { condition = tex .in_math , show_condition = tex .in_math }),
45+ autosnippet ({ trig = " cb" , wordTrig = false },
46+ { t (" ^3" ) },
47+ { condition = tex .in_math , show_condition = tex .in_math }),
48+ autosnippet ({ trig = " compl" , wordTrig = false },
49+ { t (" ^{c}" ) },
50+ { condition = tex .in_math , show_condition = tex .in_math }),
51+ autosnippet ({ trig = " vtr" , wordTrig = false },
52+ { t (" ^{T}" ) },
53+ { condition = tex .in_math , show_condition = tex .in_math }),
54+ autosnippet ({ trig = " inv" , wordTrig = false },
55+ { t (" ^{-1}" ) },
56+ { condition = tex .in_math , show_condition = tex .in_math }),
57+
4058 autosnippet ({ trig = " lim" , name = " lim(sup|inf)" , dscr = " lim(sup|inf)" },
4159 fmta ([[
4260 \lim<><><>
4361 ]] ,
4462 {c (1 , { t (" " ), t (" sup" ), t (" inf" ) }),
4563 c (2 , { t (" " ), fmta ([[ _{<> \to <>}]] , { i (1 , " n" ), i (2 , " \\ infty" ) }) }),
46- i (0 )}
47- ),
64+ i (0 )}),
4865 { condition = tex .in_math , show_condition = tex .in_math }),
66+
4967 autosnippet ({ trig = " sum" , name = " summation" , dscr = " summation" },
5068 fmta ([[
5169 \sum<> <>
5270 ]] ,
5371 { c (1 , {fmta ([[ _{<>}^{<>}]] , {i (1 , " i = 0" ), i (2 , " \\ infty" )}), t (" " )}), i (0 ) }),
54- { condition = tex .in_math , show_condition = tex .in_math }
55- ),
72+ { condition = tex .in_math , show_condition = tex .in_math }),
73+
5674 autosnippet ({ trig = " prod" , name = " product" , dscr = " product" },
5775 fmta ([[
5876 \prod<> <>
5977 ]] ,
6078 { c (1 , {fmta ([[ _{<>}^{<>}]] , {i (1 , " i = 0" ), i (2 , " \\ infty" )}), t (" " )}), i (0 ) }),
61- { condition = tex .in_math , show_condition = tex .in_math }
62- ),
79+ { condition = tex .in_math , show_condition = tex .in_math }),
80+
6381 autosnippet ({ trig = " cprod" , name = " coproduct" , dscr = " coproduct" },
6482 fmta ([[
6583 \coprod<> <>
6684 ]] ,
6785 { c (1 , {fmta ([[ _{<>}^{<>}]] , {i (1 , " i = 0" ), i (2 , " \\ infty" )}), t (" " )}), i (0 ) }),
68- { condition = tex .in_math , show_condition = tex .in_math }
69- ),
86+ { condition = tex .in_math , show_condition = tex .in_math }),
87+
88+ autosnippet ({ trig = " set" , name = " set" , dscr = " set" }, -- overload with set builder notation
89+ fmta ([[
90+ \{<>\}<>
91+ ]] ,
92+ { c (1 , { r (1 , " " ), sn (nil , { r (1 , " " ), t (" \\ mid " ), i (2 ) }) }), i (0 ) }),
93+ { condition = tex .in_math , show_condition = tex .in_math }),
94+
95+ autosnippet ({ trig = " nnn" , name = " bigcap" , dscr = " bigcap" },
96+ fmta ([[
97+ \bigcap<> <>
98+ ]] ,
99+ { c (1 , {fmta ([[ _{<>}^{<>}]] , {i (1 , " i = 0" ), i (2 , " \\ infty" )}), t (" " )}), i (0 ) }),
100+ { condition = tex .in_math , show_condition = tex .in_math }),
101+
102+ autosnippet ({ trig = " uuu" , name = " bigcup" , dscr = " bigcup" },
103+ fmta ([[
104+ \bigcup<> <>
105+ ]] ,
106+ { c (1 , {fmta ([[ _{<>}^{<>}]] , {i (1 , " i = 0" ), i (2 , " \\ infty" )}), t (" " )}), i (0 ) }),
107+ { condition = tex .in_math , show_condition = tex .in_math }),
108+
109+ autosnippet ({ trig = " bnc" , name = " binomial" , dscr = " binomial (nCR)" },
110+ fmta ([[
111+ \binom{<>}{<>}<>
112+ ]] ,
113+ { i (1 ), i (2 ), i (0 ) }),
114+ { condition = tex .in_math , show_condition = tex .in_math }),
70115}
71116
72117-- Auto backslashes
@@ -137,5 +182,161 @@ for k, v in pairs(greek_specs) do
137182end
138183vim .list_extend (M , greek_snippets )
139184
185+ local symbol_specs = {
186+ -- operators
187+ [" !=" ] = { context = { name = " !=" }, command = [[ \neq]] },
188+ [" <=" ] = { context = { name = " ≤" }, command = [[ \leq]] },
189+ [" >=" ] = { context = { name = " ≥" }, command = [[ \geq]] },
190+ [" <<" ] = { context = { name = " <<" }, command = [[ \ll]] },
191+ [" >>" ] = { context = { name = " >>" }, command = [[ \gg]] },
192+ [" ~~" ] = { context = { name = " ~" }, command = [[ \sim]] },
193+ [" ~=" ] = { context = { name = " ≈" }, command = [[ \approx]] },
194+ [" ~-" ] = { context = { name = " ≃" }, command = [[ \simeq]] },
195+ [" -~" ] = { context = { name = " ⋍" }, command = [[ \backsimeq]] },
196+ [" -=" ] = { context = { name = " ≡" }, command = [[ \equiv]] },
197+ [" =~" ] = { context = { name = " ≅" }, command = [[ \cong]] },
198+ [" :=" ] = { context = { name = " ≔" }, command = [[ \definedas]] },
199+ [" **" ] = { context = { name = " ·" , priority = 100 }, command = [[ \cdot]] },
200+ xx = { context = { name = " ×" }, command = [[ \times]] },
201+ [" !+" ] = { context = { name = " ⊕" }, command = [[ \oplus]] },
202+ [" !*" ] = { context = { name = " ⊗" }, command = [[ \otimes]] },
203+ -- sets
204+ NN = { context = { name = " ℕ" }, command = [[ \mathbb{N}]] },
205+ ZZ = { context = { name = " ℤ" }, command = [[ \mathbb{Z}]] },
206+ QQ = { context = { name = " ℚ" }, command = [[ \mathbb{Q}]] },
207+ RR = { context = { name = " ℝ" }, command = [[ \mathbb{R}]] },
208+ CC = { context = { name = " ℂ" }, command = [[ \mathbb{C}]] },
209+ OO = { context = { name = " ∅" }, command = [[ \emptyset]] },
210+ pwr = { context = { name = " P" }, command = [[ \powerset]] },
211+ cc = { context = { name = " ⊂" }, command = [[ \subset]] },
212+ cq = { context = { name = " ⊆" }, command = [[ \subseteq]] },
213+ qq = { context = { name = " ⊃" }, command = [[ \supset]] },
214+ qc = { context = { name = " ⊇" }, command = [[ \supseteq]] },
215+ [" \\\\\\ " ] = { context = { name = " ⧵" }, command = [[ \setminus]] },
216+ Nn = { context = { name = " ∩" }, command = [[ \cap]] },
217+ UU = { context = { name = " ∪" }, command = [[ \cup]] },
218+ [" ::" ] = { context = { name = " :" }, command = [[ \colon]] },
219+ -- quantifiers and logic stuffs
220+ AA = { context = { name = " ∀" }, command = [[ \forall]] },
221+ EE = { context = { name = " ∃" }, command = [[ \exists]] },
222+ inn = { context = { name = " ∈" }, command = [[ \in]] },
223+ notin = { context = { name = " ∉" }, command = [[ \not\in]] },
224+ [" !-" ] = { context = { name = " ¬" }, command = [[ \lnot]] },
225+ VV = { context = { name = " ∨" }, command = [[ \lor]] },
226+ WW = { context = { name = " ∧" }, command = [[ \land]] },
227+ [" !W" ] = { context = { name = " ∧" }, command = [[ \bigwedge]] },
228+ [" =>" ] = { context = { name = " ⇒" }, command = [[ \implies]] },
229+ [" =<" ] = { context = { name = " ⇐" }, command = [[ \impliedby]] },
230+ iff = { context = { name = " ⟺" }, command = [[ \iff]] },
231+ [" ->" ] = { context = { name = " →" , priority = 250 }, command = [[ \to]] },
232+ [" !>" ] = { context = { name = " ↦" }, command = [[ \mapsto]] },
233+ [" <-" ] = { context = { name = " ↦" , priority = 250 }, command = [[ \gets]] },
234+ -- differentials
235+ dp = { context = { name = " ⇐" }, command = [[ \partial]] },
236+ -- arrows
237+ [" -->" ] = { context = { name = " ⟶" , priority = 500 }, command = [[ \longrightarrow]] },
238+ [" <->" ] = { context = { name = " ↔" , priority = 500 }, command = [[ \leftrightarrow]] },
239+ [" 2>" ] = { context = { name = " ⇉" , priority = 400 }, command = [[ \rightrightarrows]] },
240+ upar = { context = { name = " ↑" }, command = [[ \uparrow]] },
241+ dnar = { context = { name = " ↓" }, command = [[ \downarrow]] },
242+ -- etc
243+ ooo = { context = { name = " ∞" }, command = [[ \infty]] },
244+ lll = { context = { name = " ℓ" }, command = [[ \ell]] },
245+ dag = { context = { name = " †" }, command = [[ \dagger]] },
246+ [" +-" ] = { context = { name = " †" }, command = [[ \pm]] },
247+ [" -+" ] = { context = { name = " †" }, command = [[ \mp]] },
248+ }
249+
250+ local symbol_snippets = {}
251+ for k , v in pairs (symbol_specs ) do
252+ table.insert (
253+ symbol_snippets ,
254+ symbol_snippet (vim .tbl_deep_extend (" keep" , { trig = k }, v .context ), v .command , { condition = tex .in_math })
255+ )
256+ end
257+ vim .list_extend (M , symbol_snippets )
258+
259+ local single_command_math_specs = {
260+ tt = {
261+ context = {
262+ name = " text (math)" ,
263+ dscr = " text in math mode" ,
264+ },
265+ command = [[ \text]] ,
266+ },
267+ sbf = {
268+ context = {
269+ name = " symbf" ,
270+ dscr = " bold math text" ,
271+ },
272+ command = [[ \symbf]] ,
273+ },
274+ syi = {
275+ context = {
276+ name = " symit" ,
277+ dscr = " italic math text" ,
278+ },
279+ command = [[ \symit]] ,
280+ },
281+ udd = {
282+ context = {
283+ name = " underline (math)" ,
284+ dscr = " underlined text in math mode" ,
285+ },
286+ command = [[ \underline]] ,
287+ },
288+ conj = {
289+ context = {
290+ name = " conjugate" ,
291+ dscr = " conjugate (overline)" ,
292+ },
293+ command = [[ \overline]] ,
294+ },
295+ [" __" ] = {
296+ context = {
297+ name = " subscript" ,
298+ dscr = " auto subscript 3" ,
299+ wordTrig = false ,
300+ },
301+ command = [[ _]] ,
302+ },
303+ td = {
304+ context = {
305+ name = " superscript" ,
306+ dscr = " auto superscript alt" ,
307+ wordTrig = false ,
308+ },
309+ command = [[ ^]] ,
310+ },
311+ sbt = {
312+ context = {
313+ name = " substack" ,
314+ dscr = " substack for sums/products" ,
315+ },
316+ command = [[ \substack]] ,
317+ },
318+ sq = {
319+ context = {
320+ name = " sqrt" ,
321+ dscr = " sqrt" ,
322+ },
323+ command = [[ \sqrt]] ,
324+ ext = { choice = true },
325+ },
326+ }
327+
328+ local single_command_math_snippets = {}
329+ for k , v in pairs (single_command_math_specs ) do
330+ table.insert (
331+ single_command_math_snippets ,
332+ single_command_snippet (
333+ vim .tbl_deep_extend (" keep" , { trig = k , snippetType = " autosnippet" }, v .context ),
334+ v .command ,
335+ { condition = tex .in_math },
336+ v .ext or {}
337+ )
338+ )
339+ end
340+ vim .list_extend (M , single_command_math_snippets )
140341
141342return M
0 commit comments