├── README.md ├── for 0.2.4 └── markdown.hsnips └── for 0.2.7+ ├── latex.hsnips └── markdown.hsnips /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![5jfgfd](https://user-images.githubusercontent.com/80528249/148357887-7be814cd-0509-4144-8a9b-329f64b993c2.gif) 3 | 4 | # Hsnips-Snippets 5 | 6 | HyperSnips Snippets for markdown . 7 | 8 | -------------------------------------------------------------------------------- /for 0.2.4/markdown.hsnips: -------------------------------------------------------------------------------- 1 | global 2 | 3 | // vscode api 4 | 5 | const vscode = require("vscode"); 6 | var editor=vscode.window.activeTextEditor 7 | var document=editor.document 8 | let selectedText = ""; 9 | 10 | // selected text 11 | 12 | vscode.window.onDidChangeTextEditorSelection((e) => { 13 | const newSelectedText = e.textEditor.document.getText(e.selections[0]); 14 | if (newSelectedText) { 15 | selectedText = newSelectedText; 16 | } 17 | }); 18 | 19 | function VISUAL() { 20 | let sText=selectedText.replace(/\\\\/g,"\\\\\\ ").replace(/\}/g,"\\}"); 21 | selectedText=""; 22 | return sText; 23 | } 24 | 25 | // get ActiveTextEditor 26 | 27 | vscode.window.onDidChangeActiveTextEditor((e) => { 28 | editor=vscode.window.activeTextEditor; 29 | document=editor.document 30 | }); 31 | 32 | 33 | 34 | // transformation cycle 35 | 36 | function cycle(arr,str){ 37 | let count = 0 ; 38 | while (str!=arr[++count]&&count s.includes("math")); 46 | } 47 | 48 | function inline_math(context){ 49 | return context.scopes.some(s => s.includes("math.inline")); 50 | } 51 | 52 | function block_math(context){ 53 | return context.scopes.some(s => s.includes("math.block")) | context.scopes.some(s => s.includes("math.display")); 54 | } 55 | 56 | 57 | function isAlignedEnvironment(editor) { 58 | let text = editor.document.getText(new vscode.Range(new vscode.Position(0, 0), editor.selection.start)); 59 | const reg = /\\begin\{aligned\}[^\$]*?\\end\{aligned\}/g; 60 | text = text.replace(reg, ''); 61 | return (text.indexOf('\\begin{aligned}') == -1)?false:true; 62 | } 63 | 64 | // generate matrix 65 | 66 | function gen_matrix(nrow, ncol, index) { 67 | let results = "\n"; 68 | let order = 1; 69 | for (var i=0; i ★ 98 | context !math(context) 99 | snippet %% "big star" A 100 | $\color{red}\bigstar$ 101 | endsnippet 102 | 103 | 104 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 105 | # \\ transform \\ 106 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 107 | 108 | # use ";" to transform 109 | 110 | # \frac \dfrac 111 | 112 | context math(context) 113 | snippet `(\\(frac|dfrac)\{.*\}\{.*\});` "frac change" iA 114 | `` 115 | var str=m[1].replace(/\\frac/g,"Ⱆ").replace(/\\dfrac/g,"Ⱉ").split(''); 116 | 117 | var depth=0; 118 | var i=str.length-1; 119 | var test =0; 120 | 121 | while (i>=0) { 122 | if ( str[i] == '\}' ) depth ++; 123 | if ( str[i] == '\{' ) depth --; 124 | 125 | if ( test == 2 && !depth){ 126 | if ( str[i] == 'Ⱆ'){ str[i] = 'Ⱉ';break;} 127 | if ( str[i] == 'Ⱉ'){ str[i] = 'Ⱆ';break;} 128 | } 129 | test += depth ? 0 : 1; 130 | i--; 131 | } 132 | 133 | rv=str.join('').replace(/Ⱆ/g,"\\frac").replace(/Ⱉ/g,"\\dfrac"); 134 | `` 135 | endsnippet 136 | 137 | # -> => --> ==> -> ==> 138 | 139 | context math(context) 140 | snippet `(\\rightarrow|\\Rightarrow|\\longrightarrow|\\Longrightarrow|\\to|\\implies)(| );` "change ->" Ai 141 | `` 142 | let r=["\\rightarrow","\\Rightarrow","\\longrightarrow","\\Longrightarrow","\\to","\\implies"]; 143 | rv=cycle(r,m[1])+m[2]; 144 | `` 145 | endsnippet 146 | 147 | # <= <= <-- <== <== 148 | 149 | context math(context) 150 | snippet `(\\leftarrow|\\Leftarrow|\\longleftarrow|\\Longleftarrow|\\impliedby)(| );` "change <-" Ai 151 | `` 152 | let r=["\\leftarrow","\\Leftarrow","\\longleftarrow","\\Longleftarrow","\\impliedby"]; 153 | rv=cycle(r,m[1])+m[2]; 154 | `` 155 | endsnippet 156 | 157 | context math(context) 158 | snippet `(\\leftrightarrow|\\Leftrightarrow|\\longleftrightarrow|\\Longleftrightarrow|\\iff)(| );` "<=>" iA 159 | `` 160 | let r=["\\leftrightarrow","\\Leftrightarrow","\\longleftrightarrow","\\Longleftrightarrow","\\iff"]; 161 | rv=cycle(r,m[1])+m[2]; 162 | `` 163 | endsnippet 164 | 165 | 166 | # ≤ ≤ ≦ ﹤ 167 | 168 | context math(context) 169 | snippet `(\\le|\\leq|\\leqslant|<)(| );` "change <" Ai 170 | `` 171 | let r=["\\le","\\leq","\\leqslant","<"]; 172 | rv=cycle(r,m[1])+m[2]; 173 | `` 174 | endsnippet 175 | 176 | context math(context) 177 | snippet `(\\re|\\req|\\reqslant|>)(| );` "change <" Ai 178 | `` 179 | let r=["\\le","\\leq","\\leqslant","<"]; 180 | rv=cycle(r,m[1])+m[2]; 181 | `` 182 | endsnippet 183 | 184 | # dots 185 | 186 | context math(context) 187 | snippet `\\(c|v|l|d)dots( |);` "dots" iA 188 | \\`` 189 | let r=["c","v","l","d"]; 190 | rv=cycle(r,m[1]); 191 | ``dots``rv=m[2]`` 192 | endsnippet 193 | 194 | # var greek 195 | 196 | context math(context) 197 | snippet `(\\|\\var)(epsilon|theta|phi|pi|sigma|kappa)(| );` "greek change" iA 198 | ``let r=["\\","\\var"]; 199 | rv=cycle(r,m[1])+m[2]+m[3];`` 200 | endsnippet 201 | 202 | # = <-> ≡ 203 | 204 | context math(context) 205 | snippet `(=|\\equiv|\\approx)(| );` "=" iA 206 | ``let r=["=","\\equiv","\\approx"]; 207 | rv=cycle(r,m[1])+m[2]`` 208 | endsnippet 209 | 210 | 211 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 212 | # \\ environment \\ 213 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 214 | 215 | # align 216 | 217 | # aligned environment with VISUAL 218 | priority 300 219 | context math(context) 220 | snippet `Aln` "align" iA 221 | \begin{aligned} 222 | ``rv = VISUAL();``$0 223 | \end{aligned} 224 | endsnippet 225 | 226 | # replace content of current line 227 | priority 200 228 | context math(context) 229 | snippet `aln` "Align" iA 230 | \begin{aligned} 231 | `` 232 | let pos = editor.selection.active; 233 | let range = new vscode.Range(pos.line,0,pos.line,pos.character-2) //delete snippet "Aln" 234 | let text = document.getText(range); 235 | vscode.window.activeTextEditor.edit(editBuilder => { 236 | editBuilder.delete(document.lineAt(pos).range); 237 | }); 238 | rv=text.replace("=","&="); 239 | `` $0 240 | \end{aligned} 241 | endsnippet 242 | 243 | 244 | # for `aligned` 245 | 246 | context isAlignedEnvironment(editor) 247 | snippet `==` "&=" iA 248 | &= 249 | endsnippet 250 | 251 | 252 | context isAlignedEnvironment(editor) 253 | snippet ++ "&=" iA 254 | &+ 255 | endsnippet 256 | 257 | context isAlignedEnvironment(editor) 258 | snippet `&==` "&=&" iA 259 | &=& 260 | endsnippet 261 | 262 | # case/rcase 263 | 264 | context math(context) 265 | snippet `(? 279 | # \begin{bmatrix} 280 | # | & | \\ 281 | # | & | \\ 282 | # \end{bmatrix} 283 | 284 | priority 2000 285 | context block_math(context) 286 | snippet `(bm|pm|m|vm)at([1-9])([1-9])` "matrix" iA 287 | \begin{``rv = m[1]``atrix}`` 288 | rv = gen_matrix(m[2],m[3],1); 289 | ``\end{``rv = m[1]``atrix}$0 290 | endsnippet 291 | 292 | priority 2000000 293 | context block_math(context) 294 | snippet `rv([1-9])` "row vector" iA 295 | \begin{bmatrix}`` 296 | rv=gen_matrix(1,m[1],1); 297 | ``\end{bmatrix} 298 | endsnippet 299 | 300 | priority 2000000 301 | context block_math(context) 302 | snippet `cv([1-9])` "row vector" iA 303 | \begin{bmatrix}`` 304 | rv=gen_matrix(m[1],1,1); 305 | ``\end{bmatrix} 306 | endsnippet 307 | 308 | # inline matrices 309 | 310 | priority 3000 311 | context inline_math(context) 312 | snippet `(bm|pm|m|vm)at([1-9])([1-9])` "matrix" iA 313 | \begin{``rv = m[1]``atrix}`` 314 | rv = gen_matrix(m[2],m[3],0); 315 | `` \end{``rv = m[1]``atrix}$0 316 | endsnippet 317 | 318 | priority 3000000 319 | context inline_math(context) 320 | snippet `rv([1-9])` "row vector" iA 321 | \begin{bmatrix}`` 322 | rv=gen_matrix(1,m[1],0); 323 | `` \end{bmatrix} 324 | endsnippet 325 | 326 | priority 3000000 327 | context inline_math(context) 328 | snippet `cv([1-9])` "row vector" iA 329 | \begin{bmatrix}`` 330 | rv=gen_matrix(m[1],1,0); 331 | `` \end{bmatrix} 332 | endsnippet 333 | 334 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 335 | # \\ dots \\ 336 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 337 | 338 | context math(context) 339 | snippet ... "cdots" iA 340 | \cdots 341 | endsnippet 342 | 343 | context math(context) 344 | snippet ,,, "vdots" iA 345 | \vdots 346 | endsnippet 347 | 348 | context math(context) 349 | snippet ::: "ddots" iA 350 | \ddots 351 | endsnippet 352 | 353 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 354 | # \\ script text \\ 355 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 356 | 357 | # _{} 358 | context math(context) 359 | snippet `(?\frac{1}{} 428 | 429 | priority 10 430 | context math(context) 431 | snippet `((\d+)|(\d*)(\\)?([A-Za-z]+)((\^|_)(\{\d+\}|\d))*|\\(mu|alpha|sigma|varsigma|rho|beta|gamma|delta|zeta|eta|epsilon|varepsilon|theta|iota|kappa|vartheta|lambda|nu|pi|varpi|rho|tau|upsilon|phi|varphi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|xi|Pi|sigma|varsigma|Upsilon|Phi|Psi|Omega)[ |])/` "Fraction no ()" A 432 | \frac{``rv = m[1]``}{$1}$0 433 | endsnippet 434 | 435 | context math(context) 436 | snippet `^.*\)/` "Fraction with ()" A 437 | `` 438 | let str = m[0]; 439 | str = str.slice(0, -1); 440 | let lastIndex = str.length - 1; 441 | 442 | let depth = 0; 443 | let i = str.length - 1; 444 | 445 | while (true) { 446 | if (str[i] == ')') depth += 1; 447 | if (str[i] == '(') depth -= 1; 448 | if (depth == 0) break; 449 | i -= 1; 450 | } 451 | 452 | let results = str.slice(0, i) + "\\frac{" + str.slice(i+1, -1) + "}"; 453 | results += "{$1}$0"; 454 | rv = results; 455 | `` 456 | endsnippet 457 | 458 | # //->\frac{}{} 459 | 460 | priority 10 461 | context math(context) 462 | snippet // "Fraction" iA 463 | \\frac{$1}{$2}$0 464 | endsnippet 465 | 466 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 467 | # \\\\ sign \\\\\ 468 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 469 | 470 | ## integrate signs ∫ ## 471 | 472 | # ∫ 473 | priority 1 474 | context math(context) 475 | snippet `(?<=[^s])(? ∫ a 516 | context math(context) 517 | snippet `(?<=(\\int|\\lim|\\sum))([a-ce-zA-CE-Z])` "space after int" iA 518 | ``rv=m[2]`` 519 | endsnippet 520 | 521 | 522 | ## infinity ∞ ## 523 | 524 | context math(context) 525 | snippet `oo` "infinity" iA 526 | \infty 527 | endsnippet 528 | 529 | context math(context) 530 | snippet `\\inftyp` "+infty" iA 531 | +\infty 532 | endsnippet 533 | 534 | context math(context) 535 | snippet `\\inftym` "-infty" iA 536 | -\infty 537 | endsnippet 538 | 539 | ## d/dt 540 | 541 | context math(context) 542 | snippet `DD` "diffraction" iA 543 | \frac{\mathrm{d}$1}{\mathrm{d}$2} 544 | endsnippet 545 | 546 | context math(context) 547 | snippet `PP` "diffraction" iA 548 | \frac{\partial $1}{\partial $2} 549 | endsnippet 550 | 551 | ## Fourier Trans 1/(√2π) ∫ 552 | 553 | context math(context) 554 | snippet \frt "fourier trans" iA 555 | \frac{1}{sqrt{2\pi}}\int_{-\infty}^{+\infty} 556 | endsnippet 557 | 558 | ## function and operator ## 559 | context math(context) 560 | snippet `(? ## 616 | 617 | context math(context) 618 | snippet `avg` "average" iA 619 | \left< $1 \right> $0 620 | endsnippet 621 | 622 | context math(context) 623 | snippet `[bB]ra` "Dirac bra" iA 624 | \langle $1|$0 625 | endsnippet 626 | 627 | context math(context) 628 | snippet `(?<=(\||\| ))ket` "dirac ket" iA 629 | $1\rangle$0 630 | endsnippet 631 | 632 | context math(context) 633 | snippet `(?" iA 682 | \rightarrow 683 | endsnippet 684 | 685 | context math(context) 686 | snippet `GG` "==>" iA 687 | \Longrightarrow 688 | endsnippet 689 | 690 | priority 10 691 | context math(context) 692 | snippet `@@` "at" iA 693 | \big| _{$1}^{$2}$0 694 | endsnippet 695 | 696 | priority 20 697 | context math(context) 698 | snippet `#@` "at2" iA 699 | \left. $1 \right|_{$2}$0 700 | endsnippet 701 | 702 | context math(context) 703 | snippet `NN` "cap" iA 704 | \cap 705 | endsnippet 706 | 707 | context math(context) 708 | snippet `UU` "cup" iA 709 | \cup 710 | endsnippet 711 | 712 | context math(context) 713 | snippet `II` "in" iA 714 | \in 715 | endsnippet 716 | 717 | priority 20 718 | context math(context) 719 | snippet `XX` "times" iA 720 | \times 721 | endsnippet 722 | 723 | context math(context) 724 | snippet `oxo` "otimes" iA 725 | \otimes 726 | endsnippet 727 | 728 | context math(context) 729 | snippet `opo` "oplus" iA 730 | \oplus 731 | endsnippet 732 | 733 | context math(context) 734 | snippet `oco` "oplus" iA 735 | \propto 736 | endsnippet 737 | 738 | # ▽ 739 | context math(context) 740 | snippet `(\\|)(nbl)` "nabla" iA 741 | \nabla 742 | endsnippet 743 | 744 | context math(context) 745 | snippet `(? & =>" iA 984 | \``rv=m[2]``ightarrow 985 | endsnippet 986 | 987 | priority 10 988 | context math(context) 989 | snippet `(|\\)(l|L)arr` "-> & =>" iA 990 | \``rv=m[2]``eftarrow 991 | endsnippet 992 | 993 | priority 10 994 | context math(context) 995 | snippet `(|\\)(u|U)arr` "-> & =>" iA 996 | \``rv=m[2]``parrow 997 | endsnippet 998 | 999 | priority 10 1000 | context math(context) 1001 | snippet `(|\\)(d|D)arr` "-> & =>" iA 1002 | \``rv=m[2]``ownarrow 1003 | endsnippet 1004 | 1005 | priority 20 1006 | context math(context) 1007 | snippet `(r|R)rarr` "-->" iA 1008 | \``rv=m[1]=="r"?"l":"L"``ongrightarrow 1009 | endsnippet 1010 | 1011 | priority 20 1012 | context math(context) 1013 | snippet `llarr` "<--" iA 1014 | \longleftarrow 1015 | endsnippet 1016 | 1017 | priority 30 1018 | context math(context) 1019 | snippet `lrarr` "<->" iA 1020 | \leftrightarrow 1021 | endsnippet 1022 | 1023 | priority 30 1024 | context math(context) 1025 | snippet `udarr` "<->" iA 1026 | \updownarrow 1027 | endsnippet 1028 | 1029 | context math(context) 1030 | snippet `FF` "<>" iA 1031 | \Leftrightarrow 1032 | endsnippet 1033 | 1034 | context math(context) 1035 | snippet `<>` "<>" iA 1036 | \Longleftrightarrow 1037 | endsnippet 1038 | 1039 | priority 10 1040 | context math(context) 1041 | snippet `>=` ">=" iA 1042 | \geq 1043 | endsnippet 1044 | 1045 | priority 10 1046 | context math(context) 1047 | snippet `<=` "<=" iA 1048 | \leq 1049 | endsnippet 1050 | 1051 | context math(context) 1052 | snippet `<<` "<<" iA 1053 | \ll 1054 | endsnippet 1055 | 1056 | context math(context) 1057 | snippet `>>` "<<" iA 1058 | \gg 1059 | endsnippet 1060 | 1061 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1062 | # \\ colors \\ 1063 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1064 | 1065 | context math(context) 1066 | snippet `\\(red|green|blue)` "useful color" iA 1067 | {\color{``rv=m[1]``}${1:``rv=VISUAL()``}}$0 1068 | endsnippet 1069 | -------------------------------------------------------------------------------- /for 0.2.7+/latex.hsnips: -------------------------------------------------------------------------------- 1 | ########################################## 2 | # # 3 | # HyperSnips snippets for LaTeX # 4 | # # 5 | # 2022/01/06 @yf-zhao # 6 | # # 7 | # For Hypersnips 0.2.7+ # 8 | # # 9 | # # 10 | ########################################## 11 | 12 | #### Index #### 13 | 14 | # 0 Global Function 15 | # 1 Special snippets 16 | # 2 17 | # 3 Math Notation 18 | # 4 Greek letter 19 | # 5 Matrices 20 | # 6 Fraction 21 | # 7 Superscript & subscript 22 | # 8 prefix Mode 23 | # 9 Unit Mode 24 | # 10 Other Environment 25 | # 11 Transform similar notations 26 | # 12 for Special Courses 27 | # 13 Other notations & commands 28 | # 14 lint 29 | # 15 Temp 30 | # 16 Trash 31 | 32 | 33 | 34 | #### Global JavaScript Function #### 35 | 36 | global 37 | 38 | // vscode api (necessary) 39 | 40 | const vscode = require("vscode"); 41 | let editor=vscode.window.activeTextEditor 42 | let document=editor.document 43 | 44 | 45 | // get ActiveTextEditor 46 | 47 | vscode.window.onDidChangeActiveTextEditor((e) => { 48 | editor=vscode.window.activeTextEditor; 49 | document=editor.document 50 | }); 51 | 52 | // show time in StatusBar 53 | 54 | setInterval(function(){myTimer()},1000); 55 | function myTimer(){ 56 | vscode.window.setStatusBarMessage(new Date().toLocaleTimeString()); 57 | } 58 | 59 | // selected text : use ``rv=visual();`` to get selected text 60 | 61 | let selectedText = ""; 62 | 63 | vscode.window.onDidChangeTextEditorSelection((e) => { 64 | const newSelectedText = e.textEditor.document.getText(e.selections[0]); 65 | if (newSelectedText) { 66 | selectedText = newSelectedText.replace(/\\/g,"\\\\"); 67 | } 68 | }); 69 | 70 | function visual(){ 71 | const visualText = selectedText; 72 | selectedText = ""; 73 | return visualText; 74 | } 75 | 76 | // generate matrix : use ``rv = gen_matrix(snip, "p" , 2 , 3 , 1)`` to get a 2*3 display pmatrix 77 | // snip : snip varible 78 | // flag : string. 'p', 'b' , 'B' , 'v' , 'V' ,'' . default value = '' 79 | // nrow : int. row of matrix 80 | // ncol : int. column of matrix 81 | // index: int. '\n' or '' for last char of line. 1:'\n' ; 0: ''. 82 | 83 | function gen_matrix(snip,flag, nrow, ncol, index) { 84 | addPackage('amsmath') 85 | let results = "\\\\begin{"+`${flag?flag:''}`+"matrix}"; 86 | let order = 1; 87 | let lf = index ? "\n" : ""; 88 | for (let i=0; i { 114 | if (result === '是') { 115 | vscode.window.activeTextEditor.edit(editBuilder => { 116 | if (editor.document.getText(range).indexOf(package) === -1) 117 | editBuilder.insert(new vscode.Position(1, 0), `\\usepackage{${package}}\n`); 118 | }); 119 | } 120 | }); 121 | } 122 | } 123 | 124 | // Context definition 125 | 126 | // math 127 | 128 | function math(context) { 129 | return context.scopes.some(s => s.includes("math")); 130 | } 131 | 132 | // inline & block math 133 | 134 | function inline_math(context){ 135 | return context.scopes.some(s => s.includes("math")) && !context.scopes.some(s => s.includes("math.block.environment")); 136 | } 137 | 138 | function block_math(context){ 139 | return context.scopes.some(s => s.includes("math.block.environment")) ; 140 | } 141 | 142 | // {aligned} environment 143 | 144 | function isAlignedEnvironment(editor) { 145 | let text = editor.document.getText(new vscode.Range(new vscode.Position(0, 0), editor.selection.start)); 146 | const reg = /\\begin\{aligned\}[^\$]*?\\end\{aligned\}/g; 147 | text = text.replace(reg, ''); 148 | return (text.indexOf('\\begin{aligned}') == -1)?false:true; 149 | } 150 | 151 | 152 | // Unit Environment 153 | 154 | function isUnitMode(editor) { 155 | let pos = editor.selection.active; 156 | const reg = /\\mathrm\{\\,[^\$]*?\}/g; 157 | let text = editor.document.getText(new vscode.Range(pos.line,0,pos.line,pos.character)).replace(reg, ''); 158 | return (text.indexOf('\\mathrm{\\,') != -1) 159 | } 160 | 161 | // Dic 162 | 163 | // Greek Letter 164 | 165 | const greek = { 166 | "a" : "\\alpha", 167 | "b" : "\\beta", 168 | "c" : "\\chi", 169 | "d" : "\\delta", 170 | "e" : "\\epsilon", 171 | "ve": "\\varepsilon", 172 | "f" : "\\phi", 173 | "vf" : "\\varphi", 174 | "g" : "\\gamma", 175 | "h" : "\\eta", 176 | "i" : "\\iota", 177 | "j" : "\\varphi", 178 | "k" : "\\kappa", 179 | "vk": "\\varkappa", 180 | "l" : "\\lambda", 181 | "m" : "\\mu", 182 | "n" : "\\nu", 183 | "o" : "\\omicron", 184 | "p" : "\\pi", 185 | "vp" : "\\varpi", 186 | "q" : "\\theta", 187 | "vq" : "\\vartheta", 188 | "r" : "\\rho", 189 | "s" : "\\sigma", 190 | "vs" : "\\varsigma", 191 | "t" : "\\tau", 192 | "u" : "\\upsilon", 193 | "v" : "\\varpi", 194 | "w" : "\\omega", 195 | "x" : "\\xi", 196 | "y" : "\\psi", 197 | "z" : "\\zeta", 198 | "A" : "\\Alpha", 199 | "B" : "\\Beta", 200 | "C" : "\\Chi", 201 | "D" : "\\Delta", 202 | "E" : "\\Epsilon", 203 | "F" : "\\Phi", 204 | "G" : "\\Gamma", 205 | "H" : "\\Eta", 206 | "I" : "\\Iota", 207 | "K" : "\\Kappa", 208 | "L" : "\\Lambda", 209 | "M" : "\\Mu", 210 | "N" : "\\Nu", 211 | "O" : "\\Omicron", 212 | "P" : "\\Pi", 213 | "Q" : "\\Theta", 214 | "R" : "\\Rho", 215 | "S" : "\\Sigma", 216 | "T" : "\\Tau", 217 | "U" : "\\Upsilon", 218 | "W" : "\\Omega", 219 | "X" : "\\Xi", 220 | "Y" : "\\Psi", 221 | "Z" : "\\Zeta" 222 | }; 223 | 224 | // prefix 225 | 226 | const prefix = { 227 | "bar" : ["\\\\overline{" ,"}" ], 228 | "fn" : ["\\\\overset{\\\\frown}{" ,"}" ], 229 | "td" : ["\\\\widetilde{" ,"}" ], 230 | "rm" : ["\\\\mathrm{" ,"}" ], 231 | "hat" : ["\\\\hat{" ,"}" ], 232 | "cr" : ["\\\\mathscr{" ,"}" ], 233 | "bav" : ["\\\\hat{\\\\boldsymbol{" ,"}}" ], 234 | "vec" : ["\\\\vec{" ,"}" ], 235 | "bm" : ["\\\\boldsymbol{" ,"}" ], 236 | "bf" : ["\\\\mathbf{" ,"}" ], 237 | "cal" : ["\\\\mathcal{" ,"}" ], 238 | "dot" : ["\\\\dot{" ,"}" ], 239 | "vdot" : ["\\\\dot{\\\\boldsymbol{" ,"}}" ] 240 | } 241 | 242 | // block 243 | 244 | 245 | const block = { 246 | "tm" : ["Thm" ,"brown" ,"▶",0], 247 | "tt" : ["Thm" ,"brown" ,"▶",1], 248 | "ex" : ["Ex" ,"teal" ,"▶",0], 249 | "pf" : ["Pf" ,"green" ,"▶",0], 250 | "pb" : ["Problem" ,"teal" ,"▶",0], 251 | "sn" : ["Sol" ,"green" ,"▶",0], 252 | "df" : ["Def" ,"purple" ,"▶",0], 253 | "dd" : ["Def" ,"purple" ,"▶",1], 254 | "st" : ["Step" ,"orange" ,"▶",0], 255 | "md" : ["Method" ,"brown" ,"■",0], 256 | "cc" : ["Case" ,"brown" ,"●",0], 257 | "ds" : ["Discussion" ,"brown" ,"■",0], 258 | } 259 | 260 | const arrow = { 261 | 'r' : 'right', 262 | 'R' : 'Right', 263 | 'l' : 'left', 264 | 'L' : 'Left', 265 | 'lr':'leftright', 266 | 'Lr':'Leftright', 267 | 'u' : 'up', 268 | 'U' : 'Up', 269 | 'd' : 'down', 270 | 'D': 'Down', 271 | 'ud':'updown', 272 | 'Ud':'Updown', 273 | 'rr': 'longright', 274 | 'll': 'longleft', 275 | 'RR': 'Longright', 276 | 'LL': 'Longleft', 277 | 'se': 'se', 278 | 'sw': 'sw', 279 | 'ne': 'ne', 280 | 'nw': 'nw' 281 | } 282 | 283 | ///////////////////// trash //////////////////// 284 | 285 | 286 | // autoclosing environment 287 | 288 | function autoclosing(){ 289 | let pos=editor.selection.active; 290 | let text = document.getText(document.lineAt(pos).range).charAt(pos.character+1); 291 | let reg=/[;:.,=\}\]\)>\\` \n\t\$*\|\\]/g; 292 | return reg.test(text) || text=="" 293 | } 294 | 295 | endglobal 296 | 297 | 298 | 299 | 300 | ########################################################## 301 | # Test # 302 | ########################################################## 303 | ################### Only for Test !!! #################### 304 | 305 | ########################################################## 306 | # special snippets # 307 | ########################################################## 308 | 309 | # protect "oiint" "iiint" "asccos" "mathtt" "mathbb" 310 | priority 99999999 311 | context math(context) 312 | snippet `(?<=(oii|iii|ascc|mathtt|mathbb|hetan))` "prevent" iA 313 | 314 | endsnippet 315 | 316 | # \displaystyle in `inline-math` 317 | 318 | context inline_math(context) 319 | snippet `\$([^\$]*)DS` "Displaystyle" iA 320 | ``rv=`$\\\\displaystyle${m[1]? " "+m[1] : ""}``` 321 | endsnippet 322 | 323 | 324 | 325 | 326 | ########################################################## 327 | # Math Notation # 328 | ########################################################## 329 | 330 | #### dots 331 | # 332 | # ... ⇨ \cdots 333 | # ,,, ⇨ \vdots 334 | # ... ⇨ \ddots 335 | 336 | context math(context) 337 | snippet `\.\.\.` "cdots" iA 338 | ``rv='\\cdots '`` 339 | endsnippet 340 | 341 | context math(context) 342 | snippet `,,,` "vdots" iA 343 | ``rv='\\vdots '`` 344 | endsnippet 345 | 346 | context math(context) 347 | snippet `:::` "ddots" iA 348 | ``rv='\\ddots '`` 349 | endsnippet 350 | 351 | #### integral & Big Operators 352 | # 353 | # int ⇨ \int ║ ∫ 354 | # iint ⇨ \iint ║ ∫∫ 355 | # iiint ⇨ \iiint ║ ∫∫∫ 356 | # oint ⇨ \oint ║ ∮ 357 | # oiint ⇨ \oiint ║ ∯ 358 | 359 | priority 10 360 | context math(context) 361 | snippet `(?<=[^s])(?= ⇨ \geq 504 | # << ⇨ \ll 505 | # >> ⇨ \gg 506 | # >~ ⇨ \lesssim 507 | # <~ ⇨ \gtrsim 508 | 509 | context math(context) 510 | snippet `>=` "≥" iA 511 | ``rv='\\geq '`` 512 | endsnippet 513 | 514 | context math(context) 515 | snippet `<=` "≤" iA 516 | ``rv='\\leq '`` 517 | endsnippet 518 | 519 | context math(context) 520 | snippet `<<` "≪" iA 521 | ``rv='\\ll '`` 522 | endsnippet 523 | 524 | context math(context) 525 | snippet `>>` "≫" iA 526 | ``rv='\\gg '`` 527 | endsnippet 528 | 529 | context math(context) 530 | snippet `<~` "≲" iA 531 | ``rv='\\lesssim '`` 532 | endsnippet 533 | 534 | context math(context) 535 | snippet `>~` "≳" iA 536 | ``rv='\\gtrsim '`` 537 | endsnippet 538 | 539 | #### Square 540 | # 541 | # sq ⇨ \sqrt{▮} 542 | 543 | context math(context) 544 | snippet `(?=0) { 1180 | depth += ( str[i] == '\}' ) ; 1181 | depth -= ( str[i] == '\{' ) ; 1182 | 1183 | if ( test == 2 && !depth){ 1184 | if ( str[i] == 'Ⱆ'){ str[i] = 'Ⱉ';break;} 1185 | if ( str[i] == 'Ⱉ'){ str[i] = 'Ⱆ';break;} 1186 | } 1187 | test += !!!depth; 1188 | i--; 1189 | } 1190 | 1191 | rv= (i==-1)?m[1]:str.join('').replace(/Ⱆ/g,"\\\\frac").replace(/Ⱉ/g,"\\\\dfrac"); 1192 | `` 1193 | endsnippet 1194 | 1195 | #### bracket 1196 | # 1197 | # () ⇔ \left(\right) (trigger : `;`) 1198 | # [] ⇔ \left[\right] (trigger : `;`) 1199 | # () ⇔ [] (trigger : `:`) 1200 | 1201 | context math(context) 1202 | snippet `([^\$]*(\)|\])):` "()⇔[]*" iA 1203 | `` 1204 | var str=m[1]; 1205 | var bra = ["(","["]; 1206 | var ket = [")","]"]; 1207 | 1208 | var testIndex = (m[2]=="]"); 1209 | 1210 | var i=str.length-1; 1211 | str=str.split(''); 1212 | 1213 | str[i] = ket[+!testIndex]; 1214 | var depth = 1; 1215 | while (i>=0) { 1216 | depth += (str[i] == ket[+testIndex] ) ; 1217 | depth -= (str[i] == bra[+testIndex]) ; 1218 | 1219 | if(!depth){ 1220 | str[i]=bra[+!testIndex]; 1221 | break; 1222 | } 1223 | i--; 1224 | } 1225 | rv=str.join(''); 1226 | 1227 | `` 1228 | endsnippet 1229 | 1230 | 1231 | context math(context) 1232 | snippet `([^\$]*(\)|\\right\)|\]|\\right\]|\\\}|\\right\\\}));` "()⇔\left(\right)" iA 1233 | `` 1234 | var str=m[1]; 1235 | 1236 | switch(m[2]){ 1237 | case ")" || "\\right)": 1238 | var bracket=["\\left(","\\right)","(",")"]; 1239 | var testBracket = [/\\left\(/g,/\\right\)/g,/\(/g,/\)/g]; 1240 | break; 1241 | case "]" || "\\right]": 1242 | var bracket=["\\left[","\\right]","[","]"]; 1243 | var testBracket = [/\\left\[/g,/\\right\]/g,/\[/g,/\]/g]; 1244 | break; 1245 | case "\\\}" || "\\right\\\}": 1246 | var bracket=["\\left\\\{","\\right\\\\\}","\\\{","\\\\\}"]; 1247 | var testBracket = [/\\left\\\{/g,/\\right\\\}/g,/\\\{/g,/\\\}/g]; 1248 | break; 1249 | default: 1250 | break; 1251 | } 1252 | var rep=["ᑡ","ᑑ","ᐹ","ᐴ"]; 1253 | 1254 | var i=0; 1255 | while (i=0) { 1265 | depth += (str[i] == 'ᑑ' || str[i] =='ᐴ' ) ; 1266 | depth -= (str[i] == 'ᐹ' || str[i] =='ᑡ') ; 1267 | 1268 | if(!depth){ 1269 | var test =str[i] 1270 | str[i] =( test=='ᐹ' ? 'ᑡ': 'ᐹ') 1271 | break; 1272 | } 1273 | i--; 1274 | } 1275 | 1276 | str=str.join(''); 1277 | i=rep.length; 1278 | while (--i>=0) str=str.replace(new RegExp(rep[i],'g'),bracket[i]); 1279 | rv=str; 1280 | `` 1281 | endsnippet 1282 | 1283 | # \dot{} ⇔ \ddot{} 1284 | 1285 | # 1286 | 1287 | 1288 | 1289 | 1290 | 1291 | 1292 | ######################################################### 1293 | # for Specific Courses # 1294 | ######################################################### 1295 | 1296 | #### Thermodynamics 1297 | # 1298 | # HH ⇨ \left(\frac{\partial ▮}{\partial ▮}\right)_{▮} 1299 | # ║ (∂▮/∂▮)▄ 1300 | # cvv ⇨ c_V 1301 | # cvm ⇨ c_{Vm} 1302 | # cpv ⇨ c_{pm} 1303 | 1304 | context math(context) 1305 | snippet `HH` "diffraction" iA 1306 | \\left(\\frac{\\partial $1}{\\partial $2}\\right)_{$3}$0 1307 | endsnippet 1308 | 1309 | priority 100000 1310 | context math(context) 1311 | snippet `cvv` "for c_v" iA 1312 | c_V 1313 | endsnippet 1314 | 1315 | priority 100000 1316 | context math(context) 1317 | snippet `cvm` "for c_{Vm}" iA 1318 | c_{Vm} 1319 | endsnippet 1320 | 1321 | priority 100000 1322 | context math(context) 1323 | snippet `cpm` "for c_{Vm}" iA 1324 | c_{pm} 1325 | endsnippet 1326 | 1327 | #### Quantum Mechanics 1328 | # 1329 | # hbar ⇨ \hbar ║ ℏ ║ `priority 200` for ×⇨ \overline{h} 1330 | # avg ⇨ \left< ▮ \right> ║ <▮> 1331 | # bra ⇨ \langle ▮| ║ <▮| 1332 | # ket ⇨ |▮\rangle ║ |▮> 1333 | # |ket ⇨ ▮ \rangle ║ ▮> 1334 | # frt ⇨ \frac{1}{sqrt{2\pi}}\int_{-\infty}^{+\infty} 1335 | # ║ 1/√(2π) ∫_∞^∞ 1336 | 1337 | 1338 | priority 200 1339 | context math(context) 1340 | snippet `hbar` "hbar" iA 1341 | \\hbar 1342 | endsnippet 1343 | 1344 | context math(context) 1345 | snippet `avg` "average" iA 1346 | \\left< $1 \\right>$0 1347 | endsnippet 1348 | 1349 | context math(context) 1350 | snippet `[bB]ra` "Dirac bra" iA 1351 | \\langle $1|$0 1352 | endsnippet 1353 | 1354 | context math(context) 1355 | snippet `(?<=\|[ ]?)ket` "dirac ket" iA 1356 | $1\\rangle$0 1357 | endsnippet 1358 | 1359 | context math(context) 1360 | snippet `(?=0) { 1434 | i--; 1435 | if (text[i] == '}'|| text[i] == ')' || text[i] ==']' ) depth++; 1436 | if (text[i] == '{'|| text[i] == '(' || text[i] =='[' ) depth--; 1437 | if ((text[i] == '+'|| text[i] == '=' || text[i] == '-' || text[i]=='&'|| text[i]==',')&& depth==0 || depth <0) break; 1438 | } 1439 | 1440 | rv=`${text.slice(0,i+1)}\\\\left.${text.slice(i+1,text.length)}\\\\right|_{${snip.tabstop(1)}}^{${snip.tabstop(2)}}` 1441 | 1442 | `` 1443 | endsnippet 1444 | 1445 | #### color 1446 | 1447 | # \red· --> {\color{red}▮} 1448 | # \red; --> {\color{red}${visual}} 1449 | 1450 | context math(context) 1451 | snippet `\\(red|green|blue) ` "useful color" iA 1452 | {\\color{``rv=m[1]``}$1} 1453 | endsnippet 1454 | 1455 | context math(context) 1456 | snippet `\\(red|green|blue);` "useful color" iA 1457 | {\\color{``rv=m[1]``}``rv=visual()``} 1458 | endsnippet 1459 | 1460 | 1461 | ######################################################## 1462 | # lint # 1463 | ######################################################## 1464 | 1465 | #### 1466 | # 1467 | # {} ⇨ ' ' 1468 | # +! ⇨ +1 1469 | # +@ ⇨ +2 1470 | # 、、⇨ \\ 1471 | # 》 ⇨ > 1472 | 1473 | context math(context) 1474 | snippet `(|_|\^)(? ') :m[0]`` 1496 | endsnippet 1497 | 1498 | ######################################################## 1499 | # Temp # 1500 | ######################################################## 1501 | 1502 | #### autoclose bracket 1503 | # 1504 | # ( ⇨ () 1505 | # [ ⇨ [] 1506 | # { ⇨ {} 1507 | # \{ ⇨ \{\} 1508 | 1509 | context autoclosing() 1510 | snippet `(? { 48 | editor=vscode.window.activeTextEditor; 49 | document=editor.document 50 | }); 51 | 52 | // show time in StatusBar 53 | 54 | setInterval(function(){myTimer()},1000); 55 | function myTimer(){ 56 | vscode.window.setStatusBarMessage(new Date().toLocaleTimeString()); 57 | } 58 | 59 | // selected text : use ``rv=visual();`` to get selected text 60 | 61 | let selectedText = ""; 62 | 63 | vscode.window.onDidChangeTextEditorSelection((e) => { 64 | const newSelectedText = e.textEditor.document.getText(e.selections[0]); 65 | if (newSelectedText) { 66 | selectedText = newSelectedText.replace(/\\/g,"\\\\"); 67 | } 68 | }); 69 | 70 | function visual(){ 71 | const visualText = selectedText; 72 | selectedText = ""; 73 | return visualText; 74 | } 75 | 76 | // generate matrix : use ``rv = gen_matrix(snip, "p" , 2 , 3 , 1)`` to get a 2*3 display pmatrix 77 | // snip : snip varible 78 | // flag : string. 'p', 'b' , 'B' , 'v' , 'V' ,'' . default value = '' 79 | // nrow : int. row of matrix 80 | // ncol : int. column of matrix 81 | // index: int. '\n' or '' for last char of line. 1:'\n' ; 0: ''. 82 | 83 | function gen_matrix(snip,flag, nrow, ncol, index) { 84 | let results = "\\\\begin{"+`${flag?flag:''}`+"matrix}"; 85 | let order = 1; 86 | let lf = index ? "\n" : ""; 87 | for (let i=0; i s.includes("math")); 114 | } 115 | 116 | // inline & block math 117 | 118 | function inline_math(context){ 119 | return context.scopes.some(s => s.includes("math.inline")); 120 | } 121 | 122 | function block_math(context){ 123 | return context.scopes.some(s => s.includes("math.block")) || context.scopes.some(s => s.includes("math.display")); 124 | } 125 | 126 | // {aligned} environment 127 | 128 | function isAlignedEnvironment(editor) { 129 | let text = editor.document.getText(new vscode.Range(new vscode.Position(0, 0), editor.selection.start)); 130 | const reg = /\\begin\{aligned\}[^\$]*?\\end\{aligned\}/g; 131 | text = text.replace(reg, ''); 132 | return (text.indexOf('\\begin{aligned}') == -1)?false:true; 133 | } 134 | 135 | 136 | // Unit Environment 137 | 138 | function isUnitMode(editor) { 139 | let pos = editor.selection.active; 140 | const reg = /\\mathrm\{\\,[^\$]*?\}/g; 141 | let text = editor.document.getText(new vscode.Range(pos.line,0,pos.line,pos.character)).replace(reg, ''); 142 | return (text.indexOf('\\mathrm{\\,') != -1) 143 | } 144 | 145 | // Dic 146 | 147 | // Greek Letter 148 | 149 | const greek = { 150 | "a" : "\\alpha", 151 | "b" : "\\beta", 152 | "c" : "\\chi", 153 | "d" : "\\delta", 154 | "e" : "\\epsilon", 155 | "ve": "\\varepsilon", 156 | "f" : "\\phi", 157 | "vf" : "\\varphi", 158 | "g" : "\\gamma", 159 | "h" : "\\eta", 160 | "i" : "\\iota", 161 | "j" : "\\varphi", 162 | "k" : "\\kappa", 163 | "vk": "\\varkappa", 164 | "l" : "\\lambda", 165 | "m" : "\\mu", 166 | "n" : "\\nu", 167 | "o" : "\\omicron", 168 | "p" : "\\pi", 169 | "vp" : "\\varpi", 170 | "q" : "\\theta", 171 | "vq" : "\\vartheta", 172 | "r" : "\\rho", 173 | "s" : "\\sigma", 174 | "vs" : "\\varsigma", 175 | "t" : "\\tau", 176 | "u" : "\\upsilon", 177 | "v" : "\\varpi", 178 | "w" : "\\omega", 179 | "x" : "\\xi", 180 | "y" : "\\psi", 181 | "z" : "\\zeta", 182 | "A" : "\\Alpha", 183 | "B" : "\\Beta", 184 | "C" : "\\Chi", 185 | "D" : "\\Delta", 186 | "E" : "\\Epsilon", 187 | "F" : "\\Phi", 188 | "G" : "\\Gamma", 189 | "H" : "\\Eta", 190 | "I" : "\\Iota", 191 | "K" : "\\Kappa", 192 | "L" : "\\Lambda", 193 | "M" : "\\Mu", 194 | "N" : "\\Nu", 195 | "O" : "\\Omicron", 196 | "P" : "\\Pi", 197 | "Q" : "\\Theta", 198 | "R" : "\\Rho", 199 | "S" : "\\Sigma", 200 | "T" : "\\Tau", 201 | "U" : "\\Upsilon", 202 | "W" : "\\Omega", 203 | "X" : "\\Xi", 204 | "Y" : "\\Psi", 205 | "Z" : "\\Zeta" 206 | }; 207 | 208 | // prefix 209 | 210 | const prefix = { 211 | "bar" : ["\\\\overline{" ,"}" ], 212 | "fn" : ["\\\\overset{\\\\frown}{" ,"}" ], 213 | "td" : ["\\\\widetilde{" ,"}" ], 214 | "rm" : ["\\\\mathrm{" ,"}" ], 215 | "hat" : ["\\\\hat{" ,"}" ], 216 | "cr" : ["\\\\mathscr{" ,"}" ], 217 | "bav" : ["\\\\hat{\\\\boldsymbol{" ,"}}" ], 218 | "vec" : ["\\\\vec{" ,"}" ], 219 | "bm" : ["\\\\boldsymbol{" ,"}" ], 220 | "bf" : ["\\\\mathbf{" ,"}" ], 221 | "cal" : ["\\\\mathcal{" ,"}" ], 222 | "dot" : ["\\\\dot{" ,"}" ], 223 | "vdot" : ["\\\\dot{\\\\boldsymbol{" ,"}}" ] 224 | } 225 | 226 | // block 227 | 228 | 229 | const block = { 230 | "tm" : ["Thm" ,"brown" ,"▶",0], 231 | "tt" : ["Thm" ,"brown" ,"▶",1], 232 | "ex" : ["Ex" ,"teal" ,"▶",0], 233 | "pf" : ["Pf" ,"green" ,"▶",0], 234 | "pb" : ["Problem" ,"teal" ,"▶",0], 235 | "sn" : ["Sol" ,"green" ,"▶",0], 236 | "df" : ["Def" ,"purple" ,"▶",0], 237 | "dd" : ["Def" ,"purple" ,"▶",1], 238 | "st" : ["Step" ,"orange" ,"▶",0], 239 | "md" : ["Method" ,"brown" ,"■",0], 240 | "cc" : ["Case" ,"brown" ,"●",0], 241 | "ds" : ["Discussion" ,"brown" ,"■",0], 242 | } 243 | 244 | const arrow = { 245 | 'r' : 'right', 246 | 'R' : 'Right', 247 | 'l' : 'left', 248 | 'L' : 'Left', 249 | 'lr':'leftright', 250 | 'Lr':'Leftright', 251 | 'u' : 'up', 252 | 'U' : 'Up', 253 | 'd' : 'down', 254 | 'D': 'Down', 255 | 'ud':'updown', 256 | 'Ud':'Updown', 257 | 'rr': 'longright', 258 | 'll': 'longleft', 259 | 'RR': 'Longright', 260 | 'LL': 'Longleft', 261 | 'se': 'se', 262 | 'sw': 'sw', 263 | 'ne': 'ne', 264 | 'nw': 'nw' 265 | } 266 | 267 | 268 | ///////////////////// trash //////////////////// 269 | 270 | // autoclosing environment 271 | 272 | function autoclosing(){ 273 | let pos=editor.selection.active; 274 | let text = document.getText(document.lineAt(pos).range).charAt(pos.character+1); 275 | let reg=/[;:.,=\}\]\)>\\` \n\t\$*\|\\]/g; 276 | return reg.test(text) || text=="" 277 | } 278 | 279 | endglobal 280 | 281 | 282 | 283 | 284 | ########################################################## 285 | # Test # 286 | ########################################################## 287 | ################### Only for Test !!! #################### 288 | 289 | ########################################################## 290 | # special snippets # 291 | ########################################################## 292 | 293 | # protect "oiint" "iiint" "asccos" "mathtt" "mathbb" 294 | priority 99999999 295 | context math(context) 296 | snippet `(?<=(oii|iii|ascc|mathtt|mathbb|hetan))` "prevent" iA 297 | 298 | endsnippet 299 | 300 | # \displaystyle in `inline-math` 301 | 302 | context inline_math(context) 303 | snippet `\$([^\$]*)DS` "Displaystyle" iA 304 | ``rv=`$\\\\displaystyle${m[1]? " "+m[1] : ""}``` 305 | endsnippet 306 | 307 | 308 | ########################################################## 309 | # block & environment (Theorem,etc.) # 310 | ########################################################## 311 | 312 | # vtm ⇨ (▶Thm.) 313 | # vdt ⇨
314 | # 315 | # use `block` dictionary 316 | 317 | context !math(context) 318 | snippet `v(tm|tt|ex|pf|pb|sn|df|dd|st|md|ds|cc)` "block & environment" iA 319 | `` 320 | let res = block[m[1]]; 321 | rv=`$\{\\\\color{${res[1]}}\\\\mathbf{${res[2]}\\\\ ${res[0]} .${snip.tabstop(1)}}}$ ${res[3]?`(**${snip.tabstop(2)}**) `:""}`; 322 | `` 323 | endsnippet 324 | 325 | 326 | context !math(context) 327 | snippet `vdt` "detail" wA 328 |
329 | 330 | 331 | $1 332 | 333 | 334 | 335 | $2 336 | 337 |
338 | $0 339 | endsnippet 340 | 341 | 342 | 343 | 344 | ########################################################## 345 | # Math Notation # 346 | ########################################################## 347 | 348 | #### dots 349 | # 350 | # ... ⇨ \cdots 351 | # ,,, ⇨ \vdots 352 | # ... ⇨ \ddots 353 | 354 | context math(context) 355 | snippet `\.\.\.` "cdots" iA 356 | ``rv='\\cdots '`` 357 | endsnippet 358 | 359 | context math(context) 360 | snippet `,,,` "vdots" iA 361 | ``rv='\\vdots '`` 362 | endsnippet 363 | 364 | context math(context) 365 | snippet `:::` "ddots" iA 366 | ``rv='\\ddots '`` 367 | endsnippet 368 | 369 | #### integral & Big Operators 370 | # 371 | # int ⇨ \int ║ ∫ 372 | # iint ⇨ \iint ║ ∫∫ 373 | # iiint ⇨ \iiint ║ ∫∫∫ 374 | # oint ⇨ \oint ║ ∮ 375 | # oiint ⇨ \oiint ║ ∯ 376 | 377 | priority 10 378 | context math(context) 379 | snippet `(?<=[^s])(?= ⇨ \geq 522 | # << ⇨ \ll 523 | # >> ⇨ \gg 524 | # >~ ⇨ \lesssim 525 | # <~ ⇨ \gtrsim 526 | 527 | context math(context) 528 | snippet `>=` "≥" iA 529 | ``rv='\\geq '`` 530 | endsnippet 531 | 532 | context math(context) 533 | snippet `<=` "≤" iA 534 | ``rv='\\leq '`` 535 | endsnippet 536 | 537 | context math(context) 538 | snippet `<<` "≪" iA 539 | ``rv='\\ll '`` 540 | endsnippet 541 | 542 | context math(context) 543 | snippet `>>` "≫" iA 544 | ``rv='\\gg '`` 545 | endsnippet 546 | 547 | context math(context) 548 | snippet `<~` "≲" iA 549 | ``rv='\\lesssim '`` 550 | endsnippet 551 | 552 | context math(context) 553 | snippet `>~` "≳" iA 554 | ``rv='\\gtrsim '`` 555 | endsnippet 556 | 557 | #### Square 558 | # 559 | # sq ⇨ \sqrt{▮} 560 | 561 | context math(context) 562 | snippet `(?=0) { 1306 | depth += ( str[i] == '\}' ) ; 1307 | depth -= ( str[i] == '\{' ) ; 1308 | 1309 | if ( test == 2 && !depth){ 1310 | if ( str[i] == 'Ⱆ'){ str[i] = 'Ⱉ';break;} 1311 | if ( str[i] == 'Ⱉ'){ str[i] = 'Ⱆ';break;} 1312 | } 1313 | test += !!!depth; 1314 | i--; 1315 | } 1316 | 1317 | rv= (i==-1)?m[1]:str.join('').replace(/Ⱆ/g,"\\\\frac").replace(/Ⱉ/g,"\\\\dfrac"); 1318 | `` 1319 | endsnippet 1320 | 1321 | #### bracket 1322 | # 1323 | # () ⇔ \left(\right) (trigger : `;`) 1324 | # [] ⇔ \left[\right] (trigger : `;`) 1325 | # () ⇔ [] (trigger : `:`) 1326 | 1327 | context math(context) 1328 | snippet `([^\$]*(\)|\])):` "()⇔[]*" iA 1329 | `` 1330 | var str=m[1]; 1331 | var bra = ["(","["]; 1332 | var ket = [")","]"]; 1333 | 1334 | var testIndex = (m[2]=="]"); 1335 | 1336 | var i=str.length-1; 1337 | str=str.split(''); 1338 | 1339 | str[i] = ket[+!testIndex]; 1340 | var depth = 1; 1341 | while (i>=0) { 1342 | depth += (str[i] == ket[+testIndex] ) ; 1343 | depth -= (str[i] == bra[+testIndex]) ; 1344 | 1345 | if(!depth){ 1346 | str[i]=bra[+!testIndex]; 1347 | break; 1348 | } 1349 | i--; 1350 | } 1351 | rv=str.join(''); 1352 | 1353 | `` 1354 | endsnippet 1355 | 1356 | 1357 | context math(context) 1358 | snippet `([^\$]*(\)|\\right\)|\]|\\right\]|\\\}|\\right\\\}));` "()⇔\left(\right)" iA 1359 | `` 1360 | var str=m[1]; 1361 | 1362 | switch(m[2]){ 1363 | case ")" || "\\right)": 1364 | var bracket=["\\left(","\\right)","(",")"]; 1365 | var testBracket = [/\\left\(/g,/\\right\)/g,/\(/g,/\)/g]; 1366 | break; 1367 | case "]" || "\\right]": 1368 | var bracket=["\\left[","\\right]","[","]"]; 1369 | var testBracket = [/\\left\[/g,/\\right\]/g,/\[/g,/\]/g]; 1370 | break; 1371 | case "\\\}" || "\\right\\\}": 1372 | var bracket=["\\left\\\{","\\right\\\\\}","\\\{","\\\\\}"]; 1373 | var testBracket = [/\\left\\\{/g,/\\right\\\}/g,/\\\{/g,/\\\}/g]; 1374 | break; 1375 | default: 1376 | break; 1377 | } 1378 | var rep=["ᑡ","ᑑ","ᐹ","ᐴ"]; 1379 | 1380 | var i=0; 1381 | while (i=0) { 1391 | depth += (str[i] == 'ᑑ' || str[i] =='ᐴ' ) ; 1392 | depth -= (str[i] == 'ᐹ' || str[i] =='ᑡ') ; 1393 | 1394 | if(!depth){ 1395 | var test =str[i] 1396 | str[i] =( test=='ᐹ' ? 'ᑡ': 'ᐹ') 1397 | break; 1398 | } 1399 | i--; 1400 | } 1401 | 1402 | str=str.join(''); 1403 | i=rep.length; 1404 | while (--i>=0) str=str.replace(new RegExp(rep[i],'g'),bracket[i]); 1405 | rv=str; 1406 | `` 1407 | endsnippet 1408 | 1409 | # \dot{} ⇔ \ddot{} 1410 | 1411 | # 1412 | 1413 | 1414 | 1415 | 1416 | 1417 | 1418 | ######################################################### 1419 | # for Specific Courses # 1420 | ######################################################### 1421 | 1422 | #### Thermodynamics 1423 | # 1424 | # HH ⇨ \left(\frac{\partial ▮}{\partial ▮}\right)_{▮} 1425 | # ║ (∂▮/∂▮)▄ 1426 | # cvv ⇨ c_V 1427 | # cvm ⇨ c_{Vm} 1428 | # cpv ⇨ c_{pm} 1429 | 1430 | context math(context) 1431 | snippet `HH` "diffraction" iA 1432 | \\left(\\frac{\\partial $1}{\\partial $2}\\right)_{$3}$0 1433 | endsnippet 1434 | 1435 | priority 100000 1436 | context math(context) 1437 | snippet `cvv` "for c_v" iA 1438 | c_V 1439 | endsnippet 1440 | 1441 | priority 100000 1442 | context math(context) 1443 | snippet `cvm` "for c_{Vm}" iA 1444 | c_{Vm} 1445 | endsnippet 1446 | 1447 | priority 100000 1448 | context math(context) 1449 | snippet `cpm` "for c_{Vm}" iA 1450 | c_{pm} 1451 | endsnippet 1452 | 1453 | #### Quantum Mechanics 1454 | # 1455 | # hbar ⇨ \hbar ║ ℏ ║ `priority 200` for ×⇨ \overline{h} 1456 | # avg ⇨ \left< ▮ \right> ║ <▮> 1457 | # bra ⇨ \langle ▮| ║ <▮| 1458 | # ket ⇨ |▮\rangle ║ |▮> 1459 | # |ket ⇨ ▮ \rangle ║ ▮> 1460 | # frt ⇨ \frac{1}{sqrt{2\pi}}\int_{-\infty}^{+\infty} 1461 | # ║ 1/√(2π) ∫_∞^∞ 1462 | 1463 | 1464 | priority 200 1465 | context math(context) 1466 | snippet `hbar` "hbar" iA 1467 | \\hbar 1468 | endsnippet 1469 | 1470 | context math(context) 1471 | snippet `avg` "average" iA 1472 | \\left< $1 \\right>$0 1473 | endsnippet 1474 | 1475 | context math(context) 1476 | snippet `[bB]ra` "Dirac bra" iA 1477 | \\langle $1|$0 1478 | endsnippet 1479 | 1480 | context math(context) 1481 | snippet `(?<=\|[ ]?)ket` "dirac ket" iA 1482 | $1\\rangle$0 1483 | endsnippet 1484 | 1485 | context math(context) 1486 | snippet `(? 1539 | endsnippet 1540 | 1541 | context !math(context) 1542 | snippet %% "big star" A 1543 | $\\color{red}\\bigstar$ 1544 | endsnippet 1545 | 1546 | context !math(context) 1547 | snippet `(\?\?\?|???)` "can't understand" A 1548 | ==???== 1549 | endsnippet 1550 | 1551 | context math(context) 1552 | snippet `BB` "cdot" iA 1553 | \\boxed{$1}$0 1554 | endsnippet 1555 | 1556 | context math(context) 1557 | snippet `([^$]*)@@` "at" iA 1558 | `` 1559 | let text = m[1] 1560 | 1561 | let depth=0; 1562 | let i=text.length; 1563 | 1564 | while (i>=0) { 1565 | i--; 1566 | if (text[i] == '}'|| text[i] == ')' || text[i] ==']' ) depth++; 1567 | if (text[i] == '{'|| text[i] == '(' || text[i] =='[' ) depth--; 1568 | if ((text[i] == '+'|| text[i] == '=' || text[i] == '-' || text[i]=='&'|| text[i]==',')&& depth==0 || depth <0) break; 1569 | } 1570 | 1571 | rv=`${text.slice(0,i+1)}\\\\left.${text.slice(i+1,text.length)}\\\\right|_{${snip.tabstop(1)}}^{${snip.tabstop(2)}}` 1572 | 1573 | `` 1574 | endsnippet 1575 | 1576 | #### color 1577 | 1578 | # \red· --> {\color{red}▮} 1579 | # \red; --> {\color{red}${visual}} 1580 | 1581 | context math(context) 1582 | snippet `\\(red|green|blue) ` "useful color" iA 1583 | {\\color{``rv=m[1]``}$1} 1584 | endsnippet 1585 | 1586 | context math(context) 1587 | snippet `\\(red|green|blue);` "useful color" iA 1588 | {\\color{``rv=m[1]``}``rv=visual()``} 1589 | endsnippet 1590 | 1591 | 1592 | ######################################################## 1593 | # lint # 1594 | ######################################################## 1595 | 1596 | #### 1597 | # 1598 | # {} ⇨ ' ' 1599 | # +! ⇨ +1 1600 | # +@ ⇨ +2 1601 | # 、、⇨ \\ 1602 | # 》 ⇨ > 1603 | 1604 | context math(context) 1605 | snippet `(|_|\^)(? ') :m[0]`` 1627 | endsnippet 1628 | 1629 | ######################################################## 1630 | # Temp # 1631 | ######################################################## 1632 | 1633 | #### autoclose bracket 1634 | # 1635 | # ( ⇨ () 1636 | # [ ⇨ [] 1637 | # { ⇨ {} 1638 | # \{ ⇨ \{\} 1639 | 1640 | context autoclosing() 1641 | snippet `(?