dots/.vim/snips/pandoc.snippets

926 lines
14 KiB
Plaintext
Raw Permalink Normal View History

2022-05-11 12:08:01 +02:00
# A valid snippet should starts with:
#
# snippet trigger_word [ "description" [ options ] ]
#
# and end with:
#
# endsnippet
#
# Snippet options:
#
# b - Beginning of line.
# i - In-word expansion.
# w - Word boundary.
# r - Regular expression
# e - Custom context snippet
# A - Snippet will be triggered automatically, when condition matches.
#
# Basic example:
#
# snippet emitter "emitter properties" b
# private readonly ${1} = new Emitter<$2>()
# public readonly ${1/^_(.*)/$1/}: Event<$2> = this.$1.event
# endsnippet
#
# Online reference: https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt
2023-05-15 13:41:06 +02:00
global !p
2023-08-30 01:15:29 +02:00
from datetime import datetime
from math import factorial
import subprocess
import re
import sys
ZOTERO_BASE = "http://127.0.0.1:23119/better-bibtex/cayw"
FENCES = {
"i": "idea",
"q": "question",
"n": "note",
"t": "thought",
}
2023-05-15 13:41:06 +02:00
def math_inline():
return vim.command_output('GetContext') == 'math_inline'
def math_block():
return vim.command_output('GetContext') == 'math_block'
2023-08-30 01:15:29 +02:00
def math():
return math_inline() or math_block()
def code_block():
return vim.command_output('GetContext') == 'pandocDelimitedCodeBlock'
def code_inline():
return vim.command_output('GetContext') == 'pandocNoFormatted'
def code():
return code_inline() or code_block()
2024-01-09 12:45:49 +01:00
def slugify(text):
return re.sub('\s+', '-', text.lower())
2023-08-30 01:15:29 +02:00
def linkify(text, link):
return f"[{text}]({link})"
def zot(action):
if action == "get_title":
cmd = f"curl -s '{ZOTERO_BASE}?format=json&selected=1' | jq '.[].title' -r"
elif action == "get_citekey":
cmd = f"curl -s '{ZOTERO_BASE}?format=pandoc&selected=1'"
elif action == "get_citekey_brackets":
cmd = f"curl -s '{ZOTERO_BASE}?format=pandoc&selected=1&brackets=1'"
elif action == "get_link":
link_path = re.sub("^@", "", zot("get_citekey"))
link_title = zot("get_title")
link = linkify(link_title, link_path)
return link
elif action == "get_file":
link_path = re.sub("^@", "", zot("get_citekey"))
link_title = zot("get_title")
link = linkify(link_title, f"file://{link_path}.pdf")
return link
else:
return "Zotero action not found"
return subprocess.check_output(cmd, shell=True).decode("utf-8").strip()
2023-05-15 13:41:06 +02:00
endglobal
2023-08-30 01:15:29 +02:00
snippet ctx "Context" i
`!p snip.rv = vim.command_output('GetContext')`
endsnippet
# General markdown
snippet ^h "Markdown header" r
# $1
endsnippet
snippet ^sec "Markdown section" r
## $1
endsnippet
snippet ^ssec "Markdown subsection" r
### $1
endsnippet
snippet ^sex "Markdown example section" r
## Example: $1
endsnippet
snippet ^ssex "Markdown example subsection" r
### Example: $1
endsnippet
2022-09-24 11:26:42 +02:00
2022-05-11 12:08:01 +02:00
# Zettelkasten templating
snippet nl
2023-08-17 12:36:18 +02:00
*nld*: $1
2022-05-11 12:08:01 +02:00
endsnippet
snippet eng
2023-08-17 12:36:18 +02:00
*eng*: $1
2022-05-11 12:08:01 +02:00
endsnippet
snippet fr
2023-08-17 12:36:18 +02:00
*fra*: $1
2022-09-24 11:26:42 +02:00
endsnippet
snippet (de
2023-08-17 12:36:18 +02:00
*deu*: $1
2022-09-24 11:26:42 +02:00
endsnippet
snippet (nl
2023-08-17 12:36:18 +02:00
(*nld*: $1)
2022-09-24 11:26:42 +02:00
endsnippet
snippet (eng
2023-08-17 12:36:18 +02:00
(*eng*: $1)
2022-09-24 11:26:42 +02:00
endsnippet
snippet (fr
2023-08-17 12:36:18 +02:00
(*fra*: $1)
2022-05-11 12:08:01 +02:00
endsnippet
2022-09-24 11:26:42 +02:00
snippet (de
2023-08-17 12:36:18 +02:00
(*deu*: $1)
2022-05-11 12:08:01 +02:00
endsnippet
snippet in
(In [$1]($2))$3
endsnippet
2023-08-30 01:15:29 +02:00
snippet liwhat "What?" A
`!p snip.rv = "* [What?](" + snip.basename + "_what)"`$1
endsnippet
snippet liwhy "Why?" A
`!p snip.rv = "* [Why?](" + snip.basename + "_why)"`$1
endsnippet
snippet < "Comment (html)"
2023-05-15 13:38:13 +02:00
<!-- $1 -->$2
endsnippet
2023-08-30 01:15:29 +02:00
snippet <. "Comment (html) ..." i
2023-05-15 13:38:13 +02:00
<!-- ... -->$1
endsnippet
2023-08-30 01:15:29 +02:00
snippet <t "Thought (html)" i
<!--:::thought
$1
:::-->
endsnippet
snippet <q "Question (html)" i
<!--:::question
$1
:::-->
endsnippet
snippet <i "Idea (html)" i
<!--:::idea
$1
:::-->
endsnippet
snippet <n "Note (html)" i
<!--:::note
$1
:::-->
endsnippet
snippet td "Todo"
TODO${1:: $2}
endsnippet
2022-05-11 12:08:01 +02:00
snippet ref "References"
<!--references-->
endsnippet
2022-09-24 11:26:42 +02:00
snippet sort "Sort"
<!--sort-->
endsnippet
2022-05-11 12:08:01 +02:00
snippet foot "Footnotes"
<!--footnotes-->
[^0]:
endsnippet
snippet def "Definition"
2022-09-24 11:26:42 +02:00
**Definition${1:: $2}**${3: [${4:citation}${5:, ${6:pointer}}]}
2022-05-11 12:08:01 +02:00
2022-09-24 11:26:42 +02:00
$7
2022-05-11 12:08:01 +02:00
___
endsnippet
snippet theo "Theorem"
2022-09-24 11:26:42 +02:00
**Theorem${1:: $2}**${3: [${4:citation}${5:, ${6:pointer}}]}
2022-05-11 12:08:01 +02:00
2022-09-24 11:26:42 +02:00
$7
${8/(\w+).*/**Theorem** \n\n.../}
2022-05-11 12:08:01 +02:00
___
endsnippet
snippet prop "Property"
**Property $1** [@]
$2
___
endsnippet
snippet lemm "Lemma"
**Lemma $1** [@]
$2
___
endsnippet
snippet coro "Corollary"
**Corollary $1** [@]
$2
___
endsnippet
2023-05-19 19:37:57 +02:00
# Greek symbols
context "math()"
snippet alpha "Alpha"
\\alpha
endsnippet
context "math()"
snippet beta "Beta"
\\beta
endsnippet
context "math()"
snippet gamma "Gamma"
\\gamma
endsnippet
context "math()"
snippet delta "Delta"
\\delta
endsnippet
context "math()"
snippet epsilon "Epsilon"
\\epsilonilon
endsnippet
context "math()"
snippet zeta "Zeta"
\\zeta
endsnippet
context "math()"
snippet eta "Eta"
\\eta
endsnippet
context "math()"
snippet theta "Theta"
\\theta
endsnippet
context "math()"
snippet iota "Iota"
\\iota
endsnippet
context "math()"
snippet kappa "Kappa"
\\kappa
endsnippet
context "math()"
snippet lambda "Lambda" i
\\lambda
endsnippet
context "math()"
snippet mu "Mu"
\\mu
endsnippet
context "math()"
snippet nu "Nu"
\\nu
endsnippet
context "math()"
snippet xi "Xi"
\\xi
endsnippet
context "math()"
snippet omicron "Omicron"
\\omicron
endsnippet
context "math()"
snippet pi "Pi"
\\pi
endsnippet
context "math()"
snippet rho "Rho"
\\rho
endsnippet
context "math()"
snippet sigma "Sigma"
\\sigma
endsnippet
context "math()"
snippet tau "Tau"
\\tau
endsnippet
context "math()"
snippet upsilon "Upsilon"
\\upsilon
endsnippet
context "math()"
snippet phi "Phi"
\\phi
endsnippet
context "math()"
snippet chi "Chi"
\\chi
endsnippet
context "math()"
snippet psi "Psi"
\\psi
endsnippet
context "math()"
snippet omega "Omega"
\\omega
endsnippet
context "math()"
snippet Gamma "Gamma"
\\Gamma
endsnippet
context "math()"
snippet Delta "Delta"
\\Delta
endsnippet
context "math()"
snippet Theta "Theta"
\\Theta
endsnippet
context "math()"
snippet Lambda "Lambda"
\\Lambda
endsnippet
context "math()"
snippet Xi "Xi"
\\Xi
endsnippet
context "math()"
snippet Pi "Pi"
\\Pi
endsnippet
context "math()"
snippet Sigma "Sigma"
\\Sigma
endsnippet
context "math()"
snippet Upsilon "Upsilon"
\\Upsilon
endsnippet
context "math()"
snippet Phi "Phi"
\\Phi
endsnippet
context "math()"
snippet Psi "Psi"
\\Psi
endsnippet
context "math()"
snippet Omega "Omega"
\\Omega
endsnippet
2022-09-24 11:26:42 +02:00
snippet asaw "Als en slechts als (woorden)" i
als en slechts als
2022-05-11 12:08:01 +02:00
endsnippet
2022-09-24 11:26:42 +02:00
snippet iffw "If and only if (words)" i
if and only if
2022-05-11 12:08:01 +02:00
endsnippet
2022-09-24 11:26:42 +02:00
snippet asas "Als en slechts als (shorthand)" i
**asa**
2022-05-11 12:08:01 +02:00
endsnippet
2022-09-24 11:26:42 +02:00
snippet iffs "If and only if (shorthand)" i
**iff**
2022-05-11 12:08:01 +02:00
endsnippet
2023-08-30 01:15:29 +02:00
snippet beg "Begin"
\begin{$1}
$2
\end{$1}
endsnippet
2022-05-11 12:08:01 +02:00
snippet align "" i
\begin{align}
$1
\end{align}
endsnippet
snippet cases "" i
\begin{cases}
$1 \\\\
$2
\end{cases}
$3
endsnippet
2023-05-19 19:30:44 +02:00
snippet tik "Tikzpicture" i
\begin{tikzpicture}
$1
\end{tikzpicture}
endsnippet
2022-05-11 12:08:01 +02:00
snippet matrix "Matrix" i
\begin{bmatrix}
$1
\end{bmatrix}
endsnippet
2023-05-19 19:35:07 +02:00
# Insert anything after m/M in math mode
snippet "(\b)m(.*)" "MathJax" r
`!p snip.rv = match.group(1) + "$" + match.group(2) + "$"`
2022-05-11 12:08:01 +02:00
endsnippet
2023-05-19 19:35:07 +02:00
snippet (\b)M(.*) "MathJax block" irw
2022-05-11 12:08:01 +02:00
$$
2023-05-19 19:35:07 +02:00
`!p snip.rv = match.group(2)`
2022-05-11 12:08:01 +02:00
$$
endsnippet
2023-05-19 19:37:57 +02:00
# Calligraphic letters
context "math()"
snippet c([A-z]) "Calligraphic A" r
`!p snip.rv = "\\mathcal{" + match.group(1) + "}"`$1
endsnippet
# Subscripts
context "math()"
2023-08-30 01:15:29 +02:00
snippet '([A-z])(\w+)' "Subscripts" irw
2023-05-19 19:37:57 +02:00
`!p snip.rv = match.group(1) + '_' + match.group(2) if len(match.group(2)) == 1 else match.group(1) + '_{' + match.group(2) + '}'`$1
endsnippet
2022-05-11 12:08:01 +02:00
# MathJax
snippet fa "For all" i
\forall
endsnippet
snippet frac "" i
\frac{$1}{$2}$3
endsnippet
snippet set "" i
\\{$1\\}$2
endsnippet
snippet N "" i
\mathbb{N}
endsnippet
snippet N0 "" i
\mathbb{N}_0
endsnippet
snippet N+ "" i
\mathbb{N}^+
endsnippet
snippet Z "" i
\mathbb{Z}
endsnippet
snippet Z0 "" i
\mathbb{Z}_0
endsnippet
snippet Z+ "" i
\mathbb{Z}^+
endsnippet
snippet R "" i
\mathbb{R}
endsnippet
snippet R0 "" i
\mathbb{R}_0
endsnippet
snippet R+ "" i
\mathbb{R}^+
endsnippet
snippet C "" i
\mathbb{C}
endsnippet
snippet lim "" i
\lim_{$1}$2
endsnippet
snippet limn "" i
\lim_{n \to \infty}$2
endsnippet
snippet binom "" i
\binom{$1}{$2}$3
endsnippet
snippet andmath "description" i
\text{ and }
endsnippet
snippet enmath "description" i
\text{ en }
endsnippet
snippet lra "MathJax: long right arrow" i
\longrightarrow
endsnippet
snippet Ra "MathJax: right arrow" i
\Rightarrow
endsnippet
snippet Im "MathJax: image operator" i
\operatorname{Im}
endsnippet
snippet ggd "Grootste gemene deler" i
\operatorname{ggd}
endsnippet
snippet fl "Floating point" i
\operatorname{fl}
endsnippet
snippet Var "Variance" i
\operatorname{Var}
endsnippet
snippet E "Expectation" i
\operatorname{E}
endsnippet
2022-09-24 11:26:42 +02:00
snippet Cov "Covariance" i
\operatorname{Cov}
endsnippet
2023-08-30 01:15:29 +02:00
context "math()" i
snippet ntup "Alpha"
(x_1, \ldots, x_n)
endsnippet
2022-05-11 12:08:01 +02:00
snippet mxn "Matrix" i
m \times n
endsnippet
2022-09-24 11:26:42 +02:00
snippet mxn- "Matrix" i
$m \times n$-matrix
endsnippet
snippet nxn "Matrix" i
n \times n
endsnippet
snippet det "Determinant" i
\operatorname{det}(${1:A})$2
endsnippet
snippet det| "Determinant alternative notation" i
|${1:A}|$2
endsnippet
2022-05-11 12:08:01 +02:00
snippet Span "Span" i
\operatorname{Span}\\{$1\\}$2
endsnippet
snippet Nul "Null" i
\operatorname{Nul}($1)$2
endsnippet
snippet Col "Column space" i
\operatorname{Col}($1)$2
endsnippet
snippet kern "Kernel" i
\operatorname{kern}($1)$2
endsnippet
2023-05-19 19:37:57 +02:00
context "math()"
2022-05-11 12:08:01 +02:00
snippet vec "Vector" i
\mathbf{$1}$2
endsnippet
2023-05-19 19:37:57 +02:00
context "math()"
snippet vec([A-z]) "Vector ..." r
`!p snip.rv = "\\mathbf{" + match.group(1) + "}"`$1
endsnippet
snippet v1tovp "Vectors v indexed from 1 to p"
2022-05-11 12:08:01 +02:00
\mathbf{v_1},...,\mathbf{v_p}$2
endsnippet
2023-05-19 19:37:57 +02:00
snippet a1toan "Vectors a indexed from 1 to n"
2022-05-11 12:08:01 +02:00
\mathbf{a_1},...,\mathbf{v_n}$2
endsnippet
snippet .. "Dot dot dot" i
\dots $1
endsnippet
snippet text "MathJax text" i
\text{$1}$2
endsnippet
snippet leq "Less than or equal to" i
\leq
endsnippet
snippet leq "Greater than or equal to" i
\geq
endsnippet
snippet eat "Evaluated at" i
{\biggr\rvert}_{$1}$2
endsnippet
2022-09-24 11:26:42 +02:00
snippet sketch "Link a sketch" i
[$1](file:///home/h/sketches/$2)
endsnippet
2023-05-19 19:38:51 +02:00
2023-08-30 01:15:29 +02:00
snippet deck "Get anki deck"
`get-anki-decks`
2023-05-19 19:38:51 +02:00
endsnippet
2023-08-30 01:15:29 +02:00
# snippet ` "Inline code" i
# `$1`
# endsnippet
# Escape backticks
snippet `` "Code block" bA
\`\`\`$1
2023-05-19 19:38:51 +02:00
$2
2023-08-30 01:15:29 +02:00
\`\`\`
endsnippet
snippet `tex "Latex block (see latex filter)" bA
\`\`\`{.tex}
$1
\`\`\`
2023-05-19 19:38:51 +02:00
endsnippet
2023-08-30 01:15:29 +02:00
snippet `tik "Tikz block (see tikz filter)" bA
\`\`\`{.tex}
\\begin{tikzpicture}
2023-05-19 19:38:51 +02:00
$1
2023-08-30 01:15:29 +02:00
\\end{tikzpicture}
\`\`\`
endsnippet
snippet task "Task" i
* [ ] $1 -- pro:$2
endsnippet
snippet "(\b)fn(\d+)" "" ir
`!p snip.rv = snip.basename + "_" + match.group(2).zfill(2)`$1
endsnippet
snippet "ch(\d+)" "Link chapter" ir
`!p
num_str = match.group(1).zfill(2)
title = 3*"."
link = snip.basename + "_" + num_str
snip.rv = num_str + ". " + linkify(title, link)
`
endsnippet
snippet "ch(\d+)to(\d+)" "Link chapters ... to ..." irA
`!p
for i in range(int(match.group(1)), int(match.group(2)) + 1):
num_str = str(i).zfill(2)
title = 3*"."
link = snip.basename + "_" + num_str
snip.rv += num_str + ". " + linkify(title, link) + "\n"
`
endsnippet
2024-01-09 12:45:49 +01:00
snippet "sec([\sA-z]+)" "Link section titled ..." r
`!p
snip.rv = "* " + linkify(match.group(1), f"{snip.basename}_{slugify(match.group(1))}")
`
endsnippet
2023-08-30 01:15:29 +02:00
snippet cp(\d+) "Comment current page (and date)" r
`!p snip.rv = "<!--" + datetime.now().strftime("%Y-%m-%d") + " p. " + match.group(1) + "-->"`
endsnippet
snippet (\d+)! "Factorial of ..." r
`!p snip.rv = factorial(int(match.group(1)))`
endsnippet
snippet d "Date"
`!p snip.rv = datetime.now().strftime("%Y-%m-%d")`
endsnippet
snippet :(\w*) "Fence" r
`!p snip.rv += ":::" + FENCES.get(match.group(1) or "", "") + "\n" `$1
`!p snip.rv += ":::"`$2
endsnippet
snippet \[(\w*) "Fence inline" ir
`!p snip.rv += "["`$1`!p snip.rv += "]{." + FENCES.get(match.group(1) or "", "") + "}"`$2
endsnippet
snippet ^eg "Example" r
E.g. $1
endsnippet
# E.g. after list (or list preceded by space)
snippet (\*\s|\*)eg "Example" r
* E.g. $1
endsnippet
# E.g. after dot (or dot preceded by space)
snippet (\.\s|\.)eg "Example" r
. E.g. $1
endsnippet
snippet (?<!^|\*\s|\*|\.\s|\.)eg "Example" r
e.g. $1
endsnippet
# Zettelkasten to Anki
snippet td "TARGET DECK: <Deck name>"
TARGET DECK: $1::$2
endsnippet
snippet clo "Cloze"
START
Cloze
${0:${VISUAL}}$1
END
$2
endsnippet
snippet clos "Cloze start"
START
Cloze
$1
endsnippet
snippet cloe "Cloze end"
END
endsnippet
snippet clod
START
Cloze
**Definition$1**
$2
END
endsnippet
snippet clop
START
Cloze
**Property$1**
$2
END
endsnippet
snippet clot
START
Cloze
**Theorem$1**
$2
END
endsnippet
snippet clol
START
Cloze
**Lemma$1**
$2
END
endsnippet
snippet "c(\d+)" "Cloze <number>" r
{{c`!p snip.rv = int(match.group(1))`::${0:${VISUAL}}$1}}$2
endsnippet
# Match preceded by whitespace or start of line
snippet (?<!\S)z($|t|l|z|o|\.) "Zotero" r
`!p
ACTIONS = {
"": "get_citekey",
"t": "get_title",
"l": "get_link",
"z": "get_citekey_brackets",
"o": "get_file",
}
snip.rv = zot(ACTIONS.get(match.group(1)))
`
endsnippet
snippet zq "Zotero quote" r
`!p snip.rv = '>\n> --' + zot("get_citekey_brackets")`
endsnippet
snippet acz "According to ..."
`!p snip.rv = "According to " + zot("get_citekey")`
endsnippet
snippet azex "As ... explains"
`!p snip.rv = "As " + zot("get_citekey") + " explains, "`
endsnippet
snippet iz "In ..."
`!p snip.rv = "In " + zot("get_citekey")`
endsnippet
snippet izd "In ...'s definition"
`!p snip.rv = "In " + zot("get_citekey") + "'s definition, "`
endsnippet
snippet zintends "... intends to ..." A
`!p snip.rv = zot("get_citekey") + " intends to "`
endsnippet
snippet tfol "The following" wA
the following
endsnippet
snippet tfolt "It follows that" wA
it follows that
endsnippet
snippet ntfol "In the following" wA
in the following
endsnippet
snippet algos "algorithms" wA
algorithms
endsnippet
snippet algo "algorithm" wA
algorithm
endsnippet
# TODO: Make only available in tikzpicture
context "code()"
snippet q "State" w
\node[state] ($1) [] {$2};
endsnippet
context "code()"
snippet q0 "Initial state" w
\node[initial,state] ($1) {$2};
2023-05-19 19:38:51 +02:00
endsnippet