-
Notifications
You must be signed in to change notification settings - Fork 6
/
latex.hsnips
646 lines (546 loc) · 12.7 KB
/
latex.hsnips
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
global
function gen_matrix(nrow, ncol, index) {
let results = "\n";
let order = 1;
for (var i=0; i<nrow; i++){
results += ' ';
for(var j = 0; j < ncol; j++){
results += "\$" +(order ).toString() + ((j == ncol -1) ? " \\\\\\" : " & ");
order ++;
}
if (i == nrow-1)
results = results.slice(0, -4);
results += index ? "\n" : "";
}
return results;
}
function gen_vector(m) {
let results = "";
let order = 1;
for (var i=0; i<m-1; i++){
results += "$" + (order).toString() + " & ";
order ++;
}
results += "$" + (order).toString();
return results;
}
function gen_fig(label, nfig) {
let results = "";
results += "\\begin{figure}[htb!]\n";
results += " \\centering\n";
let order = 2;
if (nfig == 1) {
results += " \\includegraphics[width=.${1:4}\\textwidth]{./img${2}}\n";
order ++;
}
else {
for (var i=0; i<nfig; i++){
results += " \\begin{subfigure}{.${1:3}\\textwidth}\n";
results += " \\includegraphics[width=\\textwidth]{./img${" + (order).toString() + "}}\n";
results += " \\caption{}\n";
results += " \\label{fig." + label + "_" + (i+1).toString() + "}\n";
results += " \\end{subfigure}\n";
order ++;
}
}
results += " \\caption{${" + (order).toString() + "}}\n";
results += " \\label{fig." + label + "}\n";
results += "\\end{figure}";
return results;
}
function gen_img(nfig) {
let results = "<div align=center>\n";
if (nfig == 1) {
results += " <img width=50% style=margin:2% src=\"assets${1}\">\n";
}
else {
let order = 1;
for (var i=0; i<nfig; i++){
results += " <img width=30% style=margin:2% src=\"assets${" + (order).toString() + "}\">\n";
order ++;
}
}
results += "</div>\n";
return results;
}
function gen_columns(m) {
if (m == 1) return "";
let results = "\\begin{columns}[c]\n";
let order = 2;
for (var i=0; i<m; i++){
results += " \\begin{column}{.${1:45}\\textwidth}\n";
results += " ${" + (order).toString() + "}\n";
results += " \\end{column}\n";
order ++;
}
results += "\\end{columns}";
return results;
}
endglobal
############################# tmp #############################
# txc -> textcolor
snippet txc "textcolor" iA
\textcolor{c}{
${1:${VISUAL}}
}$0
endsnippet
############################# tikz ############################
snippet `^( *)tikz` "theorem" bA
``rv = m[1]``\begin{tikzpicture}
``rv = m[1]`` $1
``rv = m[1]``\end{tikzpicture}$0
endsnippet
snippet `scatter\(([^,]+), ([^,]+)\) ` "scatter" bA
\addplot[
only marks,
mark=*,
mark size=1.5,
mark options={draw=``rv=m[2]``,fill=``rv=m[2]``!80},
] table[x=x, y=y, col sep=comma] {``rv=m[1]``};
endsnippet
snippet `plot\(([^,]+), ([^,]+)\) ` "plot line" bA
\addplot[
``rv=m[2]``,
thick,
] table[x=x, y=y, col sep=comma] {``rv=m[1]``};
endsnippet
snippet `scatter3\(([^,]+), ([^,]+)\) ` "scatter" bA
\addplot[
only marks,
mark=*,
mark size=1.5,
mark options={draw=``rv=m[2]``,fill=``rv=m[2]``!80},
] table[x=x, y=y, z=z, col sep=comma] {``rv=m[1]``};
endsnippet
snippet `plot3\(([^,]+), ([^,]+)\) ` "plot line" bA
\addplot[
``rv=m[2]``,
thick,
] table[x=x, y=y, z=z, col sep=comma] {``rv=m[1]``};
endsnippet
snippet `axis2 ` "pgfaxis" bA
\begin{axis}[
xlabel=$ x $, ylabel=$ y $,
xmin=-3.5, xmax=3.5,
ymin=-2.5, ymax=2.5,
grid, axis equal image,
legend cell align=left,
legend style={
at={(axis cs:3.5,2.5)},
anchor=north east,
font=\tiny,
draw=none,
fill=none
}
]
$0
\end{axis}
endsnippet
snippet `axis3 ` "pgfaxis" bA
\begin{axis}[
xlabel=$ x $, ylabel=$ y $, zlabel=$ z $,
xmin=-3.5, xmax=3.5,
ymin=-2.5, ymax=2.5,
zmin=-2.5, zmax=2.5,
grid, axis equal image,
]
$0
\end{axis}
endsnippet
############################# beamer #############################
#snippet only "beamer only" iA
#\only<${1:1}>{
# ${2:${VISUAL}}
#}$0
#endsnippet
snippet ani "animategraphics" bA
\animategraphics[width=\textwidth,autoplay,loop,palindrome]{${1:12}}{./img${2}}{${3:0}}{${4:10}}
endsnippet
snippet `col ([0-9]+) ` "columns" bA
``rv = gen_columns(m[1])``$0
endsnippet
# frame abc -> \begin{frame}
snippet `frame (\S+) ([0-9]+) ` "label" A
\begin{frame}{``rv = m[1]``}
``rv = gen_columns(m[2])``$0
\end{frame}
endsnippet
############################# latex enverniments #############################
# txt -> \text{}
snippet txt "text" iA
\text{${1:${VISUAL}}}$0
endsnippet
# tit -> \textit{}
snippet tit "text it" iA
\textit{${1:${VISUAL}}}$0
endsnippet
# tbf -> \textbf{}
priority 10
snippet tbf "textbf" iA
\textbf{${1:${VISUAL}}}$0
endsnippet
# lemma
snippet `^( *)lemma` "lemma" bA
``rv = m[1]``\begin{lemma}
``rv = m[1]`` $1
``rv = m[1]``\end{lemma}$0
endsnippet
# theorem
snippet `^( *)thm` "theorem" bA
``rv = m[1]``\begin{theorem}
``rv = m[1]`` $1
``rv = m[1]``\end{theorem}$0
endsnippet
snippet `^( *)def` "theorem" bA
``rv = m[1]``\begin{definition}
``rv = m[1]`` $1
``rv = m[1]``\end{definition}$0
endsnippet
snippet == "inline Math" iA
\\( ${1:${VISUAL}} \\)$0
endsnippet
snippet `^( *)\\\[` "inline Math" bA
``rv = m[1]``\[
``rv = m[1]`` ${VISUAL}$0
``rv = m[1]``\]
endsnippet
snippet `^( *)eq` "equation" bA
``rv = m[1]``\begin{equation}
``rv = m[1]`` ${VISUAL}$0
``rv = m[1]``\end{equation}
endsnippet
snippet `^( *)beg` "begin{} / end{}" bA
``rv = m[1]``\begin{$1}
``rv = m[1]`` ${VISUAL}$0
``rv = m[1]``\end{$1}
endsnippet
snippet `^( *)minipage` "minipage" bA
``rv = m[1]``\begin{minipage}{.${1:45}\textwidth}
``rv = m[1]`` ${VISUAL}$0
``rv = m[1]``\end{minipage}
endsnippet
# lab abc -> \label{abc}
snippet `lab (\S+) ` "label" A
\label{``rv = m[1]``}
endsnippet
# bmat m n -> a matrix with the size of m*n
snippet `(bm|pm|m|vm)at ([0-9]+) ([0-9]+) ` "matrix" bA
\begin{``rv = m[1]``atrix}``
rv = gen_matrix(m[2],m[3],1);
``\end{``rv = m[1]``atrix}$0
endsnippet
# vec m -> a vector with the size of 1*m
snippet `vec ([0-9]+) ` "matrix" bA
\begin{bmatrix} ``rv = gen_vector(m[1])`` \end{bmatrix}$0
endsnippet
# fig label n -> figure enverniment with n subfigures, and the labels are specified by label
snippet `fig (\S+) ([0-9]+) ` "figure" bA
``rv = gen_fig(m[1], m[2])``$0
endsnippet
snippet `ref (\S+) ` "reference" A
\cref{``rv = m[1]``}
endsnippet
snippet `cite (\S+) ` "cite" A
\cite{``rv = m[1]``}
endsnippet
snippet `(chapter|section|subsection|subsubsection) (\S+) ` "paragraph" bwA
\\``rv = m[1]``{``rv = m[2]``}
$0
endsnippet
############################# Math #############################
############################# Greek letters
snippet @a "alpha" iAm
\alpha
endsnippet
snippet @A "alpha" iAm
\alpha
endsnippet
snippet @b "beta" iAm
\beta
endsnippet
snippet @B "beta" iAm
\beta
endsnippet
snippet @c "chi" iAm
\chi
endsnippet
snippet @C "chi" iAm
\chi
endsnippet
snippet @p "pi" iAm
\pi
endsnippet
snippet :p "partial" iAm
\partial
endsnippet
snippet @P "Pi" iAm
\Pi
endsnippet
snippet @g "gamma" iAm
\gamma
endsnippet
snippet @G "Gamma" iAm
\Gamma
endsnippet
snippet @d "delta" iAm
\delta
endsnippet
snippet @D "Delta" iAm
\Delta
endsnippet
snippet @e "epsilon" iAm
\epsilon
endsnippet
snippet @E "epsilon" iAm
\epsilon
endsnippet
snippet :e "varepsilon" iAm
\varepsilon
endsnippet
snippet :E "varepsilon" iAm
\varepsilon
endsnippet
snippet @n "nabla" iAm
\nabla
endsnippet
snippet @z "zeta" iAm
\zeta
endsnippet
snippet @Z "zeta" iAm
\zeta
endsnippet
snippet @t "theta" iAm
\theta
endsnippet
snippet @T "Theta" iAm
\Theta
endsnippet
snippet :t "tau" iAm
\tau
endsnippet
snippet @k "kappa" iAm
\kappa
endsnippet
snippet @K "kappa" iAm
\kappa
endsnippet
snippet @l "lambda" iAm
\lambda
endsnippet
snippet @L "Lambda" iAm
\Lambda
endsnippet
snippet @m "mu" iAm
\mu
endsnippet
snippet @M "mu" iAm
\mu
endsnippet
snippet @r "rho" iAm
\rho
endsnippet
snippet @R "rho" iAm
\rho
endsnippet
snippet @s "sigma" iAm
\sigma
endsnippet
snippet @S "Sigma" iAm
\Sigma
endsnippet
snippet @o "omega" iAm
\omega
endsnippet
snippet @O "Omega" iAm
\Omega
endsnippet
snippet \{ "bracket" iAm
\\{ ${1:${VISUAL}} \\}$0
endsnippet
snippet @| "left| right|" iAm
\left| ${1:${VISUAL}} \right|$0
endsnippet
snippet :| "left\| right\|" iAm
\left\| ${1:${VISUAL}} \right\|$0
endsnippet
snippet @} "\left\{ \right\}" iAm
\left\\{ ${1:${VISUAL}} \right\\}$0
endsnippet
snippet ` bl ` "left\{ right." iAm
\left\\{ ${1:${VISUAL}} \right.$0
endsnippet
snippet ` br ` "left. right\}" iAm
\left. ${1:${VISUAL}} \right\\}$0
endsnippet
snippet @] "left[ right]" iAm
\left[ ${1:${VISUAL}} \right]$0
endsnippet
snippet @) "left( right)" iAm
\left( ${1:${VISUAL}} \right)$0
endsnippet
snippet @> "leftangle rightangle" iAm
\left< ${1:${VISUAL}} \right>$0
endsnippet
############################# math symbols
# RR -> \mathbb{R}
snippet `RR` "sets" iwAm
\\mathbb{``rv=m[0].charAt(0)``}
endsnippet
# => -> \Rightarrow
snippet `->` "implies" iAm
\rightarrow
endsnippet
# =< -> \Leftarrow
snippet `<-` "implied by" iAm
\leftarrow
endsnippet
# <= -> \leq
snippet `<=` "leq" iAm
\leq
endsnippet
# >= -> \geq
snippet `>=` "geq" iAm
\geq
endsnippet
# != -> \neq
snippet `!=` "neq" iAm
\neq
endsnippet
snippet `~=` "approx: iAm
\approx
endsnippet
# ... -> \cdots
snippet ... "dots" iAm
\dots
endsnippet
snippet *** "cdots" iAm
\cdots
endsnippet
snippet ;;; "vdots" iAm
\vdots
endsnippet
snippet ::: "ddots" iAm
\ddots
endsnippet
# inf -> \infty
snippet inf "\infty" iAm
\infty
endsnippet
############################# math functions
priority 200
snippet norm "norm" iAm
\left\| ${1:${VISUAL}} \right\|$0
endsnippet
snippet ^ "superscript" iAm
^{${1}}$0
endsnippet
snippet _ "subscript" iAm
_{${1}}$0
endsnippet
# spl -> the split enverniment with the selected text
snippet spl "split" Am
\begin{split}
${VISUAL}$0
\end{split}
endsnippet
# ali -> the aligned enverniment the selected text
snippet ali "aligned" Am
\begin{aligned}
${VISUAL}$0
\end{aligned}
endsnippet
# case -> the cases enverniment the selected text
snippet case "cases" Am
\begin{cases}
${VISUAL}$0
\end{cases}
endsnippet
# fr -> fractor enverniment with the selected text
snippet // "frac" iAm
\frac{${1:${VISUAL}}}{$2}$0
endsnippet
# \mathbf{A}^T -> \mathbf{A}^{\mathbrm T}
snippet `\^\{T` "transpose" iAm
^{\mathrm{T}
endsnippet
# \mathbf{A}^H -> \mathbf{A}^{\mathbrm H}
snippet `\^\{H` "hermitian" iAm
^{\mathrm{H}
endsnippet
# ||x||_F -> ||x||_{\mathrm F}
snippet `\_\{F` "frobenius" iAm
_{\mathrm{F}
endsnippet
snippet `(\\?[a-zA-Z0-9]\w*({?\w*})?)(bf|BF)` "mathbf" iAm
\mathbf{``rv = m[1]``}
endsnippet
snippet `(\\?[a-zA-Z0-9]\w*({?\w*})?)(bm|BM)` "mathbm" iAm
\bm{``rv = m[1]``}
endsnippet
# priority 100
snippet `(\\?[a-zA-Z]\w*({?\w*})?)bb` iAm
\mathbb{``rv = m[1]``}$0
endsnippet
# priority 100
snippet `(\\?[a-zA-Z]\w*({?\w*})?)cal` "mathcal" iAm
\mathcal{``rv = m[1].toUpperCase()``}$0
endsnippet
# priority 100
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(frak)` "mathfrak" iAm
\mathfrak{``rv = m[1]``}
endsnippet
# priority 100
snippet `(?<!\\)\b([a-zA-Z]+)rm` "mathrm" iAm
\mathrm{``rv = m[1]``}
endsnippet
snippet `(?<!arc)(?<!\\)(sin|cos|tan|csc|sec|cot|ln|log|lg|det|ker|max|min)` "function" iAm
\``rv=m[1]+' '``
endsnippet
snippet `(?<=\\(sin|cos|tan|csc|sec|cot))( )h` "function" iAm
``rv='h '``
endsnippet
# in -> \in
snippet ` (in|notin|subset|subseteq|supset|supseteq) ` "sets operator" wAm
\``rv = m[1]``
endsnippet
# cap -> \cap
snippet ` (circ|cap|cup|land|lor|lnot|oplus|ominus|times|otimes|sqcap|sqcup|vdash|models) ` "logic operator" wAm
\``rv = m[1]``
endsnippet
snippet empty "empty set" Am
\varnothing
endsnippet
snippet `(\\?[a-zA-Z0-9]\w*({?\w*})?)op` "operatorname" iAm
\operatorname{``rv = m[1]``}
endsnippet
snippet `([0-9]+)d` "degrees" iAm
``rv = m[1]``^{\circ}$0
endsnippet
snippet `sqrt` "sqrt" iAm
\sqrt{${1:${VISUAL}}}$0
endsnippet
snippet `sum` "sqrt" iAm
\sum
endsnippet
############################# hat operations
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(bar|BAR)` "Bar" iAm
\overline{``rv = m[1]``}
endsnippet
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(td|TD)` "tilde" iAm
\tilde{``rv = m[1]``}
endsnippet
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hat|HAT)` "hat" iAm
\hat{``rv = m[1]``}
endsnippet
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hvec)` "Vector postfix" iAm
\vec{``rv = m[1]``}
endsnippet
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(rta)` "Vector postfix" iAm
\overrightarrow{``rv = m[1]``}
endsnippet
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hdot)` "dot" iAm
\dot{``rv = m[1]``}
endsnippet
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hddot)` "ddot" iAm
\ddot{``rv = m[1]``}
endsnippet