-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmarkdown.hsnips
1007 lines (784 loc) · 19.4 KB
/
markdown.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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
global
// JavaScript code
function gen_matrix(nrow, ncol) {
let results = "";
let order = 1;
for (var i=0; i < nrow; i++){
results += ' ';
for(var j = 0; j < ncol - 1; j++){
results += "$" + (order).toString() + " & ";
order ++;
}
results += "$" + (order).toString() + " \\\\" + "\\";
order ++;
}
return results;
}
function gen_matrix_transposed(nrow, ncol) {
let results = "";
for (var i = 0; i < nrow; i++){
results += ' ';
var j = 0;
for(; j < ncol - 1;j++){
results += "$" + (i + j * ncol + 1).toString() + " & ";
}
results += "$" + (i + j * ncol + 1).toString() + " \\\\" + "\\";
}
return results;
}
function tes_matrix(nrow, ncol,t) {
let results = "";
let order = 1;
for (var i=0; i<nrow; i++){
results += ' ';
for(var j = 0;j <ncol-1;j++){
if (order > 1 ){
results += "${" +(order ).toString() + ":" + t[order-2] + "}\t & ";
}
else{
results += "$" +(order ).toString() + " & ";
}
order ++;
}
results += "$"+(order).toString() +" \\\\" + "\\ ";
order ++;
}
return results;
}
// 输出一个表格
function createTable(rows, cols) {
let ret = "";
let order = 1;
for (let i = 0; i < parseInt(rows) + 2; i++) {
for (let j = 0; j < parseInt(cols); j++) {
if (i === 1) {
ret += "|---";
} else {
ret += "| $" + (order).toString() + " ";
order++;
}
}
ret += "|\n"
}
return ret;
}
endglobal
# == Fraction Match ==
snippet // "Fraction" iAm
\\frac{${1:${VISUAL}}}{$2}$0
endsnippet
snippet `((\d+)|(\d*)(\\)?([A-Za-z!]+)((\^|_)(\{\d+\}|\d))*)/` "Fraction no ()" iAm
\frac{``rv = m[1]``}{$1}$0
endsnippet
priority 200
snippet `(?<=\s)(\\mu|\\alpha|\\sigma|\\rho|\\beta|\\gamma|\\delta|\\zeta|\\eta|\\varepsilon|\\theta|\\iota|\\kappa|\\vartheta|\\lambda|\\nu|\\pi|\\rho|\\tau|\\upsilon|\\phi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega|[A-Za-z]{1,2})?(_[A-Za-z0-9]|_\{[^}]+\})?(\^[A-Za-z0-9]|\^\{[^}]+\})?(_[A-Za-z0-9]|_\{[^}]+\})?(\([^)]+\))(_[A-Za-z0-9]|_\{[^}]+\})?(\^[A-Za-z0-9]|\^\{[^}]+\})?(_[A-Za-z0-9]|_\{[^}]+\})?\/` "Fraction with ()" iAm
``rv = "\\frac{" + m.slice(1, m.length).join('') + "}{$1}$2"``
endsnippet
# == Hat Operation ==
# ==== Auto Capture Hat Operation ====
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hbar|BAR)` "Bar" iAm
\overline{``rv = m[1] + m[2] + m[3]``}
endsnippet
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(htd|TD)` "tilde" iAm
\tilde{``rv = m[1]``}
endsnippet
snippet `(\\?[a-zA-Z]\w*({?\w*})?)bar` "bar" iAm
\bar{``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*})?)(dot)` "dot" iAm
\dot{``rv = m[1]``}
endsnippet
priority 1000
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hdd)` "ddot" iAm
\ddot{``rv = m[1]``}
endsnippet
# ===== Static Hat Operation ====
snippet hbar "bar" iAm
\overline{$1}$0
endsnippet
snippet hat "hat" iAm
\hat{$1}$0
endsnippet
snippet hsq "\sqrt{}" iAm
\sqrt{${1}}$0
endsnippet
# == Superscript Operation ==
snippet invs "inverse" iAm
^{-1}
endsnippet
snippet dig "digree" iAm
^{\circ}
endsnippet
priority 10000
snippet TR "inverse" iAm
^{\mathsf{T}}
endsnippet
snippet CL "complement" iAm
^{c}
endsnippet
snippet R+ "R0+" iAm
R_0^+
endsnippet
snippet pow "power" iAm
^{${1:2}}$0
endsnippet
snippet tp "to the ... power" iAm
^{${1:2}}$0
endsnippet
snippet sr "square" iAm
^{2}$0
endsnippet
# == Subscript Operation ==
snippet td "subscript" iAm
_{${1}}$0
endsnippet
snippet sb "subscript" iAm
_{${1:2}}$0
endsnippet
snippet `(})(\d)\2` "auto subscript" iAm
`` rv = m[1] + "_" + m[2]``
endsnippet
snippet `([A-Za-z])(\d)` "auto subscript" iAm
`` rv = m[1] + "_" + m[2]``
endsnippet
priority 100
snippet `([A-Za-z])_(\d{2})` "auto subscript" iAm
`` rv = m[1] + "_{" + m[2] + "}$0" ``
endsnippet
priority 100
snippet `([A-Za-z])S(\d)` "auto subscript" iAm
`` rv = m[1] + "_{" + m[2] + "$1}$2"``
endsnippet
snippet `\b(?<!\\)([A-Za-z}])([a-z])\2` "auto subscript 2" iAm
`` rv = m[1] + "_" + m[2].substring(0, 1) ``
endsnippet
snippet `\b(?<!\\)([A-Za-z}])S([a-z])\2` "auto subscript 2" iAm
`` rv = m[1] + "_{" + m[2].substring(0, 1) + "$1}$2"``
endsnippet
# Custom: Add more greek letters
snippet `(\\mu|\\alpha|\\sigma|\\rho|\\beta|\\gamma|\\delta|\\zeta|\\eta|\\varepsilon|\\epsilon|\\theta|\\iota|\\kappa|\\vartheta|\\lambda|\\nu|\\pi|\\rho|\\tau|\\upsilon|\\phi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega)([a-z])\2` "auto subscript for greek letter" iAm
`` rv = m[1] + "_" + m[2].substring(0, 1) ``
endsnippet
snippet `(\\mu|\\alpha|\\sigma|\\rho|\\beta|\\gamma|\\delta|\\zeta|\\eta|\\varepsilon|\\epsilon|\\theta|\\iota|\\kappa|\\vartheta|\\lambda|\\nu|\\pi|\\rho|\\tau|\\upsilon|\\phi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega)S([a-z])\2` "auto subscript for greek letter" iAm
`` rv = m[1] + "_{${1:" + m[2].substring(0, 1) + "}}$2"``
endsnippet
# == Font Operation ==
# ==== Static Operation ====
snippet txt "text" iAm
\text{$1}$0
endsnippet
snippet tit "text it" iAm
\textit{$1}$0
endsnippet
snippet mcal "mathcal" im
\mathcal{$1}$0
endsnippet
snippet mbb "mathbb" iAm
\mathbb{$1}$0
endsnippet
snippet mbf "mathbf" iAm
\mathbf{$1}$0
endsnippet
snippet mbm "mathbm" iAm
\mathbm{$1}$0
endsnippet
snippet KK "^K" iAm
^{\mathrm{K}}
endsnippet
snippet TT "^T" iAm
^{\mathrm{T}}
endsnippet
snippet HH "^H" iAm
^{\mathrm{H}}
endsnippet
snippet RR "R" iAm
\mathbb{R}
endsnippet
snippet NN "N" iAm
\mathbb{N}
endsnippet
snippet ZZ "Z" iAm
\mathbb{Z}
endsnippet
snippet ZZ "Z" iAm
\mathbb{Z}
endsnippet
snippet QQ "Q" iAm
\mathbb{Q}
endsnippet
snippet CC "C" iAm
\mathbb{C}
endsnippet
# ==== Dynamic Operation ====
priority 100
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(bf|BF)` "mathbf" iAm
\mathbf{``rv = m[1]``}
endsnippet
priority 100
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(bm|BM)` "mathbm" iAm
\bm{``rv = m[1]``}
endsnippet
snippet 0bm "0bm" iAm
\bm{0}
endsnippet
snippet 1bm "1bm" iAm
\bm{1}
endsnippet
priority 100
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(bs)` "boldsymbol" iAm
\boldsymbol{``rv = m[1]``}
endsnippet
priority 100
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(sf)` "mathsf" iAm
\mathsf{``rv = m[1]``}
endsnippet
priority 100
snippet `(\\?[a-zA-Z]\w*({?\w*})?)(frak)` "mathfrak" iAm
\mathfrak{``rv = m[1]``}
endsnippet
priority 100
snippet `(\\?[a-zA-Z]\w*({?\w*})?)cal` "mathcal" iAm
\mathcal{``rv = m[1].toUpperCase()``}$0
endsnippet
priority 100
snippet `(?<!\\)\b([a-zA-Z]+)rm` "mathrm" iAm
\mathrm{``rv = m[1]``}
endsnippet
priority 100
snippet `(?<!\\)\b([a-zA-Z]+)opn` "operatorname" iAm
\operatorname{``rv = m[1]``}
endsnippet
priority 100
snippet `(\\?[a-zA-Z]\w*({?\w*})?)bb` iAm
\mathbb{``rv = m[1]``}$0
endsnippet
# == Auto Symbol ==
snippet oo "\infty" iAmm
\infty
endsnippet
snippet ... "cdots" iAm
\cdots
endsnippet
snippet `(\d\d+)\.\.` "0, 1, 2, ..., n" iAm
``rv = m[1].split('').map((d) => "${1:_}" + d + "${2:, }").join('');``\cdots${3:${2:, }${1:_}n}
endsnippet
snippet `(\d\d+),` "0, 1, 2" iAm
``rv = m[1].split('').map((d) => "${1:_}" + d).join("${2:, }");``
endsnippet
snippet <> "hokje" iA
\diamond
endsnippet
# +... -> , \cdots
# - ... -> , \cdots
# add a space if there already is one.
priority 101
snippet `(?<=[-+])\s*\.\.\.` "smart cdots" imA
\cdots
endsnippet
# It seems that \ldots is only used when , ...,
# ,... -> , \ldots
# , ... -> , \ldots
priority 101
snippet `(?<=,)(\s*)\.\.\.` "smart ldots" imA
\ldots
endsnippet
snippet ** "dot multiply" iAm
\cdot
endsnippet
snippet +- "pm" iAm
\pm
endsnippet
snippet -+ "mp" iAm
\mp
endsnippet
snippet odot "odot" iAm
\odot
endsnippet
priority 101
snippet xx "cross" iAm
\times
endsnippet
snippet eps "epsilon" iAm
\epsilon
endsnippet
priority 100
snippet veps "varepsilon" iAm
\varepsilon
endsnippet
priority 100
snippet ell "ell" iAm
\ell
endsnippet
priority 100
snippet log "log" iAm
\log
endsnippet
snippet bin "binom" iAm
\binom{$1}{$2}
endsnippet
snippet oth "otherwise" iAm
\text{otherwise}
endsnippet
snippet star "star" iAm
^{*}
endsnippet
snippet `(?<!\\)(oint|iiint|iint|int)` "integrate" iAm
\\``rv = m[1]``
endsnippet
snippet `(?<!\\)(sum|min|max|argmin|argmax|sup|inf)` "sum|min|max|argmin|argmax|sup|inf" iAm
\\``rv = m[1]``
endsnippet
snippet `(?<!\\)(sin|cos|tan|arccot|cot|csc|ln|exp|det|perp|arcsin|arccos|arctan|arccot|arccsc|arcsec|ell|nabla|notin|not)` "function" iAm
\\``rv = m[1]``
endsnippet
snippet `(?<!\\)(mu|alpha|sigma|rho|beta|Beta|gamma|delta|pi|zeta|eta|varepsilon|theta|iota|kappa|vartheta|lambda|nu|pi|rho|tau|upsilon|varphi|phi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega)` "greek" iAm
\\``rv = m[1]``
endsnippet
# ==== Space Symbol ====
snippet `(?<!\\)(quad)` "ln" iAm
\\``rv = m[1]``
endsnippet
# ==== Logic Symbol ====
snippet empty "empty" iAm
\empty
endsnippet
priority 200
snippet inn "in" iAm
\in
endsnippet
priority 200
snippet `\\ln ?ot` "in" iAm
\lnot
endsnippet
snippet sse "subseteq" iAm
\subseteq
endsnippet
snippet sqs "sqsubset" iAm
\sqsubseteq
endsnippet
snippet tto "to" iAm
\to
endsnippet
priority 200
snippet ott "leftarrow" iAm
\leftarrow
endsnippet
priority 200
snippet `(?<!\\)(cap|cup|land|lor|lnot|oplus|ominus|otimes|sqcap|sqcup|vdash|models)` "logic operator" iAm
\\``rv = m[1]``
endsnippet
priority 200
snippet `(?<=\b|\d+)(?<!\\)(bot|top|dagger)` "logic symbols" iAm
\\``rv = m[1]``
endsnippet
snippet -> "to" iAm
\to
endsnippet
snippet !> "mapsto" iAm
\mapsto
endsnippet
snippet => "implies" iAm
\implies
endsnippet
snippet =< "implied by" iAm
\impliedby
endsnippet
priority 200
snippet iff "if and only if" iAm
\iff
endsnippet
snippet EE "exist" iAm
\exists
endsnippet
snippet AA "forall" iAm
\forall
endsnippet
snippet bec "because" iAm
\because
endsnippet
snippet thr "therefore" iAm
\therefore
endsnippet
# ==== Possibility Symbol ====
snippet Pr "Pr" iAm
\operatorname{Pr}
endsnippet
snippet Var "Var" iAm
\operatorname{Var}
endsnippet
snippet Cov "Cov" iAm
\operatorname{Cov}
endsnippet
snippet Exp "Expected" iAm
\mathbb{E}
endsnippet
# ==== Compare Symbol ====
snippet -- "setminus" iAm
\setminus
endsnippet
snippet >= "greater than" iAm
\ge $0
endsnippet
snippet dis "displaystyle" iAm
\displaystyle
endsnippet
snippet <= "less than" iAm
\le $0
endsnippet
snippet != "no equals" iAm
\neq
endsnippet
snippet == " constan equals" iAm
\equiv
endsnippet
snippet sim "sim" iAm
\sim
endsnippet
snippet `\\sim eq` "simeq" iAm
\simeq
endsnippet
snippet ~~ " Amppro equals" iAm
\approx
endsnippet
snippet ~= " Amppro equals2" iAm
\cong
endsnippet
snippet >> ">>" iAm
\gg
endsnippet
snippet << "<<" iAm
\ll
endsnippet
# == Auto Environment ==
# ==== Auto Math Mode ====
snippet lm "inline Math" wA
$${1}$$0
endsnippet
snippet dm "display Math" wA
$$
${1}
$$$0
endsnippet
snippet eqt "equation" wA
\begin{equation}
${1}
\end{equation}
endsnippet
snippet eqs "equation*" wA
\begin{equation*}
${1}
\end{equation*}
endsnippet
# ==== Common Environment ====
snippet case "cases" iAm
\begin{cases} $1, & $2 \\\\ $3, & $4 \end{cases}
endsnippet
snippet ali "aligned" iAm
\begin{aligned}
$1 \\\\
\end{aligned}
endsnippet
# == Auto Adaptive Close ==
snippet ceil "ceil" iAm
\left\lceil $1 \right\rceil $0
endsnippet
snippet floor "floor" iAm
\left\lfloor $1 \right\rfloor$0
endsnippet
priority 100
snippet @) "left( right)" Aim
\left( ${1} \right) $0
endsnippet
priority 100
snippet @| "left| right|" Aim
\left| ${1} \right| $0
endsnippet
priority 100
snippet @\ "left. right|" Aim
\left. ${1} \right|_{${2}}$0
endsnippet
priority 100
snippet @} "left\{ right\}" Aim
\left\\{ ${1} \right\\} $0
endsnippet
priority 100
snippet set "\{ \}" Aim
\\{ ${1} \\}$0
endsnippet
priority 100
snippet @] "left[ right]" Aim
\left[ ${1} \right] $0
endsnippet
priority 100
snippet @> "leftangle rightangle" iAm
\left<${1} \right>$0
endsnippet
priority 200
snippet norm iAm
\left\| ${1} \right\|$2
endsnippet
# == Snippet ==
# ==== General Snippet ====
# ====== Lite Snippet ======
snippet tag "tag" iAm
\tag{$1}
endsnippet
snippet xyb "Auto (x, y)" iAm
(x, y)
endsnippet
snippet xyzb "Auto (x, y ,z)" iAm
(x, y, z)
endsnippet
priority 100
snippet `\b([a-zA-Z])n(\d)` "x[n+1]" iAm
``rv = m[1]``_{${1:n}+``rv = m[2]``}$0
endsnippet
# Unkown
snippet rij "mrij" iAm
(${1:x}_${2:n})_{${3:$2} \\in ${4:N}}$0
endsnippet
priority 200
snippet abs "absolute value" iAm
\left\vert ${1} \right\vert $0
endsnippet
snippet beg "begin{} / end{}" bA
\\begin{$1}
$0
\\end{$1}
endsnippet
# ======== N Series ========
priority 100
snippet comma "comma" iAm
${1:\\alpha}_1,${1:\\alpha}_2,\\cdots,${1:\\alpha}_${2:n}
endsnippet
priority 100
snippet plus "plus" iAm
${1:k}_1${2:\\alpha}_1+${1:k}_2${2:\\alpha}_2+\\cdots+${1:k}_${3:n}${2:\\alpha}_${3:n}
endsnippet
snippet `\b([ijk])=n` "i=1,2,\cdots,n" iAm
``rv = m[1]``=1,2,\cdots,n
endsnippet
# ======== Common Operator Snippet ========
snippet taylor "taylor" iAm
\sum_{${1:k}=${2:0}}^{${3:\infty}} ${4:c_$1} (x-a)^$1 $0
endsnippet
snippet `(?<!\\)lim` "limit" iAm
\lim_{${1:n} \to ${2:\infty}}
endsnippet
snippet `(?<!\\)prod` "product" iAm
\prod_{${1:n=${2:1}}}^{${3:\infty}} ${4:${VISUAL}}$0
endsnippet
snippet `(?<!\\)part` "d/dx" iAm
\frac{\partial ${1:V}}{\partial ${2:x}}$0
endsnippet
priority 300
snippet `(?<!\\)diff` "d/dx" iAm
\frac{\mathrm{d}${1:y}}{\mathrm{d}${2:x}}$0
endsnippet
priority 400
snippet `(?<!\\)2diff` "d/dx" iAm
\frac{\mathrm{d}^2${1:y}}{\mathrm{d}${2:x}^2}$0
endsnippet
priority 400
snippet `(?<!\\)3diff` "d/dx" iAm
\frac{\mathrm{d}^3${1:y}}{\mathrm{d}${2:x}^3}$0
endsnippet
priority 300
snippet `dd` "dd" iAm
\mathrm{d}
endsnippet
snippet buu "bigcup" iAm
\bigcup_{${1:i \in ${2: I}}} $0
endsnippet
snippet bnn "bigcap" iAm
\bigcap_{${1:i \in ${2: I}}} $0
endsnippet
priority 100
snippet dint "integral" iAm
\int_{${1:-\infty}}^{${2:\infty}} ${3} \\mathrm{d}${4:x}$0
endsnippet
priority 200
snippet `c(o|n)?(l|n)?(b|c)?int` "s egral" iAm
``
let final = "\\"; // init
let isO = m[1] == "o";
(isO) ? final += "o" : "" // o option
let b = 1;
let isL = m[2] == "l";
(m[3] == 'b') ? b = 2 : (m[3] == 'c') ? b = 3 : 1;
for (let i = 0; i < b - 1; i++) {
final += "i";
}
final += "int";
final += ((b >= 2) || (b != 1 && !isO && isL)) ? "\\limits" : "";
let r = (b == 3) ? "E" : (b == 1 && (isL || isO)) ? "C" : "R";
final += ((b >= 2) || isO || (b == 1 && isL)) ? "_{${1:" + r + "}}" : "_{${1:-\\infty}}^{${2:\\infty}}";
let x = (b == 2) ? "A" : (b == 3) ? "V" : (b == 1 && isL) ? "s" : "x";
final += " ${3} \\mathrm{d}${4:" + x + "}$0";
rv = final;
``
endsnippet
# Custom: Can add more defined operator
priority 100
snippet `(?<![\a-zA-Z])(rank|trace|svd|eye|ones|orth|rows|cols|zeros|diag|rref|hstack|vstack|nullspace|eigen|dim|lcm|gcd|atan2|softmax|eig|sign|const)` "math function" iAm
\\operatorname{``rv = m[1]``}
endsnippet
# ====== Big Snippet ======
snippet bigdef "Big function" iAm
\begin{equation$6}
\begin{aligned}
$1\colon $2 &\longrightarrow $3 \\\\
$4 &\longmapsto $1($4) = $5
\end{aligned}
\end{equation$6}$0
endsnippet
priority 300
snippet bigmin "Optimization problem" iAm
\begin{equation$4}
\begin{aligned}
\min &\quad ${1:f(x)}\\\\
\text{s.t.} &\quad ${2:g(x)} \leq 0\\\\
&\quad ${3:h(x)} = 0\\\\
\end{aligned}
\end{equation$4}$0
endsnippet
priority 300
snippet bigmax "Optimization problem" iAm
\begin{equation$4}
\begin{aligned}
\max &\quad ${1:f(x)}\\\\
\text{s.t.} &\quad ${2:g(x)} \leq 0\\\\
&\quad ${3:h(x)} = 0\\\\
\end{aligned}
\end{equation$4}$0
endsnippet
priority 300
snippet Argmin "Optimization problem" iAm
\begin{aligned}
\argmin_{${1:\beta}}
&\quad ${2:f(x)} \\\\
\text{s.t.}
&\quad ${3:g(x) > 0} \\\\
\end{aligned}
endsnippet
priority 300
snippet Argmax "Optimization problem" iAm
\begin{aligned}
\argmax_{${1:\beta}}
&\quad ${2:f(x)} \\\\
\text{s.t.}
&\quad ${3:g(x) > 0} \\\\
\end{aligned}
endsnippet
snippet deff "Definition of function" iAm
$1\colon ${2:\\mathbb{R\}} \to ${3:\\mathbb{R\}}, ${4:x} \mapsto $0
endsnippet
snippet iid "independent and identical distribution" iAm
\overset{\text{i.i.d.}}{\sim}
endsnippet
snippet defe "define equal" iAm
\overset{\underset{\mathrm{def}}{}}{=}
endsnippet
snippet deft "define triangleq" iAm
\triangleq
endsnippet
# == Matrix ==
# ==== Static Matrix ====
snippet pmat "pmat" wm
\begin{pmatrix}
${1: }
\end{pmatrix} $0
endsnippet
snippet bmat "pmat" wm
\begin{bmatrix}
$1
\end{bmatrix} $0
endsnippet
snippet vecC "column vector" iAm
\begin{bmatrix} ${1:x}_1 \\\\ ${1:x}_2 \\\\ \vdots \\\\ ${1:x}_${2:n} \end{bmatrix}
endsnippet
snippet vecR "row vector" iAm
\begin{bmatrix} ${1:x}_1, ${1:x}_2, \cdots, ${1:x}_${2:n} \end{bmatrix}$0
endsnippet
priority 300
snippet omis "omission" iAm
\\begin{bmatrix}${1:1}&${2:1}&\\cdots&${4:1}\\\\${5:1}&${6:1}&\\cdots&${8:1}\\\\\\vdots&\\vdots&\\ddots&\\vdots\\\\${13:1}&${14:1}&\\cdots&${16:1}\\end{bmatrix}
endsnippet
priority 300
snippet submat "omission" iAm
\\begin{bmatrix}
${1:a}_{11} & ${1:a}_{12} & \\cdots & ${1:a}_{1n} \\\\
${1:a}_{21} & ${1:a}_{22} & \\cdots & ${1:a}_{2n} \\\\
\\vdots & \\vdots & \\ddots & \\vdots \\\\
${1:a}_{n1} & ${1:a}_{n2} & \\cdots & ${1:a}_{nn}
\\end{bmatrix}
endsnippet
priority 300
snippet subplusmat "omission" iAm
\\begin{bmatrix}
${1:a}_{11}+${2:b}_{11} & ${1:a}_{12}+${2:b}_{12} & \\cdots & ${1:a}_{1n}+${2:b}_{1n} \\\\
${1:a}_{21}+${2:b}_{21} & ${1:a}_{22}+${2:b}_{22} & \\cdots & ${1:a}_{2n}+${2:b}_{2n} \\\\
\\vdots & \\vdots & \\ddots & \\vdots \\\\
${1:a}_{n1}+${2:b}_{n1} & ${1:a}_{n2}+${2:b}_{n2} & \\cdots & ${1:a}_{nn}+${2:b}_{nn}
\\end{bmatrix}
endsnippet
snippet jacobi "jacobi" iAm
\\begin{bmatrix}\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_1}{\\partial ${2:x}_${3:n}}\\\\\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_2}{\\partial ${2:x}_${3:n}}\\\\\\vdots&\\vdots&\\ddots&\\vdots\\\\\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_1}&\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_2}&\\cdots&\\frac{\\partial ${1:f}_${3:m}}{\\partial ${2:x}_${3:n}}\\end{bmatrix}
endsnippet
# ==== Dynamic Matrix ====
priority 300
snippet `(b|p|v)mata([1-9])` "bmatrix" iiAm
\\begin{``rv = m[1]``matrix}``
let len = m[2];
let results = "";
for (var i=0; i<len; i++){
results += "$1 &".repeat(len-1) + " $1 \\\\\\\\";
}
rv = results;
``\\end{``rv = m[1]``matrix}$0
endsnippet
priority 300
snippet `(b|p|v)mat([1-9])` "bmatrix" iiAm
\\begin{``rv = m[1]``matrix}``
rv = gen_matrix(m[2],m[2]);
``\\end{``rv = m[1]``matrix}$0
endsnippet
priority 2000
snippet `(b|p|v)matr([1-9]{1})` "bmatrix" iiAm
\\begin{``rv = m[1]``matrix}``
rv = gen_matrix_transposed(m[2],m[2]);
``\\end{``rv = m[1]``matrix}$0
endsnippet
priority 300
snippet `vec([1-9])` "col vector" iiAm
\\begin{bmatrix}``
rv = gen_matrix(m[1], 1);
``\\end{bmatrix}$0
endsnippet
priority 300
snippet `vecr([1-9])` "row vector" iiAm
\\begin{bmatrix}``
rv = gen_matrix(1, m[1]);
``\\end{bmatrix}$0
endsnippet
# == General ==
snippet \box "Box"
``rv = '┌' + '─'.repeat(t[0].length + 2) + '┐'``
│ $1 │
``rv = '└' + '─'.repeat(t[0].length + 2) + '┘'``
endsnippet