dotfiles

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

tex.lua (6126B)


      1 local ls = require("luasnip")
      2 local s = ls.snippet
      3 local sn = ls.snippet_node
      4 local t = ls.text_node
      5 local i = ls.insert_node
      6 local f = ls.function_node
      7 local d = ls.dynamic_node
      8 local fmt = require("luasnip.extras.fmt").fmt
      9 local fmta = require("luasnip.extras.fmt").fmta
     10 local rep = require("luasnip.extras").rep
     11 
     12 local in_mathzone = function()
     13     -- The `in_mathzone` function requires the VimTeX plugin
     14     return vim.fn['vimtex#syntax#in_mathzone']() == 1
     15 end
     16 return {
     17     -- math modes
     18     s({ trig = "mt", snippetType = "autosnippet" },
     19         fmta("$<>$ <>", { i(1), i(2) })
     20     ),
     21     s({ trig = "mmt", snippetType = "autosnippet" },
     22         fmta("$$<>$$ <>", { i(1), i(2) })
     23     ),
     24     s({ trig = "align", snippetType = "autosnippet" },
     25         fmta([[
     26     \begin{align*}
     27       <>
     28     \end{align*}
     29     ]], { i(1) })
     30     ),
     31     s({ trig = "text", snippetType = "autosnippet" },
     32         fmta("\\text{<>} ", { i(1) }),
     33         { condition = in_mathzone }
     34     ),
     35     s({ trig = "piecewise", snippetType = "autosnippet" },
     36         fmta([[
     37       <>=\begin{cases}
     38 			<> & \text{<>} \\
     39 			<> & \text{<>}
     40       \end{cases}
     41     ]], { i(1), i(2), i(3), i(4), i(5) })
     42     ),
     43     s({ trig = "cases", snippetType = "autosnippet" },
     44         fmta([[
     45     \[
     46       \begin{minipage}{.50\linewidth}
     47         \centering
     48         \textbf{Case} <>
     49         \begin{align*}
     50         \end{align*}
     51       \end{minipage}%
     52       \begin{minipage}{.50\linewidth}
     53         \centering
     54         \textbf{Case} <>
     55         \begin{align*}
     56         \end{align*}
     57       \end{minipage}
     58     \]
     59     ]], { i(1), i(2) })
     60     ),
     61     s({ trig = "gaussian", snippetType = "autosnippet" },
     62         fmta([[
     63 	\left[
     64 		\begin{array}{ccc|c}
     65 			<> & <> & <> & <>  \\
     66 		\end{array}
     67 		\right]
     68     ]], { i(1), i(2), i(3), i(4) })
     69     ),
     70     s({ trig = "linsys", snippetType = "autosnippet" },
     71         fmta([[
     72     \[
     73         \begin{matrix}
     74         <> &  \\
     75         \end{matrix}
     76     \]
     77     ]], { i(1) })
     78     ),
     79     -- font Modes
     80     s({ trig = "Bld", snippetType = "autosnippet" },
     81         fmta("\\textbf{<>} ", { i(1) })
     82     ),
     83     -- Discrete Math
     84     s({ trig = "st.", snippetType = "autosnippet" },
     85         { t("such that ") }
     86     ),
     87     s({ trig = "fix12", snippetType = "autosnippet" },
     88         fmta("fix $x_1, x_2 \\in <>$", { i(1) })
     89     ),
     90     s({ trig = "Rn", snippetType = "autosnippet" },
     91         { t("\\mathbb{R} ") },
     92         { t("\\mathbb{R}") },
     93         { condition = in_mathzone }
     94     ),
     95     s({ trig = "Nn", snippetType = "autosnippet" },
     96         { t("\\mathbb{N} ") },
     97         { t("\\mathbb{N}") },
     98         { condition = in_mathzone }
     99     ),
    100     s({ trig = "Qn", snippetType = "autosnippet" },
    101         { t("\\mathbb{Q} ") },
    102         { t("\\mathbb{Q}") },
    103         { condition = in_mathzone }
    104     ),
    105     s({ trig = "Zn", snippetType = "autosnippet" },
    106         { t("\\mathbb{Z} ") },
    107         { t("\\mathbb{Z}") },
    108         { condition = in_mathzone }
    109     ),
    110     s({ trig = "and", snippetType = "autosnippet" },
    111         { t("\\land ") },
    112         { condition = in_mathzone }
    113     ),
    114     s({ trig = "or", snippetType = "autosnippet" },
    115         { t("\\lor ") },
    116         { condition = in_mathzone }
    117     ),
    118     s({ trig = "implies", snippetType = "autosnippet" },
    119         { t("\\implies") },
    120         { condition = in_mathzone }
    121     ),
    122     s({ trig = "dots", snippetType = "autosnippet" },
    123         { t("\\dots") },
    124         { condition = in_mathzone }
    125     ),
    126     s({ trig = "forall", snippetType = "autosnippet" },
    127         { t("\\forall") },
    128         { condition = in_mathzone }
    129     ),
    130     s({ trig = "exists", snippetType = "autosnippet" },
    131         { t("\\exists") },
    132         { condition = in_mathzone }
    133     ),
    134     -- sets
    135     s({ trig = "set", snippetType = "autosnippet" },
    136         fmta("\\{<> \\}", { i(1) }),
    137         { condition = in_mathzone }
    138     ),
    139     s({ trig = "ins", snippetType = "autosnippet" },
    140         { t("\\in ") },
    141         { condition = in_mathzone }
    142     ),
    143     s({ trig = "sub", snippetType = "autosnippet" },
    144         { t("\\subseteq") },
    145         { condition = in_mathzone }
    146     ),
    147     s({ trig = "cross", snippetType = "autosnippet" },
    148         { t("\\times") },
    149         { condition = in_mathzone }
    150     ),
    151     s({ trig = "union", snippetType = "autosnippet" },
    152         { t("\\cup") },
    153         { condition = in_mathzone }
    154     ),
    155     s({ trig = "inter", snippetType = "autosnippet" },
    156         { t("\\cap") },
    157         { condition = in_mathzone }
    158     ),
    159     s({ trig = "empty", snippetType = "autosnippet" },
    160         { t("\\emptyset") },
    161         { condition = in_mathzone }
    162     ),
    163     -- general math
    164     s({ trig = "geq", snippetType = "autosnippet" },
    165         { t("\\geq") },
    166         { condition = in_mathzone }
    167     ),
    168     s({ trig = "of", snippetType = "autosnippet" },
    169         { t("\\circ") },
    170         { condition = in_mathzone }
    171     ),
    172     s({ trig = "sq", snippetType = "autosnippet" },
    173         fmta("\\sqrt{<>}", { i(1) }),
    174         { condition = in_mathzone }
    175     ),
    176     s({ trig = "FoG", snippetType = "autosnippet" },
    177         { t("f\\circ g") },
    178         { condition = in_mathzone }
    179     ),
    180     s({ trig = "GoF", snippetType = "autosnippet" },
    181         { t("g\\circ f") },
    182         { condition = in_mathzone }
    183     ),
    184     s({ trig = "neq", snippetType = "autosnippet" },
    185         { t("\\neq") },
    186         { condition = in_mathzone }
    187     ),
    188     s({ trig = "leq", snippetType = "autosnippet" },
    189         { t("\\leq") },
    190         { condition = in_mathzone }
    191     ),
    192 
    193     -- fractions, subscript, superscript, and other regex triggers
    194     s({ trig = "([%w%p]+)/", regTrig = true, wordTrig = false, snippetType = "autosnippet" },
    195         fmta("\\frac{<>}{<>}",
    196             { f(function(_, snip) return snip.captures[1] end, {}),
    197                 i(1)
    198             }),
    199         { condition = in_mathzone }
    200     ),
    201     s({ trig = "([%a])([%d])", regTrig = true, wordTrig = false, snippetType = "autosnippet" },
    202         fmta("<>_{<><>}",
    203             {
    204                 f(function(_, snip) return snip.captures[1] end, {}),
    205                 f(function(_, snip) return snip.captures[2] end, {}),
    206                 i(1)
    207             }),
    208         { condition = in_mathzone }
    209     ),
    210 }