summaryrefslogtreecommitdiff
path: root/.vim/UltiSnips
diff options
context:
space:
mode:
authorSam Nystrom <sam@samnystrom.dev>2023-09-07 21:15:29 -0400
committerSam Nystrom <sam@samnystrom.dev>2023-09-07 21:15:29 -0400
commitf57ffebc41c61243db86ae5040222345dd5e896b (patch)
tree8d9f97b124dc6ac4c96d18b3242848f2719b103e /.vim/UltiSnips
parent75b05c0766b4fbb4d4abf2aaba5465c775942383 (diff)
vim: add latex snippets
Diffstat (limited to '.vim/UltiSnips')
-rw-r--r--.vim/UltiSnips/editorconfig.snippets8
-rw-r--r--.vim/UltiSnips/tex.snippets159
2 files changed, 167 insertions, 0 deletions
diff --git a/.vim/UltiSnips/editorconfig.snippets b/.vim/UltiSnips/editorconfig.snippets
new file mode 100644
index 0000000..c515868
--- /dev/null
+++ b/.vim/UltiSnips/editorconfig.snippets
@@ -0,0 +1,8 @@
+snippet template "Basic template" b
+root = true
+
+[*]
+charset = utf-8
+line_endings = lf
+insert_final_newline = true
+endsnippet
diff --git a/.vim/UltiSnips/tex.snippets b/.vim/UltiSnips/tex.snippets
new file mode 100644
index 0000000..65cd9c7
--- /dev/null
+++ b/.vim/UltiSnips/tex.snippets
@@ -0,0 +1,159 @@
+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 prob "Problem" b
+\problem{$1}
+$0
+endsnippet
+
+snippet part "Part" b
+\subproblem{$1}
+$0
+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
+
+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