快速编写latex的Ultisnips的snippets(个人版)

岳俊雅
2023-12-01

#使用说明:适用于vim,Neovim的Ultisnip插件,直接复制到对应格式的snip文件使用(e.g. tex.snippets 或者#markdown.snippets)

priority -50

global !p
def create_table(snip):
    # retrieving single line from current string and treat it like tabstops count
    placeholders_string = snip.buffer[snip.line].strip()[2:].split("x",1)
    rows_amount = int(placeholders_string[0])
    columns_amount = int(placeholders_string[1])

    # erase current line
    snip.buffer[snip.line] = ''

    # create anonymous snippet with expected content and number of tabstops
    anon_snippet_title = ' | '.join(['$' + str(col) for col in range(1,columns_amount+1)]) + "\n"
    anon_snippet_delimiter = ':-|' * (columns_amount-1) + ":-\n"
    anon_snippet_body = ""
    for row in range(1,rows_amount+1):
        anon_snippet_body += ' | '.join(['$' + str(row*columns_amount+col) for col in range(1,columns_amount+1)]) + "\n"
    anon_snippet_table = anon_snippet_title + anon_snippet_delimiter + anon_snippet_body

    # expand anonymous snippet
    snip.expand_anon(anon_snippet_table)
endglobal

###########################
# Sections and Paragraphs #
###########################
snippet sec "Section" b
# ${1:Section Name} #
$0
endsnippet

snippet ssec "Sub Section" b
## ${1:Section Name} ##
$0
endsnippet

snippet sssec "SubSub Section" b
### ${1:Section Name} ###
$0
endsnippet

snippet par "Paragraph" b
#### ${1:Paragraph Name} ####
$0
endsnippet

snippet spar "Paragraph" b
##### ${1:Paragraph Name} #####
$0
endsnippet

###################
# Text formatting #
###################

snippet * "italics"
*${1:${VISUAL}}*$0
endsnippet

snippet ** "bold"
**${1:${VISUAL}}**$0
endsnippet

snippet *** "bold italics"
***${1:${VISUAL}}***$0
endsnippet


################
# Common stuff #
################
snippet link "Link to something"
[${1:${VISUAL:Text}}](${3:http://${2:www.url.com}})$0
endsnippet

snippet img "Image"
![${1:pic alt}](${2:path}${3/.+/ "/}${3:opt title}${3/.+/"/})$0
endsnippet

snippet ilc "Inline Code" i
\`$1\`$0
endsnippet

snippet cbl "Codeblock" b
\`\`\`
$1
\`\`\`
$0
endsnippet

snippet refl "Reference Link"
[${1:${VISUAL:Text}}][${2:id}]$0

[$2]:${4:http://${3:www.url.com}} "${5:$4}"
endsnippet

snippet fnt "Footnote"
[^${1:${VISUAL:Footnote}}]$0

[^$1]:${2:Text}
endsnippet

pre_expand "create_table(snip)"
snippet "tb(\d+x\d+)" "Customizable table" br
endsnippet

# vim:ft=snippets:
##############
# MATH STUFF #
##############

snippet eqnn "Equation without a number" b
\begin{equation*}
    ${0:${VISUAL}}
\end{equation*}
endsnippet

snippet al "Align" b
\begin{align}
    ${0:${VISUAL}}
\end{align}
endsnippet

snippet alnn "Align without a number" b
\begin{align*}
    ${0:${VISUAL}}
\end{align*}
endsnippet

snippet eqa "Equation array" b
\begin{eqnarray}
    ${1:${VISUAL}} & ${2:${VISUAL}} & ${0:${VISUAL}}
\end{eqnarray}
endsnippet

snippet eqann "Equation array without a number" b
\begin{eqnarray*}
    ${1:${VISUAL}} & ${2:${VISUAL}} & ${0:${VISUAL}}
\end{eqnarray*}
endsnippet

#################
#PERPONAL STUFF #
#################

snippet today
`!v strftime("%Y-%m-%d")`
endsnippet

snippet box "Box"
`!p snip.rv = '┌' + '─' * (len(t[1]) + 2) + '┐'`
│ $1 │
`!p snip.rv = '└' + '─' * (len(t[1]) + 2) + '┘'`
$0
endsnippet
#分数
snippet '((\d+)|(\d*)(\\)?([A-Za-z]+)((\^|_)(\{\d+\}|\d))*)/' "Fraction" wrA
\\frac{`!p snip.rv = match.group(1)`}{$1}$0
endsnippet
#行内公式
snippet im "inlinemath" A
\$$1\$$0
endsnippet
#行内公式
snippet im "inlinemath" i
\$$1\$$0
endsnippet
#行间公式
snippet om "outlineMath" wA
\$\$
$1
\$\$ $2
endsnippet
#上标(单标数字)
snippet '([A-Za-z])(\d)' "auto subscript" wrA
`!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
endsnippet
#上标(双标数字)
snippet '([A-Za-z])_(\d\d)' "auto subscript2" wrA
`!p snip.rv = match.group(1)`_{`!p snip.rv = match.group(2)`}
endsnippet
#简单上标
snippet 2w "^2" iA
^2
endsnippet

snippet 3p "^3" iA
^3
endsnippet
#取补上标
snippet compl "complement" i
^{c}
endsnippet
#任意上标
snippet p "superscript" i
^{$1}$0
endsnippet

#外测度
snippet outm "outmeasure" i
m_{*}($1)
endsnippet
#闭区间
snippet cl "interval" i
[${1:1},${2:2}]$0
endsnippet
#开区间
snippet op "interval" i
(${1:1},${2:2})$0
endsnippet
#数学符号=============================================

snippet \e "epsilon" i
\\epsilon
endsnippet

snippet \d "delta" i
\\delta
endsnippet

snippet \a "alpha" i
\\alpha
endsnippet

snippet \b "beta" i
\\beta
endsnippet

snippet \t "theta" i
\\theta
endsnippet

#数学符号=============================================


snippet cantor "Cantorset" i
C_{\frac{1}{3}}
endsnippet
#求和符号
snippet sum "Sum" i
\sum_{${1:i=1}}^{${2:\infty}}
endsnippet
#分段函数
snippet case "cases" b
${1:x} = \begin{cases}
    ${2:a} & ${3:b} \\\\
    ${4:c} & ${5:d}
\end{cases}

endsnippet

priority 1000
snippet '^.*\)/' "() Fraction" 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 bcap "subcap" i
\\bigcap_{${1:i=1}}^{${2:\infty}}$0
endsnippet
#并集
snippet bcup "bigcup" i
\\bigcup_{${1:i=1}}^{${2:\infty}}$0
endsnippet
#下标
snippet d "下标" i
_{$1}$0
endsnippet
#居中下标
snippet cd "centerdownmark" i
\limits_{$1}$0
endsnippet
#二阶矩阵
snippet matrix "matrix" b
\\begin{pmatrix}
    ${1:a} & ${2:b} \\\\
    ${3:c} & ${4:d}
\\end{pmatrix}
endsnippet
#二阶行列式
snippet det "det of matrix" b
\\begin{vmatrix}
    ${1:a} & ${2:b} \\\\
    ${3:c} & ${4:d}
\\end{vmatrix}
endsnippet
#右箭头
snippet ra "rightarrow" i
\\rightarrow
endsnippet
#左箭头
snippet la "leftarrow" i
\\leftarrow
endsnippet

#字体格式====================================================
snippet mbb "mathbb" i
\\mathbb{$1}$0

endsnippet

snippet mc "mathcal" i
\\mathcal
endsnippet
#字体格式====================================================


 

 类似资料: