552 lines
9.6 KiB
Plaintext
552 lines
9.6 KiB
Plaintext
|
global !p
|
||
|
def math():
|
||
|
return vim.eval('vimtex#syntax#in_mathzone()') == '1'
|
||
|
|
||
|
def comment():
|
||
|
return vim.eval('vimtex#syntax#in_comment()') == '1'
|
||
|
|
||
|
def env(name):
|
||
|
[x,y] = vim.eval("vimtex#env#is_inside('" + name + "')")
|
||
|
return x != '0' and y != '0'
|
||
|
|
||
|
endglobal
|
||
|
|
||
|
|
||
|
# Color boxes =================================================<<<{{{
|
||
|
snippet block "Simple box with colored border, interior, and text"
|
||
|
\begin{tcolorbox}[
|
||
|
coltext={${1:gruv-box-yellow}},
|
||
|
colback={${2:gruv-box-background}},
|
||
|
colframe={$1}]
|
||
|
$3
|
||
|
\end{tcolorbox}$4
|
||
|
endsnippet
|
||
|
|
||
|
snippet titlebox "Box with a centered title and color option" A
|
||
|
\begin{tcolorbox}[title={\centering ${1:untitled}},
|
||
|
colframe={${2:Magenta!75!black}}]
|
||
|
$3
|
||
|
\end{tcolorbox}$4
|
||
|
endsnippet
|
||
|
|
||
|
snippet splitbox "Box with a top, bottom, and title"
|
||
|
\begin{tcolorbox}[title={${1:untitled}},colframe={${2:Magenta}}]
|
||
|
$3
|
||
|
\tcblower
|
||
|
$4
|
||
|
\end{tcolorbox}$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet minipage "Small page indent" A
|
||
|
\hfill\begin{minipage}{\dimexpr\textwidth-2.2cm}
|
||
|
$1
|
||
|
\end{minipage}$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet ebox "Box for containing examples"
|
||
|
\hfill\begin{minipage}{\dimexpr\textwidth-2.2cm}
|
||
|
\begin{tcolorbox}[title={${1:Ex: untitled}},colframe={${2:Magenta!75!black}}]
|
||
|
$3
|
||
|
\end{tcolorbox}\medskip
|
||
|
\end{minipage}$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet inbox "Indented titled box"
|
||
|
\hfill\begin{minipage}{\dimexpr\textwidth-2.2cm}
|
||
|
\begin{tcolorbox}[title={${1:untitled}},colframe={${2:Magenta!75!black}}]
|
||
|
$3
|
||
|
\end{tcolorbox}\medskip
|
||
|
\end{minipage}$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet code "Code environment"
|
||
|
\begin{lstlisting}
|
||
|
$1
|
||
|
\end{lstlisting}$2
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Environments ================================================<<<{{{
|
||
|
snippet begin "begin{} / end{}" bA
|
||
|
\\begin{$1}
|
||
|
$0
|
||
|
\\end{$1}
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet case "cases" wA
|
||
|
\begin{cases}
|
||
|
$1
|
||
|
\end{cases}
|
||
|
endsnippet
|
||
|
|
||
|
snippet enum "Enumerate" bA
|
||
|
\begin{enumerate}
|
||
|
\item $0
|
||
|
\end{enumerate}
|
||
|
endsnippet
|
||
|
|
||
|
priority 100
|
||
|
snippet item "First item" bA
|
||
|
\item $0
|
||
|
endsnippet
|
||
|
|
||
|
snippet desc "Description" b
|
||
|
\begin{description}
|
||
|
\item[$1] $0
|
||
|
\end{description}
|
||
|
endsnippet
|
||
|
|
||
|
snippet mk "Math" wA
|
||
|
$${1}$$2
|
||
|
endsnippet
|
||
|
|
||
|
snippet dm "Math" wA
|
||
|
\[
|
||
|
${1:${VISUAL}}
|
||
|
\] $0
|
||
|
endsnippet
|
||
|
|
||
|
snippet dl "Math" wA
|
||
|
\[ ${1:${VISUAL}} \]$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet align "Align" bA
|
||
|
\begin{align*}
|
||
|
${1:${VISUAL}}
|
||
|
\end{align*}
|
||
|
endsnippet
|
||
|
|
||
|
priority 10
|
||
|
snippet item "Itemize" bA
|
||
|
\begin{itemize}
|
||
|
\item $0
|
||
|
\end{itemize}
|
||
|
endsnippet
|
||
|
|
||
|
snippet chmargin "Bigger left margin" bA
|
||
|
\begin{changemargin}{3cm}{0cm}
|
||
|
$0
|
||
|
\end{changemargin}
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Fractions ===================================================<<<{{{
|
||
|
context "math()"
|
||
|
snippet // "Standard fraction, nothing fancy" iA
|
||
|
\\frac{$1}{$2}$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet / "Fraction" i
|
||
|
\\frac{${VISUAL}}{$1}$0
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet '(-?(\d+)|(\d*)(\\)?([A-Za-z]+)((\^|_)(\{\d+\}|\d))*)/' "powerful frac like 2/" wrA
|
||
|
\\frac{`!p snip.rv = match.group(1)`}{$1}$0
|
||
|
endsnippet
|
||
|
|
||
|
priority 1000
|
||
|
context "math()"
|
||
|
snippet '^.*\)/' "() frac" wrA
|
||
|
`!p
|
||
|
stripped = match.string[:-1]
|
||
|
depth = 0
|
||
|
i = len(stripped) - 1
|
||
|
while True:
|
||
|
if stripped[i] == ')': depth += 1
|
||
|
if stripped[i] == '(': depth -= 1
|
||
|
if depth == 0: break;
|
||
|
i-=1
|
||
|
snip.rv = stripped[0:i] + "\\frac{" + stripped[i+1:-1] + "}"
|
||
|
`{$1} $0
|
||
|
endsnippet
|
||
|
|
||
|
snippet part "partial derivative d/dx" w
|
||
|
\frac{\partial ${1:V}}{\partial ${2:x}}$0
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Sub/Super scripts ===========================================<<<{{{
|
||
|
priority 10
|
||
|
context "math()"
|
||
|
snippet '([A-Za-z])(-?\d) ' "auto exponentiate like x-2 -> x^{-2}" wrA
|
||
|
`!p snip.rv = match.group(1)`^{`!p snip.rv = match.group(2)`} $0
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet td "exponentiate" iA
|
||
|
^{$1}$0
|
||
|
endsnippet
|
||
|
|
||
|
priority 20
|
||
|
context "math()"
|
||
|
snippet '([A-Za-z])_([-\w\d]{2,})(,)? ' "auto subscript after space" wrA
|
||
|
`!p snip.rv = match.group(1)`_{`!p snip.rv = match.group(2)`}`!p
|
||
|
if match.group(3) is not None:
|
||
|
snip.rv = match.group(3)`$0
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet '([A-Za-z|\]])ud' "auto 上下 script" wrA
|
||
|
`!p snip.rv = match.group(1)`^{${1:exp}}_{${2:sub}} $0
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet sqrt "\sqrt{}" iA
|
||
|
\sqrt{${1:${VISUAL}}}$0
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Equality shortcuts ==========================================<<<{{{
|
||
|
snippet == "aligned equals" iA
|
||
|
&= $1 \\\\
|
||
|
endsnippet
|
||
|
|
||
|
snippet n= "not equal" iA
|
||
|
\neq
|
||
|
endsnippet
|
||
|
|
||
|
snippet <= "leq" iA
|
||
|
\le
|
||
|
endsnippet
|
||
|
|
||
|
snippet >= "geq" iA
|
||
|
\ge
|
||
|
endsnippet
|
||
|
|
||
|
snippet >> ">>" iA
|
||
|
\gg
|
||
|
endsnippet
|
||
|
|
||
|
snippet << "<<" iA
|
||
|
\ll
|
||
|
endsnippet
|
||
|
|
||
|
snippet ~~ "~" iA
|
||
|
\sim
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Matricies ===================================================<<<{{{
|
||
|
snippet (mat "round brackets" i
|
||
|
\begin{pmatrix}
|
||
|
$1
|
||
|
\end{pmatrix} $0
|
||
|
endsnippet
|
||
|
|
||
|
snippet [mat "square brackets" i
|
||
|
\begin{bmatrix}
|
||
|
$1
|
||
|
\end{bmatrix} $0
|
||
|
endsnippet
|
||
|
|
||
|
snippet |mat "square brackets" i
|
||
|
\begin{vmatrix}
|
||
|
$1
|
||
|
\end{vmatrix} $0
|
||
|
endsnippet
|
||
|
|
||
|
priority 100
|
||
|
snippet cvec "column vector" iA
|
||
|
\begin{pmatrix} ${1:x}_${2:1}\\\\ \vdots\\\\ $1_${2:n} \end{pmatrix}
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Enclosing delimiters ========================================<<<{{{
|
||
|
context "math()"
|
||
|
snippet () "() delimiters" iA
|
||
|
\left( ${1:${VISUAL}} \right)$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet lr "() delimiters" i
|
||
|
\left( ${1:${VISUAL}} \right)$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet lr( "() delimiters" i
|
||
|
\left( ${1:${VISUAL}} \right)$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet lr| "|| delimiters" i
|
||
|
\left| ${1:${VISUAL}} \right|$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet lr|| "|| || for vector magnitudes" i
|
||
|
\left\| ${1:${VISUAL}} \right\|$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet lr{ "{} delimiters" i
|
||
|
\left\\{ ${1:${VISUAL}} \right\\}$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet lrb "{} delimiters" i
|
||
|
\left\\{ ${1:${VISUAL}} \right\\}$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet lr[ "[] delimiters" i
|
||
|
\left[ ${1:${VISUAL}} \right]$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet lr< "<> delimiters" i
|
||
|
\left< ${1:${VISUAL}} \right>$0
|
||
|
endsnippet
|
||
|
|
||
|
snippet lra "<> delimiters" iA
|
||
|
\left<${1:${VISUAL}} \right>$0
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet set "set" wA
|
||
|
\\{$1\\} $0
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Math symbols with numbers ===================================<<<{{{
|
||
|
snippet sum "sum" w
|
||
|
\sum_{i=${1:0}}^{${2:\infty}} ${3:a_i z^i}
|
||
|
endsnippet
|
||
|
|
||
|
snippet taylor "taylor" w
|
||
|
\sum_{${1:k}=${2:0}}^{${3:\infty}} ${4:c_$1} (x-a)^$1 $0
|
||
|
endsnippet
|
||
|
|
||
|
snippet lim "limit" w
|
||
|
\lim_{${1:x} \to ${2:\infty}} $0
|
||
|
endsnippet
|
||
|
|
||
|
priority 300
|
||
|
context "math()"
|
||
|
snippet dint "integral" wA
|
||
|
\int_{${1:-\infty}}^{${2:\infty}} $4 \,d${3:x}$0
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Symbol shortcuts ============================================<<<{{{
|
||
|
snippet ooo "\infty" iA
|
||
|
\infty
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet EE "geq" iA
|
||
|
\exists
|
||
|
endsnippet
|
||
|
|
||
|
priority 300
|
||
|
context "math()"
|
||
|
snippet 'prime(\d+)' "prime like x^(4)" wrA
|
||
|
^{(`!p snip.rv = match.group(1)`)} $0
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet AA "forall" iA
|
||
|
\forall
|
||
|
endsnippet
|
||
|
|
||
|
snippet lll "l" iA
|
||
|
\ell
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet nabla "nabla" iA
|
||
|
\nabla
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet xx "cross" iA
|
||
|
\times
|
||
|
endsnippet
|
||
|
|
||
|
priority 100
|
||
|
snippet ** "cdot" iA
|
||
|
\cdot
|
||
|
endsnippet
|
||
|
|
||
|
priority 100
|
||
|
context "math()"
|
||
|
snippet -> "to" iA
|
||
|
\to
|
||
|
endsnippet
|
||
|
|
||
|
priority 200
|
||
|
context "math()"
|
||
|
snippet <-> "leftrightarrow" iA
|
||
|
\leftrightarrow
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet !> "mapsto" iA
|
||
|
\mapsto
|
||
|
endsnippet
|
||
|
|
||
|
snippet Nn "cap" iA
|
||
|
\cap
|
||
|
endsnippet
|
||
|
|
||
|
snippet UU "cup" iA
|
||
|
\cup
|
||
|
endsnippet
|
||
|
|
||
|
snippet uuu "bigcup" iA
|
||
|
\bigcup_{${1:i \in ${2: I}}} $0
|
||
|
endsnippet
|
||
|
|
||
|
snippet nnn "bigcap" iA
|
||
|
\bigcap_{${1:i \in ${2: I}}} $0
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet iff "iff" Ai
|
||
|
\iff
|
||
|
endsnippet
|
||
|
|
||
|
priority 100
|
||
|
snippet ... "ldots" iA
|
||
|
\ldots
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Set related symbols =========================================<<<{{{
|
||
|
priority 10
|
||
|
context "math()"
|
||
|
snippet 'cc ' "subset" rAi
|
||
|
\\subset $0
|
||
|
endsnippet
|
||
|
|
||
|
snippet notin "not in " iA
|
||
|
\not\in
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet inn "in " iA
|
||
|
\in
|
||
|
endsnippet
|
||
|
|
||
|
snippet NN "n" iA
|
||
|
\N
|
||
|
endsnippet
|
||
|
|
||
|
snippet OO "emptyset" iA
|
||
|
\O
|
||
|
endsnippet
|
||
|
|
||
|
snippet RR "real" iA
|
||
|
\R
|
||
|
endsnippet
|
||
|
|
||
|
snippet QQ "Q" iA
|
||
|
\Q
|
||
|
endsnippet
|
||
|
|
||
|
snippet ZZ "Z" iA
|
||
|
\Z
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Symbols right on top ========================================<<<{{{
|
||
|
context "math()"
|
||
|
snippet conj "conjugate" iA
|
||
|
\overline{$1}$0
|
||
|
endsnippet
|
||
|
|
||
|
priority 10
|
||
|
context "math()"
|
||
|
snippet "bar" "bar" riA
|
||
|
\bar{$1}$0
|
||
|
endsnippet
|
||
|
# Used to be: \overline{$1}$0
|
||
|
|
||
|
|
||
|
priority 100
|
||
|
context "math()"
|
||
|
snippet "([a-zA-Z])bar" "bar" riA
|
||
|
\overline{`!p snip.rv=match.group(1)`}
|
||
|
endsnippet
|
||
|
|
||
|
priority 10
|
||
|
context "math()"
|
||
|
snippet "hat" "hat" riA
|
||
|
\hat{$1}$0
|
||
|
endsnippet
|
||
|
|
||
|
priority 100
|
||
|
context "math()"
|
||
|
snippet "([a-zA-Z])hat" "hat" riA
|
||
|
\hat{`!p snip.rv=match.group(1)`}
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Mathematical functions ======================================<<<{{{
|
||
|
priority 100
|
||
|
context "math()"
|
||
|
snippet '(?<!\\)(sin|cos|tan|arccot|sec|cot|csc|ln|log|exp|star|perp)' "ln" rwA
|
||
|
\\`!p snip.rv = match.group(1)`
|
||
|
endsnippet
|
||
|
|
||
|
priority 200
|
||
|
context "math()"
|
||
|
snippet '(?<!\\)(arcsin|arccos|arctan|arccot|arccsc|arcsec|pi|zeta|theta|phi)' "ln" rwA
|
||
|
\\`!p snip.rv = match.group(1)`$0
|
||
|
endsnippet
|
||
|
|
||
|
|
||
|
priority 30
|
||
|
context "math"
|
||
|
snippet ' (?<!\\)int(_[A-Za-z]+)? ' "blank integral, with possible subscript" rwA
|
||
|
\\int`!p
|
||
|
if match.group(1) is not None:
|
||
|
snip.rv = "_{" + match.group(1)[1:] + "}"`$0
|
||
|
endsnippet
|
||
|
|
||
|
priority 20
|
||
|
context "math()"
|
||
|
snippet 'vec([A-Za-z0])(_((\{\w+\})?|(\w)))? ' "vector arrow [with subscript]" rwA
|
||
|
\\vec{`!p
|
||
|
snip.rv = match.group(1)
|
||
|
|
||
|
if match.group(2) is not None:
|
||
|
snip.rv += match.group(2)`}$0
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Misc ========================================================<<<{{{
|
||
|
context "math()"
|
||
|
snippet tt "text" iA
|
||
|
\text{$1}$0
|
||
|
endsnippet
|
||
|
|
||
|
context "math()"
|
||
|
snippet '(?<!\\)(mathbcal)' "Autocomplete for special chars" rwA
|
||
|
\\mathbcal{$1}$2
|
||
|
endsnippet
|
||
|
|
||
|
# }}}>>>
|
||
|
|
||
|
# Huge environments ===========================================<<<{{{
|
||
|
snippet template "Basic template" b
|
||
|
\documentclass[a4paper]{article}
|
||
|
|
||
|
\usepackage[margin=1in]{geometry} % Set margin preference
|
||
|
|
||
|
\input{~/.vim/UltiSnips/math_preamble.tex}
|
||
|
|
||
|
\begin{document}
|
||
|
\pagecolor{gruv-box-dark-bg}
|
||
|
\color{gruv-box-yellow}
|
||
|
\fontfamily{phv}\selectfont
|
||
|
|
||
|
$0
|
||
|
\end{document}
|
||
|
endsnippet
|