global !p def math(): return vim.eval('vimtex#syntax#in_mathzone()') == '1' def env(name): x, y = vim.eval(f"vimtex#env#is_inside('{name}')") return x != '0' and y != '0' endglobal snippet begin "Begin/end" bA \begin{$1} $0 \end{$1} endsnippet snippet enum "Enumerate" bA \begin{enumerate} \item $0 \end{enumerate} endsnippet snippet item "Itemize" bA \begin{itemize} \item $0 \end{itemize} endsnippet snippet desc "Description" bA \begin{description} \item[$1] $0 \end{description} endsnippet snippet define "Definition" bA \begin{definition}[$1] $0 \end{definition} endsnippet snippet example "Example" bA \begin{example} $1 \end{example} \begin{solution} $0 \end{solution} endsnippet snippet table "Table" b \begin{table}[${1:htpb}] \centering \caption{${2:caption}} \begin{tabular}{@{} ${5:c c} @{}} $0${5/((?<=.)[clr])|./(?1: & )/g} \end{tabular} \end{table} endsnippet snippet fig "Figure" b \begin{figure}[${1:htpb}] \centering ${2:\includegraphics[width=0.8\textwidth]{$3}} \caption{${4:$3}} \end{figure} endsnippet snippet plot "Plot" w \begin{figure}[$1] \centering \begin{tikzpicture} \begin{axis}[ title=$2, xlabel=$3, ylabel=$4 ] \addplot[$5]{$6}; \end{axis} \end{tikzpicture} \caption{$7} \end{figure} endsnippet context "env('tikzpicture')" snippet arrow "Arrow" w \draw[thick, ->] ($1,$2) -- ($3,$4);$0 endsnippet context "math()" snippet // "Fraction" iA \frac{$1}{$2}$0 endsnippet context "math()" snippet '((\d*\.?\d+)|(\d*)(\\)?([A-Za-z]+)((\^|_)(\{\d+\}|\d))*)/' "Fraction" wrA \frac{`!p snip.rv = match.group(1)`}{$1}$0 endsnippet priority 1000 context "math()" snippet '^.*\)/' "Fraction" wrA `!p depth = 1 i = len(match.string) - 3 while depth > 0 and i >= 0: if match.string[i] == ')': depth += 1 if match.string[i] == '(': depth -= 1 i -= 1 snip.rv = match.string[0:i+1] + '\\frac{' + match.string[i+2:-2] `}{$1}$0 endsnippet context "math()" snippet tt "Text" iA \text{$1}$0 endsnippet snippet ... "Ellipsis" iA \ldots endsnippet snippet == "Equals" iA &= $1 \\\\ endsnippet snippet != "neq" iA \neq endsnippet snippet >= "geq" iA \ge endsnippet snippet <= "leq" iA \le endsnippet snippet __ "Subscript" iA _{$1}$0 endsnippet snippet ^^ "Superscript" iA ^{$1}$0 endsnippet snippet ** "cdot" iA \cdot endsnippet snippet qty "Quantity" iA \qty{$1}{$2}$0 endsnippet snippet unit "Unit" i \unit{$1}$0 endsnippet priority 10 context "math()" snippet bar "bar" iA \overline{$1}$0 endsnippet priority 100 context "math()" snippet '([a-zA-Z])bar' "bar" riA \overline{`!p snip.rv=match.group(1)`} endsnippet priority 10 snippet deg "deg" iA \deg{$1}$0 endsnippet priority 100 snippet '([0-9]+)deg' "deg" riA \deg{`!p snip.rv=match.group(1)`} endsnippet