Skip to content

Instantly share code, notes, and snippets.

@DesyncTheThird
Last active October 26, 2024 04:38
Show Gist options
  • Save DesyncTheThird/0c7a18dc6bedaf27e2627c07f0c53e17 to your computer and use it in GitHub Desktop.
Save DesyncTheThird/0c7a18dc6bedaf27e2627c07f0c53e17 to your computer and use it in GitHub Desktop.
LaTeX Snippets
global
function math(context) {
return context.scopes.some(s => s.startsWith("meta.math"));
}
endglobal
snippet sec "subsection" i
\section{$1}$0
endsnippet
snippet ssec "subsection" i
\subsection{$1}$0
endsnippet
snippet sssec "subsection" i
\subsubsection{$1}$0
endsnippet
context math(context)
snippet // "Fraction simple" iA
``rv = `\\frac{${snip.tabstop(1,'')}}{${snip.tabstop(2,'')}}${snip.tabstop(3,'')}` ``
endsnippet
context math(context)
snippet `(\\?[a-zA-Z]+)\/` "fraction" A
\frac{``rv = m[1]``}{$1}$0
endsnippet
context math(context)
snippet `((\d+)|(\d*)(\\)?([A-Za-z]+)((\^|_)(\{\d+\}|\d))*)\/` "fraction" A
\frac{``rv = m[1]``}{$1}$0
endsnippet
context math(context)
snippet `^.*\)/` "fraction brackets" A
``
let str = m[0];
str = str.slice(0, -1);
let lastIndex = str.length - 1;
let depth = 0;
let i = str.length - 1;
while (true) {
if (str[i] == ')') depth += 1;
if (str[i] == '(') depth -= 1;
if (depth == 0) break;
i -= 1;
}
let results = str.slice(0, i) + "\\frac{" + str.slice(i+1, -1) + "}";
rv = results +`{${snip.tabstop(1,'')}}${snip.tabstop(2,'')}`;
``
endsnippet
snippet `mat([1-9])([1-9])` "matrix" A
``rv = '\\begin{bmatrix}'``
``count = 1;
msg = '';
for (i=0; i < parseInt(m[1],10); i++) {
msg += ' '
msg += ('00'+count).substr(-2,2);
count++;
for (j=1; j < parseInt(m[2],10); j++) {
msg += ' & '+('00'+count).substr(-2,2);
count++;
}
if (i != parseInt(m[1],10)-1) {
msg += ' \\\\\\ \n';
}
}
rv = msg;``
\\end{bmatrix}
endsnippet
snippet `idmat([1-9])` "identity matrix" A
``rv = '\\begin{bmatrix}'``
``count = 1;
msg = '';
for (i=0; i < parseInt(m[1],10); i++) {
msg += ' '
if (i==0){
msg += '1'
}
else{
msg +='0'
}
count++;
for (j=1; j < parseInt(m[1],10); j++) {
if (i==j){
msg += ' & '+'1';
}
else {
msg += ' & '+'0';
}
count++;
}
if (i != parseInt(m[1],10)-1) {
msg += ' \\\\\\ \n';
}
}
rv = msg;``
\\end{bmatrix}
endsnippet
snippet `vec([1-9])` "column vector" A
``rv = '\\begin{bmatrix}'``
``count=2;
msg = ' 1';
for (i = 1; i < parseInt(m[1],10); i++) {
msg += ' \\\\\\ \n '+count+'';
count++;
}
rv = msg;
``
\\end{bmatrix}
endsnippet
snippet defaxis "angle brackets" iA
\begin{axis}[
anchor={center},
at={(0,0)},
width=5cm,
height=5cm,
xmin=-1.9,
xmax=1.9,
ymin=-1.9,
ymax=1.9,
axis x line=center,
axis y line=center,
axis line style=thick,
xticklabels={},
yticklabels={},
xlabel={\$x\$},
ylabel={\$y\$},
xlabel style={right},
ylabel style={above},
grid=both,
]
${1}
\end{axis}
endsnippet
snippet `([a-zA-Z])([0-9]+) ` "underset"
``if ( m[2].length == 1 ) { a = '_'; b = ' '; }
else { a = '_{'; b = '} '; }
rv = m[1] + a + m[2] + b``
endsnippet
snippet `DFA#` "DFA" iA
(Q,\Sigma,q_0,F,\delta)
endsnippet
snippet `\s+~~` "relation" iA
\sim
endsnippet
snippet `~~` "relation" iA
\sim
endsnippet
context math(context)
snippet `(\\?\w+)(,\.|\.,)` "vector" i
``rv = '\\vec{' + m[1] + '}'``
endsnippet
context math(context)
snippet `\b([a-zA-Z])bar\b` "bar" A
``rv = '\\bar{' + m[1] + '}'``
endsnippet
snippet ` ?(\\?[a-zA-Z]+)~` "tilde" iA
``rv = '\\tilde{' + m[1] + '}'``
endsnippet
snippet `\\tilde\{([a-zA-Z])\}~` "sim" iA
``rv = m[1] + '\\sim'``
endsnippet
snippet `([a-zA-Z])^` "hat" iA
``rv = '\\hat{' + m[1] + '}'``
endsnippet
snippet ihat "ihat" A
\ihat
endsnippet
snippet jhat "jhat" A
\jhat
endsnippet
snippet nhat "nhat" iA
\hat{\mathbf{n}}
endsnippet
context math(context)
snippet `\b([abfhnrsuvxyz])hat\b` "hat" iA
``rv = '\\hat{' + m[1] + '}'``
endsnippet
context math(context)
snippet `\b([ruwxyz])dot\b` "uwxyz dot" iA
``rv = '\\dot{' + m[1] + '}'``
endsnippet
context math(context)
snippet `\b([a-zA-Z])ddot\b` "ddot" iA
``rv = '\\ddot{' + m[1] + '}'``
endsnippet
context math(context)
snippet `([a-zA-Z])elin` "overline" iA
``rv = '\\overline{' + m[1] + '}'``
endsnippet
context math(context)
snippet `([a-zA-Z])dlin` "underline" iA
``rv = '\\underline{' + m[1] + '}'``
endsnippet
context math(context)
snippet `([a-zA-Z])line#` "overline" iA
``rv = '\\overline{' + m[1] + '}'``
endsnippet
context math(context)
snippet `([a-zA-Z])line;` "underline" iA
``rv = '\\underline{' + m[1] + '}'``
endsnippet
snippet `([A-Z])cal` "mathcal" iA
``rv = '\\mathcal{' + m[1] + '}'``
endsnippet
snippet `([A-Z])pcal` "mathscr" iA
``rv = '\\mathscr{' + m[1] + '}'``
endsnippet
context math(context)
snippet `([a-zA-Z])frak` "mathfrak" iA
``rv = '\\mathfrak{' + m[1] + '}'``
endsnippet
snippet beni "enumerate" iA
\begin{enumerate}
\item[$(i)$] $1
\item[$(ii)$] $2
\end{enumerate}$0
endsnippet
snippet m "inline maths" i
$${1: }$$0
endsnippet
snippet `ek|hk|mk` "inline maths" A
$${1: }$$0
endsnippet
snippet aa "greek" i
\alpha
endsnippet
snippet AA "greek" i
\Alpha
endsnippet
snippet bb "greek" i
\beta
endsnippet
snippet BB "greek" i
B
endsnippet
snippet cc "greek" i
\chi
endsnippet
snippet CC "greek" i
X
endsnippet
snippet dd "greek" i
\delta
endsnippet
snippet DD "greek" i
\Delta
endsnippet
snippet DDv "var greek" i
\varDelta
endsnippet
snippet ee "greek" i
\epsilon
endsnippet
snippet eev "vargreek" i
\varepsilon
endsnippet
snippet EE "greek" i
endsnippet
snippet ff "greek" i
\phi
endsnippet
snippet ffv "var greek" i
\varphi
endsnippet
snippet FF "greek" i
\Phi
endsnippet
snippet FFv "var greek" i
\varPhi
endsnippet
snippet gg "greek" i
\gamma
endsnippet
snippet GG "greek" i
\Gamma
endsnippet
snippet GGv "var greek" i
\varGamma
endsnippet
snippet hh "greek" i
\eta
endsnippet
snippet HH "greek" i
H
endsnippet
snippet ii"greek" i
\iota
endsnippet
snippet II "greek" i
I
endsnippet
snippet jj "greek" i
endsnippet
snippet JJ "greek" i
endsnippet
snippet kk "greek" i
\kappa
endsnippet
snippet KK "greek" i
K
endsnippet
snippet ll "greek" i
\lambda
endsnippet
snippet LL "greek" i
\Lambda
endsnippet
snippet mm "greek" i
\mu
endsnippet
snippet MM "greek" i
M
endsnippet
snippet nn "greek" i
\nu
endsnippet
snippet NN "greek" i
N
endsnippet
snippet oo "greek" i
\omega
endsnippet
snippet oom "greek" i
\omicron
endsnippet
snippet OO "greek" i
\Omega
endsnippet
snippet OOv "vargreek" i
\varOmega
endsnippet
snippet pp "greek" i
\pi
endsnippet
snippet ppv "var greek" i
\varpi
endsnippet
snippet PP "greek" i
\Pi
endsnippet
snippet PPv "var greek" i
\varPi
endsnippet
snippet qq "greek" i
endsnippet
snippet QQ "greek" i
endsnippet
snippet rr "greek" i
\rho
endsnippet
snippet rrv "var greek" i
\varrho
endsnippet
snippet RR "greek" i
P
endsnippet
snippet RRv "var greek" i
\varRho
endsnippet
snippet ss "greek" i
\sigma
endsnippet
snippet ssv "var greek" i
\varsigma
endsnippet
snippet SS "greek" i
\Sigma
endsnippet
snippet SSv "var greek" i
\varSigma
endsnippet
snippet tt "greek" i
\theta
endsnippet
snippet ttv "var greek" i
\vartheta
endsnippet
snippet TT "greek" i
\Theta
endsnippet
snippet TTv "var greek" i
\varTheta
endsnippet
snippet uu "greek" i
\tau
endsnippet
snippet UU "greek" i
T
endsnippet
snippet vv "greek" i
\psi
endsnippet
snippet VV "greek" i
\Psi
endsnippet
snippet VVv "var greek" i
\varPsi
endsnippet
snippet ww "greek" i
endsnippet
snippet WW "greek" i
endsnippet
snippet xx "greek" i
\xi
endsnippet
snippet XX "greek" i
\xi
endsnippet
snippet yy "greek" i
\upsilon
endsnippet
snippet YY "greek" i
\Upsilon
endsnippet
snippet YYv "var greek" i
\varUpsilon
endsnippet
snippet zz "greek" i
\zeta
endsnippet
snippet ZZ "greek" i
Z
endsnippet
snippet aa# "greek" iA
\alpha
endsnippet
snippet AA# "greek" iA
\Alpha
endsnippet
snippet bb# "greek" iA
\beta
endsnippet
snippet BB# "greek" iA
B
endsnippet
snippet cc# "greek" iA
\chi
endsnippet
snippet CC# "greek" iA
X
endsnippet
snippet dd# "greek" iA
\delta
endsnippet
snippet DD# "greek" iA
\Delta
endsnippet
snippet DDv "var greek" iA
\varDelta
endsnippet
snippet ee# "greek" iA
\epsilon
endsnippet
snippet eev# "vargreek" iA
\varepsilon
endsnippet
snippet EE# "greek" iA
endsnippet
snippet ff# "greek" iA
\phi
endsnippet
snippet ffv# "var greek" iA
\varphi
endsnippet
snippet FF# "greek" iA
\Phi
endsnippet
snippet FFv# "var greek" iA
\varPhi
endsnippet
snippet gg# "greek" iA
\gamma
endsnippet
snippet GG# "greek" iA
\Gamma
endsnippet
snippet GGv# "var greek" iA
\varGamma
endsnippet
snippet hh# "greek" iA
\eta
endsnippet
snippet HH# "greek" iA
H
endsnippet
snippet ii# "greek" iA
\iota
endsnippet
snippet II# "greek" iA
I
endsnippet
snippet jj# "greek" iA
endsnippet
snippet JJ# "greek" iA
endsnippet
snippet kk# "greek" iA
\kappa
endsnippet
snippet KK# "greek" iA
K
endsnippet
snippet ll# "greek" iA
\lambda
endsnippet
snippet LL# "greek" iA
\Lambda
endsnippet
snippet mm# "greek" iA
\mu
endsnippet
snippet MM# "greek" iA
M
endsnippet
snippet nn# "greek" iA
\nu
endsnippet
snippet NN# "greek" iA
N
endsnippet
snippet oo# "greek" iA
\omega
endsnippet
snippet oom# "greek" iA
\omicron
endsnippet
snippet OO# "greek" iA
\Omega
endsnippet
snippet OOv# "vargreek" iA
\varOmega
endsnippet
snippet pp# "greek" iA
\pi
endsnippet
snippet ppv# "var greek" iA
\varpi
endsnippet
snippet PP# "greek" iA
\Pi
endsnippet
snippet PPv# "var greek" iA
\varPi
endsnippet
snippet qq# "greek" iA
endsnippet
snippet QQ# "greek" iA
endsnippet
snippet rr# "greek" iA
\rho
endsnippet
snippet rrv# "var greek" iA
\varrho
endsnippet
snippet RR# "greek" iA
P
endsnippet
snippet RRv# "var greek" iA
\varRho
endsnippet
snippet ss# "greek" iA
\sigma
endsnippet
snippet ssv# "var greek" iA
\varsigma
endsnippet
snippet SS# "greek" iA
\Sigma
endsnippet
snippet SSv# "var greek" iA
\varSigma
endsnippet
snippet tt# "greek" iA
\theta
endsnippet
snippet ttv# "var greek" iA
\vartheta
endsnippet
snippet TT# "greek" iA
\Theta
endsnippet
snippet TTv# "var greek" iA
\varTheta
endsnippet
snippet uu# "greek" iA
\tau
endsnippet
snippet UU# "greek" iA
T
endsnippet
snippet vv# "greek" iA
\psi
endsnippet
snippet VV# "greek" iA
\Psi
endsnippet
snippet VVv# "var greek" iA
\varPsi
endsnippet
snippet ww# "greek" iA
endsnippet
snippet WW# "greek" iA
endsnippet
snippet xx# "greek" iA
\xi
endsnippet
snippet XX# "greek" iA
\xi
endsnippet
snippet yy# "greek" iA
\upsilon
endsnippet
snippet YY# "greek" iA
\Upsilon
endsnippet
snippet YYv# "var greek" iA
\varUpsilon
endsnippet
snippet zz# "greek" iA
\zeta
endsnippet
snippet ZZ# "greek" iA
Z
endsnippet
snippet `([a-zA-Z])#` "bb" iA
``rv = '\\mathbb{' + m[1] + '}'``
endsnippet
snippet verb "verb" i
\verb|$0|
endsnippet
snippet @@ "infinity" iA
``rv = '\\infty'``
endsnippet
snippet @6 "partial" iA
\partial
endsnippet
snippet bn "partial (boundary)" i
\partial
endsnippet
snippet @8 "infinity" iA
\infty
endsnippet
snippet inf "infinity" i
\infty
endsnippet
context math(context)
snippet `(d|D)(\\?\w?)[dD](\w{1}|\\\w+)` "derivatives" i
``
if (m[1] == 'd')
rv = '\\frac{\\partial ' + m[2] + '}{\\partial ' + m[3] + '}';
else
rv = '\\frac{d' + m[2] + '}{\d' + m[3] + '}';
``
endsnippet
context math(context)
snippet `(d|D)[dD](\w{1}|\\\w+)` "derivatives" i
``
if (m[1] == 'd')
rv = '\\frac{\\partial}{\\partial ' + m[2] + '}';
else
rv = '\\frac{d}{d' + m[2] + '}';
``
endsnippet
context math(context)
snippet `([a-zA-Z0-9])pw` "exponentiation" iA
``rv = m[1] + `^{${snip.tabstop(1,'')}}` ``
endsnippet
context math(context)
snippet lim "lim" i
\lim_{$1\to$2}$0
endsnippet
snippet __ "subscript" iA
_{$1}$0
endsnippet
snippet ^^ "power" iA
^{$1}$0
endsnippet
snippet ** "bigproduct" iA
\prod_{$1=$2}^{$3}$0
endsnippet
snippet ` ?(\+\+)` "bigsum" iA
\sum_{$1=$2}^{$3}$0
endsnippet
snippet >-> "monomorphism" iA
\rightarrowtail
endsnippet
snippet ->> "epimorphism" iA
\twoheadrightarrow
endsnippet
snippet \rightarrow> "epimorphism" iA
\twoheadrightarrow
endsnippet
snippet <-> "leftrightarrow" iA
\leftrightarrow
endsnippet
snippet \leftarrow> "leftrightarrow" iA
\leftrightarrow
endsnippet
snippet *-> "inclusion mapping" iA
\hookrightarrow
endsnippet
snippet <- "leftarrow" iA
\leftarrow
endsnippet
snippet -> "rightarrow" iA
\rightarrow
endsnippet
snippet <= "Leftarrow" iA
\Leftarrow
endsnippet
snippet =< "Leftarrow" iA
\Leftarrow
endsnippet
snippet => "Rightarrow" iA
\Rightarrow
endsnippet
snippet >= "Rightarrow" iA
\Rightarrow
endsnippet
snippet |-> "mapsto" iA
\mapsto
endsnippet
snippet mapsto "mapsto" i
\mapsto
endsnippet
snippet date "big-endian date"
$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE
endsnippet
context math(context)
snippet sqrt "sqrt" A
\sqrt{$0}
endsnippet
context math(context)
snippet cbrt "cbrt" iA
\sqrt[3]{$0}
endsnippet
context math(context)
snippet nrt "nth root" iA
\sqrt[$1]{$0}
endsnippet
snippet leq "leq" i
\leq
endsnippet
snippet geq "geq" i
\geq
endsnippet
snippet neq "neq" i
\neq
endsnippet
snippet != "neq" iA
\neq
endsnippet
context math(context)
snippet abs "abs" i
|$0|
endsnippet
snippet bmatrix "bmatrix"
\begin{bmatrix}
$0
\end{bmatrix}
endsnippet
snippet align "align"
\begin{align*}
$0
\end{align*}
endsnippet
snippet `([a-zA-Z])rfunc` "real scalar function" iA
``rv = `\$`+m[1]+`:\\mathbb{R}\\rightarrow\\mathbb{R}\$` ``
endsnippet
snippet `([a-zA-Z])cfunc` "complex scalar function" iA
``rv = `\$`+m[1]+`:\\mathbb{C}\\rightarrow\\mathbb{C}\$` ``
endsnippet
snippet `([a-zA-Z])ifunc` "interval to real function" iA
``rv = `\$`+m[1]+`:[a,b]\\rightarrow\\mathbb{R}\$` ``
endsnippet
snippet `([a-zA-Z])vsfunc` "vector to scalar function" iA
``rv = `\$`+m[1]+`:\\mathbb{R}^n\\rightarrow\\mathbb{R}\$` ``
endsnippet
snippet `([a-zA-Z])vvfunc` "vector to vector function" iA
``rv = `\$\\mathbf{`+m[1]+`}:\\mathbb{R}^${snip.tabstop(1,'n')}\\rightarrow\\mathbb{R}^${snip.tabstop(2,'n')}\$${snip.tabstop(3,'')}` ``
endsnippet
snippet `([a-zA-Z])gfunc` "generic function" iA
``rv = `\$`+m[1]+`:${snip.tabstop(1,'A')}\\rightarrow${snip.tabstop(2,'B')}\$ ${snip.tabstop(3,'')}` ``
endsnippet
snippet `([a-zA-Z])path` "path" iA
``rv = `\$`+m[1]+`:I\\rightarrow ${snip.tabstop(2,'X')}\$ ${snip.tabstop(3,'')}` ``
endsnippet
snippet `relhom` "homotopy rel boundary" iA
\stackrel{\partial}{\simeq}
endsnippet
snippet `ghom` "group homomorphism" iA
$${1:\phi}:${2:G}\rightarrow ${3:H}$$0
endsnippet
snippet `rhom` "ring homomorphism" iA
$${1:\phi}:${2:R}\rightarrow ${3:S}$$0
endsnippet
context math(context)
snippet tec "colour" i
\textcolor{$1}{$0}
endsnippet
snippet tsc "small caps" iA
\textsc{$1}$0
endsnippet
snippet mbf "mathbf" iA
\mathbf{$1}$0
endsnippet
snippet mbb "mathbb" iA
\mathbb{$1}$0
endsnippet
snippet left "brackets" i
\left$2$1\right$2 $0
endsnippet
snippet tnp "transpose" iA
^\top
endsnippet
snippet invs "inverse" iA
^{-1}
endsnippet
snippet int "integral" i
\int_{$1}^{$2}$0
endsnippet
snippet met# "metric space" iA
(${1:X},d_${1:X})$0
endsnippet
snippet seq "sequence" i
($1_${2:i})_{${2:i}=1}^{${3:\infty}}$0
endsnippet
snippet ord "ordered set" i
(${1:X},${2:<}_${1:X})$0
endsnippet
snippet top "topological space" i
(${1:T}_${2:1},\\pazocal{${1:T}}_${2:1})$0
endsnippet
snippet pring "polynomial ring" i
${1:k}[${2:x}_1,\ldots,${2:x}_n]$0
endsnippet
snippet sseq "subseteq" i
\subseteq
endsnippet
snippet ss "subseteq" i
\subseteq
endsnippet
snippet `([a-zA-Z])col` "finite collection" i
``rv = m[1]+`_1,\\ldots,`+ m[1]+`_`+snip.tabstop(1,'n') ``
endsnippet
snippet lsb "large set brackets" i
\left\\{$1\right\\}$0
endsnippet
snippet sb "set brackets" i
\\{$1\\}$0
endsnippet
snippet llan "large angle brackets" i
\left\langle$0\right\rangle
endsnippet
snippet lan "angle brackets" i
\langle$0\rangle
endsnippet
snippet \langle# "angle brackets" iA
\langle$0\rangle
endsnippet
snippet `llb|llp` "large brackets" iA
\left($0\right)
endsnippet
snippet `[b|h]{4}p` "Biggl brackets" iA
\Biggl($0\Biggr)
endsnippet
snippet `[b|h]{3}p` "biggl brackets" iA
\biggl($0\biggr)
endsnippet
snippet `[b|h]{2}p` "Bigl brackets" iA
\Bigl($0\Bigr)
endsnippet
snippet bp "bigl brackets" i
\bigl($0\bigr)
endsnippet
snippet hp "bigl brackets" i
\bigl($0\bigr)
endsnippet
snippet `[b|h]{4}s` "Biggl set brackets" iA
\Biggl\\{$0\Biggr\\}
endsnippet
snippet `[b|h]{3}s` "biggl set brackets" iA
\biggl\\{$0\biggr\\}
endsnippet
snippet `[b|h]{2}s` "Bigl set brackets" iA
\Bigl\\{$0\Bigr\\}
endsnippet
snippet `bs|hs` "bigl set brackets" i
\bigl\\{$0\bigr\\}
endsnippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment