Gilles Castel写的vim中使用的代码片段,质量很高,原文:https://github.com/gillescastel

下载后,存放到 ~/.vim/plugged/ultisnips/UltiSnips

下面是记录一下,该代码片段:

global !p
texMathZones = ['texMathZone'+x for x in ['A', 'AS', 'B', 'BS', 'C', 'CS', 'D', 'DS', 'E', 'ES', 'F', 'FS', 'G', 'GS', 'H', 'HS', 'I', 'IS', 'J', 'JS', 'K', 'KS', 'L', 'LS', 'DS', 'V', 'W', 'X', 'Y', 'Z']] texIgnoreMathZones = ['texMathText'] texMathZoneIds = vim.eval('map('+str(texMathZones)+", 'hlID(v:val)')")
texIgnoreMathZoneIds = vim.eval('map('+str(texIgnoreMathZones)+", 'hlID(v:val)')") ignore = texIgnoreMathZoneIds[0] def math():
synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))")
try:
first = next(i for i in reversed(synstackids) if i in texIgnoreMathZoneIds or i in texMathZoneIds)
return first != ignore
except StopIteration:
return False
endglobal snippet template "Basic template" b
\documentclass[a4paper]{article} \usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[dutch]{babel}
\usepackage{amsmath, amssymb} % figure support
\usepackage{import}
\usepackage{xifthen}
\pdfminorversion=7
\usepackage{pdfpages}
\usepackage{transparent}
\newcommand{\incfig}[1]{%
\def\svgwidth{\columnwidth}
\import{./figures/}{#1.pdf_tex}
} \pdfsuppresswarningpagegroup=1 \begin{document}
$0
\end{document}
endsnippet snippet beg "begin{} / end{}" bA
\\begin{$1}
$0
\\end{$1}
endsnippet priority 100
snippet ... "ldots" iA
\ldots
endsnippet snippet table "Table environment" b
\begin{table}[${1:htpb}]
\centering
\caption{${2:caption}}
\label{tab:${3:label}}
\begin{tabular}{${5:c}}
$0${5/((?<=.)c|l|r)|./(?1: & )/g}
\end{tabular}
\end{table}
endsnippet snippet fig "Figure environment" b
\begin{figure}[${1:htpb}]
\centering
${2:\includegraphics[width=0.8\textwidth]{$3}}
\caption{${4:$3}}
\label{fig:${5:${3/\W+/-/g}}}
\end{figure}
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" b
\begin{description}
\item[$1] $0
\end{description}
endsnippet snippet pac "Package" b
\usepackage[${1:options}]{${2:package}}$0
endsnippet snippet => "implies" Ai
\implies
endsnippet snippet =< "implied by" Ai
\impliedby
endsnippet context "math()"
snippet iff "iff" Ai
\iff
endsnippet snippet mk "Math" wA
$${1}$`!p
if t[2] and t[2][0] not in [',', '.', '?', '-', ' ']:
snip.rv = ' '
else:
snip.rv = ''
`$2
endsnippet snippet dm "Math" wA
\[
${1:${VISUAL}}
.\] $0
endsnippet snippet ali "Align" bA
\begin{align*}
${1:${VISUAL}}
.\end{align*}
endsnippet context "math()"
snippet // "Fraction" iA
\\frac{$1}{$2}$0
endsnippet snippet / "Fraction" i
\\frac{${VISUAL}}{$1}$0
endsnippet context "math()"
snippet '((\d+)|(\d*)(\\)?([A-Za-z]+)((\^|_)(\{\d+\}|\d))*)/' "symbol frac" 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 context "math()"
snippet '([A-Za-z])(\d)' "auto subscript" wrA
`!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
endsnippet context "math()"
snippet '([A-Za-z])_(\d\d)' "auto subscript2" wrA
`!p snip.rv = match.group(1)`_{`!p snip.rv = match.group(2)`}
endsnippet snippet sympy "sympyblock " w
sympy $1 sympy$0
endsnippet priority 10000
snippet 'sympy(.*)sympy' "sympy" wr
`!p
from sympy import *
x, y, z, t = symbols('x y z t')
k, m, n = symbols('k m n', integer=True)
f, g, h = symbols('f g h', cls=Function)
init_printing()
snip.rv = eval('latex(' + match.group(1).replace('\\', '').replace('^', '**').replace('{', '(').replace('}', ')') + ')')
`
endsnippet priority 1000
snippet math "mathematicablock" w
math $1 math$0
endsnippet priority 10000
snippet 'math(.*)math' "math" wr
`!p
import subprocess
code = match.group(1)
code = 'ToString[' + code + ', TeXForm]'
snip.rv = subprocess.check_output(['wolframscript', '-code', code])
`
endsnippet snippet == "equals" iA
&= $1 \\\\
endsnippet snippet != "equals" iA
\neq
endsnippet context "math()"
snippet ceil "ceil" iA
\left\lceil $1 \right\rceil $0
endsnippet context "math()"
snippet floor "floor" iA
\left\lfloor $1 \right\rfloor$0
endsnippet snippet pmat "pmat" iA
\begin{pmatrix} $1 \end{pmatrix} $0
endsnippet snippet bmat "bmat" iA
\begin{bmatrix} $1 \end{bmatrix} $0
endsnippet context "math()"
snippet () "left( right)" iA
\left( ${1:${VISUAL}} \right) $0
endsnippet snippet lr "left( right)" i
\left( ${1:${VISUAL}} \right) $0
endsnippet snippet lr( "left( right)" i
\left( ${1:${VISUAL}} \right) $0
endsnippet snippet lr| "left| right|" i
\left| ${1:${VISUAL}} \right| $0
endsnippet snippet lr{ "left\{ right\}" i
\left\\{ ${1:${VISUAL}} \right\\} $0
endsnippet snippet lrb "left\{ right\}" i
\left\\{ ${1:${VISUAL}} \right\\} $0
endsnippet snippet lr[ "left[ right]" i
\left[ ${1:${VISUAL}} \right] $0
endsnippet snippet lra "leftangle rightangle" iA
\left<${1:${VISUAL}} \right>$0
endsnippet context "math()"
snippet conj "conjugate" iA
\overline{$1}$0
endsnippet snippet sum "sum" w
\sum_{n=${1:1}}^{${2:\infty}} ${3:a_n z^n}
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:n} \to ${2:\infty}}
endsnippet snippet limsup "limsup" w
\limsup_{${1:n} \to ${2:\infty}}
endsnippet snippet prod "product" w
\prod_{${1:n=${2:1}}}^{${3:\infty}} ${4:${VISUAL}} $0
endsnippet snippet part "d/dx" w
\frac{\partial ${1:V}}{\partial ${2:x}} $0
endsnippet context "math()"
snippet sq "\sqrt{}" iA
\sqrt{${1:${VISUAL}}} $0
endsnippet context "math()"
snippet sr "^2" iA
^2
endsnippet context "math()"
snippet cb "^3" iA
^3
endsnippet context "math()"
snippet td "to the ... power" iA
^{$1}$0
endsnippet context "math()"
snippet rd "to the ... power" iA
^{($1)}$0
endsnippet snippet __ "subscript" iA
_{$1}$0
endsnippet snippet ooo "\infty" iA
\infty
endsnippet snippet rij "mrij" i
(${1:x}_${2:n})_{${3:$2}\\in${4:\\N}}$0
endsnippet snippet <= "leq" iA
\le
endsnippet snippet >= "geq" iA
\ge
endsnippet context "math()"
snippet EE "geq" iA
\exists
endsnippet context "math()"
snippet AA "forall" iA
\forall
endsnippet context "math()"
snippet xnn "xn" iA
x_{n}
endsnippet context "math()"
snippet ynn "yn" iA
y_{n}
endsnippet context "math()"
snippet xii "xi" iA
x_{i}
endsnippet context "math()"
snippet yii "yi" iA
y_{i}
endsnippet context "math()"
snippet xjj "xj" iA
x_{j}
endsnippet context "math()"
snippet yjj "yj" iA
y_{j}
endsnippet context "math()"
snippet xp1 "x" iA
x_{n+1}
endsnippet context "math()"
snippet xmm "x" iA
x_{m}
endsnippet snippet R0+ "R0+" iA
\\R_0^+
endsnippet snippet plot "Plot" w
\begin{figure}[$1]
\centering
\begin{tikzpicture}
\begin{axis}[
xmin= ${2:-10}, xmax= ${3:10},
ymin= ${4:-10}, ymax = ${5:10},
axis lines = middle,
]
\addplot[domain=$2:$3, samples=${6:100}]{$7};
\end{axis}
\end{tikzpicture}
\caption{$8}
\label{${9:$8}}
\end{figure}
endsnippet snippet nn "Tikz node" w
\node[$5] (${1/[^0-9a-zA-Z]//g}${2}) ${3:at (${4:0,0}) }{$${1}$};
$0
endsnippet context "math()"
snippet mcal "mathcal" iA
\mathcal{$1}$0
endsnippet snippet lll "l" iA
\ell
endsnippet context "math()"
snippet nabl "nabla" iA
\nabla
endsnippet context "math()"
snippet xx "cross" iA
\times
endsnippet priority 100
snippet ** "cdot" iA
\cdot
endsnippet context "math()"
snippet norm "norm" iA
\|$1\|$0
endsnippet priority 100
context "math()"
snippet '(?<!\\)(sin|cos|arccot|cot|csc|ln|log|exp|star|perp)' "ln" rwA
\\`!p snip.rv = match.group(1)`
endsnippet priority 300
context "math()"
snippet dint "integral" wA
\int_{${1:-\infty}}^{${2:\infty}} ${3:${VISUAL}} $0
endsnippet priority 200
context "math()"
snippet '(?<!\\)(arcsin|arccos|arctan|arccot|arccsc|arcsec|pi|zeta|int)' "ln" rwA
\\`!p snip.rv = match.group(1)`
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 context "math()"
snippet invs "inverse" iA
^{-1}
endsnippet context "math()"
snippet compl "complement" iA
^{c}
endsnippet context "math()"
snippet \\\ "setminus" iA
\setminus
endsnippet snippet >> ">>" iA
\gg
endsnippet snippet << "<<" iA
\ll
endsnippet snippet ~~ "~" iA
\sim
endsnippet context "math()"
snippet set "set" wA
\\{$1\\} $0
endsnippet snippet || "mid" iA
\mid
endsnippet context "math()"
snippet cc "subset" Ai
\subset
endsnippet snippet notin "not in " iA
\not\in
endsnippet context "math()"
snippet inn "in " iA
\in
endsnippet snippet NN "n" iA
\N
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 snippet OO "emptyset" iA
\O
endsnippet snippet RR "real" iA
\R
endsnippet snippet QQ "Q" iA
\Q
endsnippet snippet ZZ "Z" iA
\Z
endsnippet snippet <! "normal" iA
\triangleleft
endsnippet snippet <> "hokje" iA
\diamond
endsnippet context "math()"
snippet '(?<!i)sts' "text subscript" irA
_\text{$1} $0
endsnippet context "math()"
snippet tt "text" iA
\text{$1}$0
endsnippet context "math()"
snippet case "cases" wA
\begin{cases}
$1
\end{cases}
endsnippet snippet SI "SI" iA
\SI{$1}{$2}
endsnippet snippet bigfun "Big function" iA
\begin{align*}
$1: $2 &\longrightarrow $3 \\\\
$4 &\longmapsto $1($4) = $0
.\end{align*}
endsnippet snippet cvec "column vector" iA
\begin{pmatrix} ${1:x}_${2:1}\\\\ \vdots\\\\ $1_${2:n} \end{pmatrix}
endsnippet priority 10
context "math()"
snippet "bar" "bar" riA
\overline{$1}$0
endsnippet 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 snippet letw "let omega" iA
Let $\Omega \subset \C$ be open.
endsnippet snippet HH "H" iA
\mathbb{H}
endsnippet snippet DD "D" iA
\mathbb{D}
endsnippet # vim:ft=snippets

latex在vim中的代码片段的更多相关文章

  1. 使用 Git 来管理 Xcode 中的代码片段

    使用 Git 来管理 Xcode 中的代码片段 代码片段介绍 xcode4 引入了一个新 feature: code snippets,在整个界面的右下角,可以通过快捷键:cmd + ctrl + o ...

  2. 如何在VScode中添加代码片段

    拿 VUE 举例,新建 VUE 文件,输入前缀,出现代码段 文件 --->  首选项 ---> 用户代码片段  在输入框中输入 vue ,找到 vue.json ,然后在 vue.json ...

  3. sublimetext3中保存代码片段

    在日常的开发工作中,不断重复上一次敲过的代码,有时确实感到伐木累."蓝瘦"(难受)."香菇"(想哭),大概表达的也是这样的心境吧!:grinning: 所以,在 ...

  4. 如何在Sublime Text中添加代码片段

    我们在编写代码的时候,总会遇到一些需要反复使用的代码片段.这时候就需要反复的复制和黏贴,大大影响效率.我们利用Sublime Text的snippet(代码片段)功能,就能很好的解决这一问题.通俗的讲 ...

  5. 金蝶handler中 collection 代码片段理解

    1,AtsOverTimeBillBatchEditHandler中collection的理解 SelectorItemCollection selectors = new SelectorItemC ...

  6. VS中添加自定义代码片段

    前言 用#4敲出 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; int main(voi ...

  7. VS中自定义代码片段

    VS - 工具 - 代码片段管理器 实现:propnotify 加 Tab 键 生成属性定义代码片段 (包含一个字段定义,一个属性get/set定义,其中set会触发属性值变更事件) <?xml ...

  8. [工作总结]jQuery在工作开发中常用代码片段集锦(1-10)

    1.jQuery,JS实现tab切换 原生JS实现 HTML代码如下: <div class="wrap"> <ul id="tag"> ...

  9. Android 中常用代码片段

    一:AsyncTask 的使用 (1)activity_main.xml <TextView android:id="@+id/tvInfo" android:layout_ ...

随机推荐

  1. OEL7.6源码安装MYSQL5.7

    首先官网下载安装包https://dev.mysql.com/downloads/mysql/5.7.html#downloads 然后上传解压至/usr/local目录 [root@localhos ...

  2. C# Net 比较2个字符串的相似度(使用余弦相似度)

    C# Net 比较2个字符串的相似度(使用余弦相似度) 复制代码使用: /// <summary> /// 比较2个字符串的相似度(使用余弦相似度) /// </summary> ...

  3. hadoop hdfs 有内网、公网ip后,本地调试访问不了集群解决

    问题背景: 使用云上的虚拟环境搭建测试集群,导入一些数据,在本地idea做些debug调试,但是发现本地idea连接不上测试环境 集群内部配置hosts映射是内网映射(内网ip与主机名映射),本地只能 ...

  4. Linux的httpd服务介绍和部署

    软件介绍 客户端代理软件     IE,firefox,chroome,opera      服务器端软件      httpd,Nginx,Tengine,ISS,Lighthttp       应 ...

  5. K8s Helm安装配置入门

    作为k8s现在主流的一种包部署方式,尽管不用,也需要进行一些了解.因为,它确实太流行了. 这一套太极拳打下来,感觉helm这种部署,目前还不太适合于我们公司的应用场景.它更适合需要手工编程各种yaml ...

  6. Windows中的txt文件到Mac打开是乱码 解决办法

    在Mac下打开“文本编辑”程序之后,选择菜单“文本编辑” -> “偏好设置”.2)在“偏好设置”中选择第二个标签页“打开和存储”,选择“纯文本文件编码”中的“打开文件”和“存储文件”修改成为“中 ...

  7. Comet OJ 夏季欢乐赛 分配学号

    Comet OJ 夏季欢乐赛 H 分配学号 题目传送门 题目描述 今天,是JWJU给同学们分配学号的一天!为了让大家尽可能的得到自己想要的学号,鸡尾酒让大家先从 [1,10^{18}][1,1018] ...

  8. django ORM CRUD

    一.增加数据-Create 1.类名.objects.create(属性=值,属性=值) Myomodel.objects.create(name=) 2.d={"属性":&quo ...

  9. [PHP] Layui + jquery 实现 实用的文章自定义标签

    先看实现效果: html 代码如下: <!doctype html> <html> <head> <meta charset="utf-8" ...

  10. dfs與bfs常用模板

    基本遍歷: //dfs void dfs(int x) { v[x]=1; for(int i=head[x];i;i=next[i]) { int y=ver[i]; if(v[y]) contin ...