tex2typst 0.3.0-beta-2 → 0.3.0-beta-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +96 -15
- package/dist/tex2typst.min.js +19 -19
- package/dist/types.d.ts +4 -3
- package/dist/typst-parser.d.ts +2 -2
- package/package.json +1 -1
- package/src/map.ts +3 -1
- package/src/tex-writer.ts +50 -10
- package/src/types.ts +2 -1
- package/src/typst-parser.ts +55 -5
- package/src/writer.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -367,7 +367,6 @@ var map_from_official_docs = new Map([
|
|
|
367
367
|
["mathquestion", "quest"],
|
|
368
368
|
["Question", "quest.double"],
|
|
369
369
|
["mathoctothorpe", "hash"],
|
|
370
|
-
["mathhyphen", "hyph"],
|
|
371
370
|
["mathpercent", "percent"],
|
|
372
371
|
["mathparagraph", "pilcrow"],
|
|
373
372
|
["mathsection", "section"],
|
|
@@ -988,7 +987,8 @@ var typst_to_tex_map = new Map([
|
|
|
988
987
|
["tilde", "tilde"],
|
|
989
988
|
["hat", "hat"],
|
|
990
989
|
["upright", "mathrm"],
|
|
991
|
-
["bold", "boldsymbol"]
|
|
990
|
+
["bold", "boldsymbol"],
|
|
991
|
+
["hyph.minus", "\\text{-}"]
|
|
992
992
|
]);
|
|
993
993
|
for (const [key, value] of typst_to_tex_map) {
|
|
994
994
|
reverseSymbolMap.set(key, value);
|
|
@@ -2273,8 +2273,6 @@ function convertToken(token) {
|
|
|
2273
2273
|
return "\\/";
|
|
2274
2274
|
} else if (token === "\\|") {
|
|
2275
2275
|
return "parallel";
|
|
2276
|
-
} else if (token === "\\colon") {
|
|
2277
|
-
return ":";
|
|
2278
2276
|
} else if (token === "\\\\") {
|
|
2279
2277
|
return "\\";
|
|
2280
2278
|
} else if (["\\$", "\\#", "\\&", "\\_"].includes(token)) {
|
|
@@ -2669,8 +2667,9 @@ class TypstParser {
|
|
|
2669
2667
|
if ([1 /* ELEMENT */, 0 /* SYMBOL */].includes(firstToken.type)) {
|
|
2670
2668
|
if (start + 1 < tokens.length && tokens[start + 1].eq(LEFT_PARENTHESES)) {
|
|
2671
2669
|
if (firstToken.value === "mat") {
|
|
2672
|
-
const [matrix, newPos2] = this.parseGroupsOfArguments(tokens, start + 1);
|
|
2670
|
+
const [matrix, named_params, newPos2] = this.parseGroupsOfArguments(tokens, start + 1);
|
|
2673
2671
|
const mat = new TypstNode("matrix", "", [], matrix);
|
|
2672
|
+
mat.setOptions(named_params);
|
|
2674
2673
|
return [mat, newPos2];
|
|
2675
2674
|
}
|
|
2676
2675
|
const [args, newPos] = this.parseArguments(tokens, start + 1);
|
|
@@ -2688,19 +2687,61 @@ class TypstParser {
|
|
|
2688
2687
|
parseGroupsOfArguments(tokens, start) {
|
|
2689
2688
|
const end = find_closing_match2(tokens, start);
|
|
2690
2689
|
const matrix = [];
|
|
2690
|
+
let named_params = {};
|
|
2691
2691
|
let pos = start + 1;
|
|
2692
2692
|
while (pos < end) {
|
|
2693
2693
|
while (pos < end) {
|
|
2694
|
+
let extract_named_params = function(arr) {
|
|
2695
|
+
const COLON = new TypstNode("atom", ":");
|
|
2696
|
+
const np2 = {};
|
|
2697
|
+
const to_delete = [];
|
|
2698
|
+
for (let i = 0;i < arr.length; i++) {
|
|
2699
|
+
if (arr[i].type !== "group") {
|
|
2700
|
+
continue;
|
|
2701
|
+
}
|
|
2702
|
+
const g = arr[i];
|
|
2703
|
+
const pos_colon = array_find(g.args, COLON);
|
|
2704
|
+
if (pos_colon === -1 || pos_colon === 0) {
|
|
2705
|
+
continue;
|
|
2706
|
+
}
|
|
2707
|
+
to_delete.push(i);
|
|
2708
|
+
const param_name = g.args[pos_colon - 1];
|
|
2709
|
+
if (param_name.eq(new TypstNode("symbol", "delim"))) {
|
|
2710
|
+
if (g.args[pos_colon + 1].type === "text") {
|
|
2711
|
+
np2["delim"] = g.args[pos_colon + 1].content;
|
|
2712
|
+
if (g.args.length !== 3) {
|
|
2713
|
+
throw new TypstParserError("Invalid number of arguments for delim");
|
|
2714
|
+
}
|
|
2715
|
+
} else if (g.args[pos_colon + 1].eq(new TypstNode("atom", "#"))) {
|
|
2716
|
+
if (g.args.length !== 4 || !g.args[pos_colon + 2].eq(new TypstNode("symbol", "none"))) {
|
|
2717
|
+
throw new TypstParserError("Invalid number of arguments for delim");
|
|
2718
|
+
}
|
|
2719
|
+
np2["delim"] = "#none";
|
|
2720
|
+
} else {
|
|
2721
|
+
throw new TypstParserError("Not implemented for other types of delim");
|
|
2722
|
+
}
|
|
2723
|
+
} else {
|
|
2724
|
+
throw new TypstParserError("Not implemented for other named parameters");
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
for (let i = to_delete.length - 1;i >= 0; i--) {
|
|
2728
|
+
arr.splice(to_delete[i], 1);
|
|
2729
|
+
}
|
|
2730
|
+
return [arr, np2];
|
|
2731
|
+
};
|
|
2694
2732
|
let next_stop = array_find(tokens, SEMICOLON, pos);
|
|
2695
2733
|
if (next_stop === -1) {
|
|
2696
2734
|
next_stop = end;
|
|
2697
2735
|
}
|
|
2698
|
-
|
|
2736
|
+
let row = this.parseCommaSeparatedArguments(tokens, pos, next_stop);
|
|
2737
|
+
let np = {};
|
|
2738
|
+
[row, np] = extract_named_params(row);
|
|
2699
2739
|
matrix.push(row);
|
|
2740
|
+
Object.assign(named_params, np);
|
|
2700
2741
|
pos = next_stop + 1;
|
|
2701
2742
|
}
|
|
2702
2743
|
}
|
|
2703
|
-
return [matrix, end + 1];
|
|
2744
|
+
return [matrix, named_params, end + 1];
|
|
2704
2745
|
}
|
|
2705
2746
|
parseCommaSeparatedArguments(tokens, start, end) {
|
|
2706
2747
|
const args = [];
|
|
@@ -2831,15 +2872,17 @@ function convert_typst_node_to_tex(node) {
|
|
|
2831
2872
|
case "whitespace":
|
|
2832
2873
|
return new TexNode("whitespace", node.content);
|
|
2833
2874
|
case "atom":
|
|
2834
|
-
if (node.content === ":") {
|
|
2835
|
-
return new TexNode("symbol", "\\colon");
|
|
2836
|
-
}
|
|
2837
2875
|
return new TexNode("element", node.content);
|
|
2838
2876
|
case "symbol":
|
|
2839
|
-
|
|
2840
|
-
|
|
2877
|
+
switch (node.content) {
|
|
2878
|
+
case "comma":
|
|
2879
|
+
return new TexNode("element", ",");
|
|
2880
|
+
case "hyph":
|
|
2881
|
+
case "hyph.minus":
|
|
2882
|
+
return new TexNode("text", "-");
|
|
2883
|
+
default:
|
|
2884
|
+
return new TexNode("symbol", typst_token_to_tex(node.content));
|
|
2841
2885
|
}
|
|
2842
|
-
return new TexNode("symbol", typst_token_to_tex(node.content));
|
|
2843
2886
|
case "text":
|
|
2844
2887
|
return new TexNode("text", node.content);
|
|
2845
2888
|
case "comment":
|
|
@@ -2916,10 +2959,48 @@ function convert_typst_node_to_tex(node) {
|
|
|
2916
2959
|
const typst_data = node.data;
|
|
2917
2960
|
const tex_data = typst_data.map((row) => row.map(convert_typst_node_to_tex));
|
|
2918
2961
|
const matrix = new TexNode("beginend", "matrix", [], tex_data);
|
|
2962
|
+
let left_delim = "\\left(";
|
|
2963
|
+
let right_delim = "\\right)";
|
|
2964
|
+
if (node.options) {
|
|
2965
|
+
if ("delim" in node.options) {
|
|
2966
|
+
switch (node.options.delim) {
|
|
2967
|
+
case "#none":
|
|
2968
|
+
return matrix;
|
|
2969
|
+
case "[":
|
|
2970
|
+
left_delim = "\\left[";
|
|
2971
|
+
right_delim = "\\right]";
|
|
2972
|
+
break;
|
|
2973
|
+
case "]":
|
|
2974
|
+
left_delim = "\\left]";
|
|
2975
|
+
right_delim = "\\right[";
|
|
2976
|
+
break;
|
|
2977
|
+
case "{":
|
|
2978
|
+
left_delim = "\\left\\{";
|
|
2979
|
+
right_delim = "\\right\\}";
|
|
2980
|
+
break;
|
|
2981
|
+
case "}":
|
|
2982
|
+
left_delim = "\\left\\}";
|
|
2983
|
+
right_delim = "\\right\\{";
|
|
2984
|
+
break;
|
|
2985
|
+
case "|":
|
|
2986
|
+
left_delim = "\\left|";
|
|
2987
|
+
right_delim = "\\right|";
|
|
2988
|
+
break;
|
|
2989
|
+
case ")":
|
|
2990
|
+
left_delim = "\\left)";
|
|
2991
|
+
right_delim = "\\right(";
|
|
2992
|
+
case "(":
|
|
2993
|
+
default:
|
|
2994
|
+
left_delim = "\\left(";
|
|
2995
|
+
right_delim = "\\right)";
|
|
2996
|
+
break;
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
2919
3000
|
return new TexNode("ordgroup", "", [
|
|
2920
|
-
new TexNode("element",
|
|
3001
|
+
new TexNode("element", left_delim),
|
|
2921
3002
|
matrix,
|
|
2922
|
-
new TexNode("element",
|
|
3003
|
+
new TexNode("element", right_delim)
|
|
2923
3004
|
]);
|
|
2924
3005
|
}
|
|
2925
3006
|
case "control": {
|
package/dist/tex2typst.min.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var B=new Map([["nonumber",""],["vec","arrow"],["neq","eq.not"],["dot","dot"],["ddot","dot.double"],["doteq","dot(eq)"],["dots","dots.h"],["vdots","dots.v"],["ddots","dots.down"],["widehat","hat"],["widetilde","tilde"],["quad","quad"],["qquad","wide"],["overbrace","overbrace"],["underbrace","underbrace"],["overline","overline"],["underline","underline"],["bar","macron"],["dbinom","binom"],["tbinom","binom"],["dfrac","frac"],["tfrac","frac"],["operatorname","op"],["boldsymbol","bold"],["mathbb","bb"],["mathbf","bold"],["mathcal","cal"],["mathit","italic"],["mathfrak","frak"],["mathrm","upright"],["mathsf","sans"],["mathtt","mono"],["rm","upright"],["pmb","bold"],["pm","plus.minus"],["mp","minus.plus"],["boxplus","plus.square"],["otimes","times.circle"],["boxtimes","times.square"],["approx","approx"],["cong","tilde.equiv"],["simeq","tilde.eq"],["asymp","≍"],["equiv","equiv"],["propto","prop"],["gets","arrow.l"],["hookleftarrow","arrow.l.hook"],["leftharpoonup","harpoon.lt"],["leftharpoondown","harpoon.lb"],["rightleftharpoons","harpoons.rtlb"],["longleftarrow","arrow.l.long"],["longrightarrow","arrow.r.long"],["longleftrightarrow","arrow.l.r.long"],["Longleftarrow","arrow.l.double.long"],["Longrightarrow","arrow.r.double.long"],["Longleftrightarrow","arrow.l.r.double.long"],["hookrightarrow","arrow.r.hook"],["rightharpoonup","harpoon.rt"],["rightharpoondown","harpoon.rb"],["iff","arrow.l.r.double.long"],["implies","arrow.r.double.long"],["uparrow","arrow.t"],["downarrow","arrow.b"],["updownarrow","arrow.t.b"],["Uparrow","arrow.t.double"],["Downarrow","arrow.b.double"],["Updownarrow","arrow.t.b.double"],["nearrow","arrow.tr"],["searrow","arrow.br"],["swarrow","arrow.bl"],["nwarrow","arrow.tl"],["leadsto","arrow.squiggly"],["leftleftarrows","arrows.ll"],["rightrightarrows","arrows.rr"],["Cap","sect.double"],["Cup","union.double"],["Delta","Delta"],["Gamma","Gamma"],["Join","join"],["Lambda","Lambda"],["Leftarrow","arrow.l.double"],["Leftrightarrow","arrow.l.r.double"],["Longrightarrow","arrow.r.double.long"],["Omega","Omega"],["P","pilcrow"],["Phi","Phi"],["Pi","Pi"],["Psi","Psi"],["Rightarrow","arrow.r.double"],["S","section"],["Sigma","Sigma"],["Theta","Theta"],["aleph","alef"],["alpha","alpha"],["angle","angle"],["approx","approx"],["approxeq","approx.eq"],["beta","beta"],["bigcap","sect.big"],["bigcirc","circle.big"],["bigcup","union.big"],["bigodot","dot.circle.big"],["bigotimes","times.circle.big"],["bigsqcup","union.sq.big"],["biguplus","union.plus.big"],["bigvee","or.big"],["bigwedge","and.big"],["bullet","bullet"],["cap","sect"],["cdot","dot.op"],["cdots","dots.c"],["checkmark","checkmark"],["chi","chi"],["circ","circle.small"],["colon","colon"],["cong","tilde.equiv"],["coprod","product.co"],["copyright","copyright"],["cup","union"],["curlyvee","or.curly"],["curlywedge","and.curly"],["dagger","dagger"],["dashv","tack.l"],["ddagger","dagger.double"],["delta","delta"],["ddots","dots.down"],["diamond","diamond"],["div","div"],["divideontimes","times.div"],["dotplus","plus.dot"],["downarrow","arrow.b"],["ell","ell"],["emptyset","nothing"],["epsilon","epsilon.alt"],["equiv","equiv"],["eta","eta"],["exists","exists"],["forall","forall"],["gamma","gamma"],["ge","gt.eq"],["geq","gt.eq"],["geqslant","gt.eq.slant"],["gg","gt.double"],["hbar","planck.reduce"],["imath","dotless.i"],["iiiint","integral.quad"],["iiint","integral.triple"],["iint","integral.double"],["in","in"],["infty","infinity"],["int","integral"],["intercal","top"],["iota","iota"],["jmath","dotless.j"],["kappa","kappa"],["lambda","lambda"],["land","and"],["langle","angle.l"],["lbrace","brace.l"],["lbrack","bracket.l"],["ldots","dots.h"],["le","lt.eq"],["leadsto","arrow.squiggly"],["leftarrow","arrow.l"],["leftthreetimes","times.three.l"],["leftrightarrow","arrow.l.r"],["leq","lt.eq"],["leqslant","lt.eq.slant"],["lhd","triangle.l"],["ll","lt.double"],["lor","or"],["ltimes","times.l"],["measuredangle","angle.arc"],["mid","divides"],["models","models"],["mp","minus.plus"],["mu","mu"],["nabla","nabla"],["ncong","tilde.equiv.not"],["ne","eq.not"],["neg","not"],["neq","eq.not"],["nexists","exists.not"],["ni","in.rev"],["nleftarrow","arrow.l.not"],["nleq","lt.eq.not"],["nparallel","parallel.not"],["ngeq","gt.eq.not"],["nmid","divides.not"],["notin","in.not"],["nsim","tilde.not"],["nsubseteq","subset.eq.not"],["nu","nu"],["ntriangleleft","lt.tri.not"],["ntriangleright","gt.tri.not"],["nwarrow","arrow.tl"],["odot","dot.circle"],["oint","integral.cont"],["oiint","integral.surf"],["oiiint","integral.vol"],["omega","omega"],["ominus","minus.circle"],["otimes","times.circle"],["parallel","parallel"],["partial","diff"],["perp","perp"],["phi","phi.alt"],["pi","pi"],["pm","plus.minus"],["pounds","pound"],["prec","prec"],["preceq","prec.eq"],["prime","prime"],["prod","product"],["propto","prop"],["psi","psi"],["rangle","angle.r"],["rbrace","brace.r"],["rbrack","bracket.r"],["rhd","triangle"],["rho","rho"],["rightarrow","arrow.r"],["rightthreetimes","times.three.r"],["rtimes","times.r"],["setminus","without"],["sigma","sigma"],["sim","tilde.op"],["simeq","tilde.eq"],["slash","slash"],["smallsetminus","without"],["spadesuit","suit.spade"],["sqcap","sect.sq"],["sqcup","union.sq"],["sqsubseteq","subset.eq.sq"],["sqsupseteq","supset.eq.sq"],["subset","subset"],["subseteq","subset.eq"],["subsetneq","subset.neq"],["succ","succ"],["succeq","succ.eq"],["sum","sum"],["supset","supset"],["supseteq","supset.eq"],["supsetneq","supset.neq"],["swarrow","arrow.bl"],["tau","tau"],["theta","theta"],["times","times"],["to","arrow.r"],["top","top"],["triangle","triangle.t"],["twoheadrightarrow","arrow.r.twohead"],["uparrow","arrow.t"],["updownarrow","arrow.t.b"],["upharpoonright","harpoon.tr"],["uplus","union.plus"],["upsilon","upsilon"],["varepsilon","epsilon"],["varnothing","diameter"],["varphi","phi"],["varpi","pi.alt"],["varrho","rho.alt"],["varsigma","sigma.alt"],["vartheta","theta.alt"],["vdash","tack.r"],["vdots","dots.v"],["vee","or"],["wedge","and"],["wr","wreath"],["xi","xi"],["yen","yen"],["zeta","zeta"],["mathscr","scr"],["LaTeX","#LaTeX"],["TeX","#TeX"]]),D2=new Map([["lparen","paren.l"],["lParen","paren.l.double"],["rparen","paren.r"],["rParen","paren.r.double"],["overparen","paren.t"],["underparen","paren.b"],["lbrace","brace.l"],["lBrace","brace.l.double"],["rbrace","brace.r"],["rBrace","brace.r.double"],["underbrace","brace.b"],["lbrack","bracket.l"],["lBrack","bracket.l.double"],["rbrack","bracket.r"],["rBrack","bracket.r.double"],["overbracket","bracket.t"],["underbracket","bracket.b"],["lbrbrak","shell.l"],["Lbrbrak","shell.l.double"],["rbrbrak","shell.r"],["Rbrbrak","shell.r.double"],["obrbrak","shell.t"],["ubrbrak","shell.b"],["vert","bar.v"],["Vert","bar.v.double"],["Vvert","bar.v.triple"],["circledvert","bar.v.circle"],["horizbar","bar.h"],["lvzigzag","fence.l"],["Lvzigzag","fence.l.double"],["rvzigzag","fence.r"],["Rvzigzag","fence.r.double"],["fourvdots","fence.dotted"],["angle","angle"],["langle","angle.l"],["lcurvyangle","angle.l.curly"],["langledot","angle.l.dot"],["rangle","angle.r"],["rcurvyangle","angle.r.curly"],["rangledot","angle.r.dot"],["angdnr","angle.acute"],["measuredangle","angle.arc"],["measuredangleleft","angle.arc.rev"],["wideangledown","angle.oblique"],["revangle","angle.rev"],["rightangle","angle.right"],["measuredrightangle","angle.right.arc"],["rightanglemdot","angle.right.dot"],["rightanglesqr","angle.right.sq"],["angles","angle.s"],["threedangle","angle.spatial"],["sphericalangle","angle.spheric"],["gtlpar","angle.spheric.rev"],["sphericalangleup","angle.spheric.top"],["lceil","ceil.l"],["rceil","ceil.r"],["lfloor","floor.l"],["rfloor","floor.r"],["mathampersand","amp"],["upand","amp.inv"],["ast","ast.op"],["circledast","ast.circle"],["boxast","ast.square"],["mathatsign","at"],["backslash","backslash"],["obslash","backslash.circle"],["rsolbar","backslash.not"],["mathcolon","colon"],["Colon","colon.double"],["coloneq","colon.eq"],["Coloneq","colon.double.eq"],["mathcomma","comma"],["dagger","dagger"],["ddagger","dagger.double"],["dashcolon","dash.colon"],["circleddash","dash.circle"],["hzigzag","dash.wave.double"],["cdot","dot.op"],["mathperiod","dot.basic"],["cdotp","dot.c"],["odot","dot.circle"],["bigodot","dot.circle.big"],["boxdot","dot.square"],["dddot","dot.triple"],["ddddot","dot.quad"],["mathexclam","excl"],["Exclam","excl.double"],["mathquestion","quest"],["Question","quest.double"],["mathoctothorpe","hash"],["mathhyphen","hyph"],["mathpercent","percent"],["mathparagraph","pilcrow"],["mathsection","section"],["mathsemicolon","semi"],["mathslash","slash"],["sslash","slash.double"],["trslash","slash.triple"],["xsol","slash.big"],["unicodecdots","dots.h.c"],["unicodeellipsis","dots.h"],["vdots","dots.v"],["ddots","dots.down"],["adots","dots.up"],["sim","tilde.op"],["dotsim","tilde.dot"],["sime","tilde.eq"],["nsimeq","tilde.eq.not"],["backsimeq","tilde.eq.rev"],["cong","tilde.equiv"],["ncong","tilde.equiv.not"],["simneqq","tilde.nequiv"],["nsim","tilde.not"],["backsim","tilde.rev"],["backcong","tilde.rev.equiv"],["approxident","tilde.triple"],["caretinsert","caret"],["prime","prime"],["backprime","prime.rev"],["dprime","prime.double"],["backdprime","prime.double.rev"],["trprime","prime.triple"],["backtrprime","prime.triple.rev"],["qprime","prime.quad"],["mathplus","plus"],["oplus","plus.circle"],["rightarrowonoplus","plus.circle.arrow"],["bigoplus","plus.circle.big"],["dotplus","plus.dot"],["doubleplus","plus.double"],["pm","plus.minus"],["boxplus","plus.square"],["triangleplus","plus.triangle"],["tripleplus","plus.triple"],["minus","minus"],["ominus","minus.circle"],["dotminus","minus.dot"],["mp","minus.plus"],["boxminus","minus.square"],["eqsim","minus.tilde"],["triangleminus","minus.triangle"],["div","div"],["odiv","div.circle"],["times","times"],["bigtimes","times.big"],["otimes","times.circle"],["bigotimes","times.circle.big"],["divideontimes","times.div"],["leftthreetimes","times.three.l"],["rightthreetimes","times.three.r"],["ltimes","times.l"],["rtimes","times.r"],["boxtimes","times.square"],["triangletimes","times.triangle"],["mathratio","ratio"],["equal","eq"],["stareq","eq.star"],["circledequal","eq.circle"],["eqcolon","eq.colon"],["eqdef","eq.def"],["triangleq","eq.delta"],["veeeq","eq.equi"],["wedgeq","eq.est"],["eqgtr","eq.gt"],["eqless","eq.lt"],["measeq","eq.m"],["ne","eq.not"],["curlyeqprec","eq.prec"],["questeq","eq.quest"],["curlyeqsucc","eq.succ"],["equiv","eq.triple"],["Equiv","eq.quad"],["greater","gt"],["ogreaterthan","gt.circle"],["gtrdot","gt.dot"],["gtrapprox","gt.approx"],["gg","gt.double"],["geq","gt.eq"],["geqslant","gt.eq.slant"],["gtreqless","gt.eq.lt"],["ngeq","gt.eq.not"],["geqq","gt.equiv"],["gtrless","gt.lt"],["ngtrless","gt.lt.not"],["gneq","gt.neq"],["gnapprox","gt.napprox"],["gneqq","gt.nequiv"],["ngtr","gt.not"],["gnsim","gt.ntilde"],["gtrsim","gt.tilde"],["ngtrsim","gt.tilde.not"],["vartriangleright","gt.tri"],["trianglerighteq","gt.tri.eq"],["ntrianglerighteq","gt.tri.eq.not"],["nvartriangleright","gt.tri.not"],["ggg","gt.triple"],["gggnest","gt.triple.nested"],["less","lt"],["olessthan","lt.circle"],["lessdot","lt.dot"],["lessapprox","lt.approx"],["ll","lt.double"],["leq","lt.eq"],["leqslant","lt.eq.slant"],["lesseqgtr","lt.eq.gt"],["nleq","lt.eq.not"],["leqq","lt.equiv"],["lessgtr","lt.gt"],["nlessgtr","lt.gt.not"],["lneq","lt.neq"],["lnapprox","lt.napprox"],["lneqq","lt.nequiv"],["nless","lt.not"],["lnsim","lt.ntilde"],["lesssim","lt.tilde"],["nlesssim","lt.tilde.not"],["vartriangleleft","lt.tri"],["trianglelefteq","lt.tri.eq"],["ntrianglelefteq","lt.tri.eq.not"],["nvartriangleleft","lt.tri.not"],["lll","lt.triple"],["lllnest","lt.triple.nested"],["approx","approx"],["approxeq","approx.eq"],["napprox","approx.not"],["prec","prec"],["precapprox","prec.approx"],["preccurlyeq","prec.curly.eq"],["npreccurlyeq","prec.curly.eq.not"],["Prec","prec.double"],["preceq","prec.eq"],["preceqq","prec.equiv"],["precnapprox","prec.napprox"],["precneq","prec.neq"],["precneqq","prec.nequiv"],["nprec","prec.not"],["precnsim","prec.ntilde"],["precsim","prec.tilde"],["succ","succ"],["succapprox","succ.approx"],["succcurlyeq","succ.curly.eq"],["nsucccurlyeq","succ.curly.eq.not"],["Succ","succ.double"],["succeq","succ.eq"],["succeqq","succ.equiv"],["succnapprox","succ.napprox"],["succneq","succ.neq"],["succneqq","succ.nequiv"],["nsucc","succ.not"],["succnsim","succ.ntilde"],["succsim","succ.tilde"],["nequiv","equiv.not"],["propto","prop"],["origof","original"],["imageof","image"],["varnothing","emptyset"],["emptysetoarr","emptyset.arrow.r"],["emptysetoarrl","emptyset.arrow.l"],["emptysetobar","emptyset.bar"],["emptysetocirc","emptyset.circle"],["revemptyset","emptyset.rev"],["setminus","without"],["complement","complement"],["in","in"],["notin","in.not"],["ni","in.rev"],["nni","in.rev.not"],["smallni","in.rev.small"],["smallin","in.small"],["subset","subset"],["subsetdot","subset.dot"],["Subset","subset.double"],["subseteq","subset.eq"],["nsubseteq","subset.eq.not"],["sqsubseteq","subset.eq.sq"],["nsqsubseteq","subset.eq.sq.not"],["subsetneq","subset.neq"],["nsubset","subset.not"],["sqsubset","subset.sq"],["sqsubsetneq","subset.sq.neq"],["supset","supset"],["supsetdot","supset.dot"],["Supset","supset.double"],["supseteq","supset.eq"],["nsupseteq","supset.eq.not"],["sqsupseteq","supset.eq.sq"],["nsqsupseteq","supset.eq.sq.not"],["supsetneq","supset.neq"],["nsupset","supset.not"],["sqsupset","supset.sq"],["sqsupsetneq","supset.sq.neq"],["cup","union"],["cupleftarrow","union.arrow"],["bigcup","union.big"],["cupdot","union.dot"],["bigcupdot","union.dot.big"],["Cup","union.double"],["uminus","union.minus"],["cupvee","union.or"],["uplus","union.plus"],["biguplus","union.plus.big"],["sqcup","union.sq"],["bigsqcup","union.sq.big"],["Sqcup","union.sq.double"],["cap","sect"],["capwedge","sect.and"],["bigcap","sect.big"],["capdot","sect.dot"],["Cap","sect.double"],["sqcap","sect.sq"],["bigsqcap","sect.sq.big"],["Sqcap","sect.sq.double"],["infty","infinity"],["nvinfty","infinity.bar"],["iinfin","infinity.incomplete"],["tieinfty","infinity.tie"],["partial","diff"],["nabla","gradient"],["sum","sum"],["sumint","sum.integral"],["prod","product"],["coprod","product.co"],["int","integral"],["intlarhk","integral.arrow.hook"],["awint","integral.ccw"],["oint","integral.cont"],["ointctrclockwise","integral.cont.ccw"],["varointclockwise","integral.cont.cw"],["intclockwise","integral.cw"],["intbar","integral.dash"],["intBar","integral.dash.double"],["iint","integral.double"],["iiiint","integral.quad"],["intcap","integral.sect"],["fint","integral.slash"],["sqint","integral.square"],["oiint","integral.surf"],["intx","integral.times"],["iiint","integral.triple"],["intcup","integral.union"],["oiiint","integral.vol"],["increment","laplace"],["forall","forall"],["exists","exists"],["nexists","exists.not"],["top","top"],["bot","bot"],["neg","not"],["wedge","and"],["bigwedge","and.big"],["curlywedge","and.curly"],["wedgedot","and.dot"],["Wedge","and.double"],["vee","or"],["bigvee","or.big"],["curlyvee","or.curly"],["veedot","or.dot"],["Vee","or.double"],["models","models"],["Vdash","forces"],["nVdash","forces.not"],["therefore","therefore"],["because","because"],["QED","qed"],["vysmwhtcircle","compose"],["multimap","multimap"],["dualmap","multimap.double"],["tplus","tiny"],["tminus","miny"],["mid","divides"],["nmid","divides.not"],["wr","wreath"],["parallel","parallel"],["nhpar","parallel.struck"],["circledparallel","parallel.circle"],["equalparallel","parallel.eq"],["equivVert","parallel.equiv"],["nparallel","parallel.not"],["eparsl","parallel.slanted.eq"],["smeparsl","parallel.slanted.eq.tilde"],["eqvparsl","parallel.slanted.equiv"],["parsim","parallel.tilde"],["perp","perp"],["operp","perp.circle"],["diameter","diameter"],["Join","join"],["rightouterjoin","join.r"],["leftouterjoin","join.l"],["fullouterjoin","join.l.r"],["smashtimes","smash"],["mathdollar","dollar"],["euro","euro"],["mathsterling","pound"],["mathyen","yen"],["checkmark","checkmark"],["maltese","maltese"],["clubsuit","suit.club.filled"],["varclubsuit","suit.club.stroked"],["vardiamondsuit","suit.diamond.filled"],["diamondsuit","suit.diamond.stroked"],["varheartsuit","suit.heart.filled"],["heartsuit","suit.heart.stroked"],["spadesuit","suit.spade.filled"],["varspadesuit","suit.spade.stroked"],["quarternote","note.quarter.alt"],["eighthnote","note.eighth.alt"],["twonotes","note.eighth.beamed"],["natural","natural"],["flat","flat"],["sharp","sharp"],["smblkcircle","bullet"],["mdlgwhtcircle","circle.stroked"],["mdsmwhtcircle","circle.stroked.small"],["lgwhtcircle","circle.stroked.big"],["mdlgblkcircle","circle.filled"],["mdsmblkcircle","circle.filled.tiny"],["vysmblkcircle","circle.filled.small"],["lgblkcircle","circle.filled.big"],["dottedcircle","circle.dotted"],["circledcirc","circle.nested"],["whthorzoval","ellipse.stroked.h"],["whtvertoval","ellipse.stroked.v"],["blkhorzoval","ellipse.filled.h"],["blkvertoval","ellipse.filled.v"],["bigtriangleup","triangle.stroked.t"],["bigtriangledown","triangle.stroked.b"],["triangleright","triangle.stroked.r"],["triangleleft","triangle.stroked.l"],["lltriangle","triangle.stroked.bl"],["lrtriangle","triangle.stroked.br"],["ultriangle","triangle.stroked.tl"],["urtriangle","triangle.stroked.tr"],["vartriangle","triangle.stroked.small.t"],["triangledown","triangle.stroked.small.b"],["smalltriangleright","triangle.stroked.small.r"],["smalltriangleleft","triangle.stroked.small.l"],["whiteinwhitetriangle","triangle.stroked.nested"],["trianglecdot","triangle.stroked.dot"],["bigblacktriangleup","triangle.filled.t"],["bigblacktriangledown","triangle.filled.b"],["blacktriangleright","triangle.filled.r"],["blacktriangleleft","triangle.filled.l"],["llblacktriangle","triangle.filled.bl"],["lrblacktriangle","triangle.filled.br"],["ulblacktriangle","triangle.filled.tl"],["urblacktriangle","triangle.filled.tr"],["blacktriangle","triangle.filled.small.t"],["blacktriangledown","triangle.filled.small.b"],["smallblacktriangleright","triangle.filled.small.r"],["smallblacktriangleleft","triangle.filled.small.l"],["mdlgwhtsquare","square.stroked"],["smwhtsquare","square.stroked.tiny"],["mdsmwhtsquare","square.stroked.small"],["mdwhtsquare","square.stroked.medium"],["lgwhtsquare","square.stroked.big"],["dottedsquare","square.stroked.dotted"],["squoval","square.stroked.rounded"],["mdlgblksquare","square.filled"],["smblksquare","square.filled.tiny"],["mdsmblksquare","square.filled.small"],["mdblksquare","square.filled.medium"],["lgblksquare","square.filled.big"],["hrectangle","rect.stroked.h"],["vrectangle","rect.stroked.v"],["hrectangleblack","rect.filled.h"],["vrectangleblack","rect.filled.v"],["pentagon","penta.stroked"],["pentagonblack","penta.filled"],["varhexagon","hexa.stroked"],["varhexagonblack","hexa.filled"],["mdlgwhtdiamond","diamond.stroked"],["smwhtdiamond","diamond.stroked.small"],["mdwhtdiamond","diamond.stroked.medium"],["diamondcdot","diamond.stroked.dot"],["mdlgblkdiamond","diamond.filled"],["mdblkdiamond","diamond.filled.medium"],["smblkdiamond","diamond.filled.small"],["mdlgwhtlozenge","lozenge.stroked"],["smwhtlozenge","lozenge.stroked.small"],["mdwhtlozenge","lozenge.stroked.medium"],["mdlgblklozenge","lozenge.filled"],["smblklozenge","lozenge.filled.small"],["mdblklozenge","lozenge.filled.medium"],["parallelogram","parallelogram.stroked"],["parallelogramblack","parallelogram.filled"],["star","star.op"],["bigwhitestar","star.stroked"],["bigstar","star.filled"],["rightarrow","arrow.r"],["longmapsto","arrow.r.long.bar"],["mapsto","arrow.r.bar"],["rightdowncurvedarrow","arrow.r.curve"],["rightdasharrow","arrow.r.dashed"],["rightdotarrow","arrow.r.dotted"],["Rightarrow","arrow.r.double"],["Mapsto","arrow.r.double.bar"],["Longrightarrow","arrow.r.double.long"],["Longmapsto","arrow.r.double.long.bar"],["nRightarrow","arrow.r.double.not"],["hookrightarrow","arrow.r.hook"],["longrightarrow","arrow.r.long"],["longrightsquigarrow","arrow.r.long.squiggly"],["looparrowright","arrow.r.loop"],["nrightarrow","arrow.r.not"],["RRightarrow","arrow.r.quad"],["rightsquigarrow","arrow.r.squiggly"],["rightarrowbar","arrow.r.stop"],["rightwhitearrow","arrow.r.stroked"],["rightarrowtail","arrow.r.tail"],["similarrightarrow","arrow.r.tilde"],["Rrightarrow","arrow.r.triple"],["twoheadmapsto","arrow.r.twohead.bar"],["twoheadrightarrow","arrow.r.twohead"],["rightwavearrow","arrow.r.wave"],["leftarrow","arrow.l"],["mapsfrom","arrow.l.bar"],["leftdowncurvedarrow","arrow.l.curve"],["leftdasharrow","arrow.l.dashed"],["leftdotarrow","arrow.l.dotted"],["Leftarrow","arrow.l.double"],["Mapsfrom","arrow.l.double.bar"],["Longleftarrow","arrow.l.double.long"],["Longmapsfrom","arrow.l.double.long.bar"],["nLeftarrow","arrow.l.double.not"],["hookleftarrow","arrow.l.hook"],["longleftarrow","arrow.l.long"],["longmapsfrom","arrow.l.long.bar"],["longleftsquigarrow","arrow.l.long.squiggly"],["looparrowleft","arrow.l.loop"],["nleftarrow","arrow.l.not"],["LLeftarrow","arrow.l.quad"],["leftsquigarrow","arrow.l.squiggly"],["barleftarrow","arrow.l.stop"],["leftwhitearrow","arrow.l.stroked"],["leftarrowtail","arrow.l.tail"],["similarleftarrow","arrow.l.tilde"],["Lleftarrow","arrow.l.triple"],["twoheadmapsfrom","arrow.l.twohead.bar"],["twoheadleftarrow","arrow.l.twohead"],["leftwavearrow","arrow.l.wave"],["uparrow","arrow.t"],["mapsup","arrow.t.bar"],["uprightcurvearrow","arrow.t.curve"],["updasharrow","arrow.t.dashed"],["Uparrow","arrow.t.double"],["UUparrow","arrow.t.quad"],["baruparrow","arrow.t.stop"],["upwhitearrow","arrow.t.stroked"],["Uuparrow","arrow.t.triple"],["twoheaduparrow","arrow.t.twohead"],["downarrow","arrow.b"],["mapsdown","arrow.b.bar"],["downrightcurvedarrow","arrow.b.curve"],["downdasharrow","arrow.b.dashed"],["Downarrow","arrow.b.double"],["DDownarrow","arrow.b.quad"],["downarrowbar","arrow.b.stop"],["downwhitearrow","arrow.b.stroked"],["Ddownarrow","arrow.b.triple"],["twoheaddownarrow","arrow.b.twohead"],["leftrightarrow","arrow.l.r"],["Leftrightarrow","arrow.l.r.double"],["Longleftrightarrow","arrow.l.r.double.long"],["nLeftrightarrow","arrow.l.r.double.not"],["longleftrightarrow","arrow.l.r.long"],["nleftrightarrow","arrow.l.r.not"],["leftrightsquigarrow","arrow.l.r.wave"],["updownarrow","arrow.t.b"],["Updownarrow","arrow.t.b.double"],["nearrow","arrow.tr"],["Nearrow","arrow.tr.double"],["hknearrow","arrow.tr.hook"],["searrow","arrow.br"],["Searrow","arrow.br.double"],["hksearrow","arrow.br.hook"],["nwarrow","arrow.tl"],["Nwarrow","arrow.tl.double"],["hknwarrow","arrow.tl.hook"],["swarrow","arrow.bl"],["Swarrow","arrow.bl.double"],["hkswarrow","arrow.bl.hook"],["nwsearrow","arrow.tl.br"],["neswarrow","arrow.tr.bl"],["acwopencirclearrow","arrow.ccw"],["curvearrowleft","arrow.ccw.half"],["cwopencirclearrow","arrow.cw"],["curvearrowright","arrow.cw.half"],["downzigzagarrow","arrow.zigzag"],["rightrightarrows","arrows.rr"],["leftleftarrows","arrows.ll"],["upuparrows","arrows.tt"],["downdownarrows","arrows.bb"],["leftrightarrows","arrows.lr"],["barleftarrowrightarrowbar","arrows.lr.stop"],["rightleftarrows","arrows.rl"],["updownarrows","arrows.tb"],["downuparrows","arrows.bt"],["rightthreearrows","arrows.rrr"],["leftthreearrows","arrows.lll"],["rightharpoonup","harpoon.rt"],["barrightharpoonup","harpoon.rt.bar"],["rightharpoonupbar","harpoon.rt.stop"],["rightharpoondown","harpoon.rb"],["barrightharpoondown","harpoon.rb.bar"],["rightharpoondownbar","harpoon.rb.stop"],["leftharpoonup","harpoon.lt"],["leftharpoonupbar","harpoon.lt.bar"],["barleftharpoonup","harpoon.lt.stop"],["leftharpoondown","harpoon.lb"],["leftharpoondownbar","harpoon.lb.bar"],["barleftharpoondown","harpoon.lb.stop"],["upharpoonleft","harpoon.tl"],["upharpoonleftbar","harpoon.tl.bar"],["barupharpoonleft","harpoon.tl.stop"],["upharpoonright","harpoon.tr"],["upharpoonrightbar","harpoon.tr.bar"],["barupharpoonright","harpoon.tr.stop"],["downharpoonleft","harpoon.bl"],["bardownharpoonleft","harpoon.bl.bar"],["downharpoonleftbar","harpoon.bl.stop"],["downharpoonright","harpoon.br"],["bardownharpoonright","harpoon.br.bar"],["downharpoonrightbar","harpoon.br.stop"],["leftrightharpoonupup","harpoon.lt.rt"],["leftrightharpoondowndown","harpoon.lb.rb"],["leftrightharpoondownup","harpoon.lb.rt"],["leftrightharpoonupdown","harpoon.lt.rb"],["updownharpoonleftleft","harpoon.tl.bl"],["updownharpoonrightright","harpoon.tr.br"],["updownharpoonleftright","harpoon.tl.br"],["updownharpoonrightleft","harpoon.tr.bl"],["rightharpoonsupdown","harpoons.rtrb"],["downharpoonsleftright","harpoons.blbr"],["downupharpoonsleftright","harpoons.bltr"],["leftrightharpoonsdown","harpoons.lbrb"],["leftharpoonsupdown","harpoons.ltlb"],["leftrightharpoons","harpoons.ltrb"],["leftrightharpoonsup","harpoons.ltrt"],["rightleftharpoonsdown","harpoons.rblb"],["rightleftharpoons","harpoons.rtlb"],["rightleftharpoonsup","harpoons.rtlt"],["updownharpoonsleftright","harpoons.tlbr"],["upharpoonsleftright","harpoons.tltr"],["vdash","tack.r"],["nvdash","tack.r.not"],["vlongdash","tack.r.long"],["assert","tack.r.short"],["vDash","tack.r.double"],["nvDash","tack.r.double.not"],["dashv","tack.l"],["longdashv","tack.l.long"],["shortlefttack","tack.l.short"],["Dashv","tack.l.double"],["bigbot","tack.t.big"],["Vbar","tack.t.double"],["shortuptack","tack.t.short"],["bigtop","tack.b.big"],["barV","tack.b.double"],["shortdowntack","tack.b.short"],["dashVdash","tack.l.r"],["BbbA","AA"],["BbbB","BB"],["BbbC","CC"],["BbbD","DD"],["BbbE","EE"],["BbbF","FF"],["BbbG","GG"],["BbbH","HH"],["BbbI","II"],["BbbJ","JJ"],["BbbK","KK"],["BbbL","LL"],["BbbM","MM"],["BbbN","NN"],["BbbO","OO"],["BbbP","PP"],["BbbQ","QQ"],["BbbR","RR"],["BbbS","SS"],["BbbT","TT"],["BbbU","UU"],["BbbV","VV"],["BbbW","WW"],["BbbX","XX"],["BbbY","YY"],["BbbZ","ZZ"],["ell","ell"],["Planckconst","planck"],["hslash","planck.reduce"],["Angstrom","angstrom"],["Re","Re"],["Im","Im"],["imath","dotless.i"],["jmath","dotless.j"]]);for(let[q,J]of D2)if(!B.has(q))B.set(q,J);var R=new Map;for(let[q,J]of Array.from(B.entries()).reverse())R.set(J,q);R.set("dif","mathrm{d}");var U2=new Map([["top","top"],["frac","frac"],["tilde","tilde"],["hat","hat"],["upright","mathrm"],["bold","boldsymbol"]]);for(let[q,J]of U2)R.set(q,J);function t(q,J,z=0){for(let V=z;V<q.length;V++)if(q[V].eq(J))return V;return-1}function w(q,J){for(let z of q)if(z.eq(J))return!0;return!1}function c(q,J){let z=[],V=[];for(let Z of q)if(Z.eq(J))z.push(V),V=[];else V.push(Z);return z.push(V),z}class j{type;value;constructor(q,J){this.type=q,this.value=J}eq(q){return this.type===q.type&&this.value===q.value}toString(){switch(this.type){case 2:return`\\text{${this.value}}`;case 3:return`%${this.value}`;default:return this.value}}}function O2(q){if(["{","}","%"].includes(q))return"\\"+q;return q}class ${type;content;args;data;constructor(q,J,z,V){this.type=q,this.content=J,this.args=z,this.data=V}eq(q){return this.type===q.type&&this.content===q.content}toString(){switch(this.type){case"text":return`\\text{${this.content}}`;default:throw new Error(`toString() is not implemented for type ${this.type}`)}}serialize(){switch(this.type){case"empty":return[];case"element":{let q=this.content;return q=O2(q),[new j(0,q)]}case"symbol":return[new j(1,this.content)];case"text":return[new j(2,this.content)];case"comment":return[new j(3,this.content)];case"whitespace":{let q=[];for(let J of this.content){let z=J===" "?4:5;q.push(new j(z,J))}return q}case"ordgroup":return this.args.map((q)=>q.serialize()).flat();case"unaryFunc":{let q=[];if(q.push(new j(1,this.content)),this.content==="\\sqrt"&&this.data)q.push(new j(0,"[")),q=q.concat(this.data.serialize()),q.push(new j(0,"]"));if(this.content==="\\operatorname"&&this.args.length===1&&this.args[0].type==="text"){let J=this.args[0].content;return q.push(new j(0,"{")),q.push(new j(1,J)),q.push(new j(0,"}")),q}return q.push(new j(0,"{")),q=q.concat(this.args[0].serialize()),q.push(new j(0,"}")),q}case"binaryFunc":{let q=[];return q.push(new j(1,this.content)),q.push(new j(0,"{")),q=q.concat(this.args[0].serialize()),q.push(new j(0,"}")),q.push(new j(0,"{")),q=q.concat(this.args[1].serialize()),q.push(new j(0,"}")),q}case"supsub":{let q=[],{base:J,sup:z,sub:V}=this.data;if(q=q.concat(J.serialize()),V)if(q.push(new j(6,"_")),V.type==="ordgroup"||V.type==="supsub"||V.type==="empty")q.push(new j(0,"{")),q=q.concat(V.serialize()),q.push(new j(0,"}"));else q=q.concat(V.serialize());if(z)if(q.push(new j(6,"^")),z.type==="ordgroup"||z.type==="supsub"||z.type==="empty")q.push(new j(0,"{")),q=q.concat(z.serialize()),q.push(new j(0,"}"));else q=q.concat(z.serialize());return q}case"control":return[new j(6,this.content)];case"beginend":{let q=[],J=this.data;q.push(new j(1,`\\begin{${this.content}}`)),q.push(new j(5,`
|
|
2
|
-
`));for(let z=0;z<J.length;z++){let V=J[z];for(let Z=0;Z<V.length;Z++){let X=V[Z];if(q=q.concat(X.serialize()),Z!==V.length-1)q.push(new
|
|
3
|
-
`)),q.push(new
|
|
4
|
-
`)X+=1;Z=new
|
|
5
|
-
`:Z=new
|
|
6
|
-
`)Z=new
|
|
7
|
-
`),z+=2;else Z=new
|
|
8
|
-
`),z++;break}case" ":{let X=z;while(X<q.length&&q[X]===" ")X+=1;Z=new
|
|
9
|
-
`)continue}if(X.type==="control"&&X.content==="&")throw new H("Unexpected & outside of an alignment");V.push(X)}if(V.length===0)return
|
|
10
|
-
`)continue}if(X.type==="control"&&X.content==="\\\\")V=[],Z=new
|
|
11
|
-
`);class
|
|
12
|
-
`),z||=this.buffer==="",z||=/^\s/.test(J),z||=this.buffer.endsWith("&")&&J==="=",z||=/[\s_^{\(]$/.test(this.buffer),!z)this.buffer+=" ";this.buffer+=J}serialize(q){switch(q.type){case"empty":break;case"atom":{if(q.content===","&&this.insideFunctionDepth>0)this.queue.push(new
|
|
13
|
-
`)this.queue.push(new
|
|
14
|
-
`:Z=new
|
|
15
|
-
`)Z=new
|
|
16
|
-
`),z+=2;else Z=new
|
|
17
|
-
`),z++;break}case" ":{let X=z;while(X<q.length&&q[X]===" ")X++;Z=new
|
|
18
|
-
`)X++;Z=new
|
|
19
|
-
`)continue}Z.push(
|
|
1
|
+
var I=new Map([["nonumber",""],["vec","arrow"],["neq","eq.not"],["dot","dot"],["ddot","dot.double"],["doteq","dot(eq)"],["dots","dots.h"],["vdots","dots.v"],["ddots","dots.down"],["widehat","hat"],["widetilde","tilde"],["quad","quad"],["qquad","wide"],["overbrace","overbrace"],["underbrace","underbrace"],["overline","overline"],["underline","underline"],["bar","macron"],["dbinom","binom"],["tbinom","binom"],["dfrac","frac"],["tfrac","frac"],["operatorname","op"],["boldsymbol","bold"],["mathbb","bb"],["mathbf","bold"],["mathcal","cal"],["mathit","italic"],["mathfrak","frak"],["mathrm","upright"],["mathsf","sans"],["mathtt","mono"],["rm","upright"],["pmb","bold"],["pm","plus.minus"],["mp","minus.plus"],["boxplus","plus.square"],["otimes","times.circle"],["boxtimes","times.square"],["approx","approx"],["cong","tilde.equiv"],["simeq","tilde.eq"],["asymp","≍"],["equiv","equiv"],["propto","prop"],["gets","arrow.l"],["hookleftarrow","arrow.l.hook"],["leftharpoonup","harpoon.lt"],["leftharpoondown","harpoon.lb"],["rightleftharpoons","harpoons.rtlb"],["longleftarrow","arrow.l.long"],["longrightarrow","arrow.r.long"],["longleftrightarrow","arrow.l.r.long"],["Longleftarrow","arrow.l.double.long"],["Longrightarrow","arrow.r.double.long"],["Longleftrightarrow","arrow.l.r.double.long"],["hookrightarrow","arrow.r.hook"],["rightharpoonup","harpoon.rt"],["rightharpoondown","harpoon.rb"],["iff","arrow.l.r.double.long"],["implies","arrow.r.double.long"],["uparrow","arrow.t"],["downarrow","arrow.b"],["updownarrow","arrow.t.b"],["Uparrow","arrow.t.double"],["Downarrow","arrow.b.double"],["Updownarrow","arrow.t.b.double"],["nearrow","arrow.tr"],["searrow","arrow.br"],["swarrow","arrow.bl"],["nwarrow","arrow.tl"],["leadsto","arrow.squiggly"],["leftleftarrows","arrows.ll"],["rightrightarrows","arrows.rr"],["Cap","sect.double"],["Cup","union.double"],["Delta","Delta"],["Gamma","Gamma"],["Join","join"],["Lambda","Lambda"],["Leftarrow","arrow.l.double"],["Leftrightarrow","arrow.l.r.double"],["Longrightarrow","arrow.r.double.long"],["Omega","Omega"],["P","pilcrow"],["Phi","Phi"],["Pi","Pi"],["Psi","Psi"],["Rightarrow","arrow.r.double"],["S","section"],["Sigma","Sigma"],["Theta","Theta"],["aleph","alef"],["alpha","alpha"],["angle","angle"],["approx","approx"],["approxeq","approx.eq"],["beta","beta"],["bigcap","sect.big"],["bigcirc","circle.big"],["bigcup","union.big"],["bigodot","dot.circle.big"],["bigotimes","times.circle.big"],["bigsqcup","union.sq.big"],["biguplus","union.plus.big"],["bigvee","or.big"],["bigwedge","and.big"],["bullet","bullet"],["cap","sect"],["cdot","dot.op"],["cdots","dots.c"],["checkmark","checkmark"],["chi","chi"],["circ","circle.small"],["colon","colon"],["cong","tilde.equiv"],["coprod","product.co"],["copyright","copyright"],["cup","union"],["curlyvee","or.curly"],["curlywedge","and.curly"],["dagger","dagger"],["dashv","tack.l"],["ddagger","dagger.double"],["delta","delta"],["ddots","dots.down"],["diamond","diamond"],["div","div"],["divideontimes","times.div"],["dotplus","plus.dot"],["downarrow","arrow.b"],["ell","ell"],["emptyset","nothing"],["epsilon","epsilon.alt"],["equiv","equiv"],["eta","eta"],["exists","exists"],["forall","forall"],["gamma","gamma"],["ge","gt.eq"],["geq","gt.eq"],["geqslant","gt.eq.slant"],["gg","gt.double"],["hbar","planck.reduce"],["imath","dotless.i"],["iiiint","integral.quad"],["iiint","integral.triple"],["iint","integral.double"],["in","in"],["infty","infinity"],["int","integral"],["intercal","top"],["iota","iota"],["jmath","dotless.j"],["kappa","kappa"],["lambda","lambda"],["land","and"],["langle","angle.l"],["lbrace","brace.l"],["lbrack","bracket.l"],["ldots","dots.h"],["le","lt.eq"],["leadsto","arrow.squiggly"],["leftarrow","arrow.l"],["leftthreetimes","times.three.l"],["leftrightarrow","arrow.l.r"],["leq","lt.eq"],["leqslant","lt.eq.slant"],["lhd","triangle.l"],["ll","lt.double"],["lor","or"],["ltimes","times.l"],["measuredangle","angle.arc"],["mid","divides"],["models","models"],["mp","minus.plus"],["mu","mu"],["nabla","nabla"],["ncong","tilde.equiv.not"],["ne","eq.not"],["neg","not"],["neq","eq.not"],["nexists","exists.not"],["ni","in.rev"],["nleftarrow","arrow.l.not"],["nleq","lt.eq.not"],["nparallel","parallel.not"],["ngeq","gt.eq.not"],["nmid","divides.not"],["notin","in.not"],["nsim","tilde.not"],["nsubseteq","subset.eq.not"],["nu","nu"],["ntriangleleft","lt.tri.not"],["ntriangleright","gt.tri.not"],["nwarrow","arrow.tl"],["odot","dot.circle"],["oint","integral.cont"],["oiint","integral.surf"],["oiiint","integral.vol"],["omega","omega"],["ominus","minus.circle"],["otimes","times.circle"],["parallel","parallel"],["partial","diff"],["perp","perp"],["phi","phi.alt"],["pi","pi"],["pm","plus.minus"],["pounds","pound"],["prec","prec"],["preceq","prec.eq"],["prime","prime"],["prod","product"],["propto","prop"],["psi","psi"],["rangle","angle.r"],["rbrace","brace.r"],["rbrack","bracket.r"],["rhd","triangle"],["rho","rho"],["rightarrow","arrow.r"],["rightthreetimes","times.three.r"],["rtimes","times.r"],["setminus","without"],["sigma","sigma"],["sim","tilde.op"],["simeq","tilde.eq"],["slash","slash"],["smallsetminus","without"],["spadesuit","suit.spade"],["sqcap","sect.sq"],["sqcup","union.sq"],["sqsubseteq","subset.eq.sq"],["sqsupseteq","supset.eq.sq"],["subset","subset"],["subseteq","subset.eq"],["subsetneq","subset.neq"],["succ","succ"],["succeq","succ.eq"],["sum","sum"],["supset","supset"],["supseteq","supset.eq"],["supsetneq","supset.neq"],["swarrow","arrow.bl"],["tau","tau"],["theta","theta"],["times","times"],["to","arrow.r"],["top","top"],["triangle","triangle.t"],["twoheadrightarrow","arrow.r.twohead"],["uparrow","arrow.t"],["updownarrow","arrow.t.b"],["upharpoonright","harpoon.tr"],["uplus","union.plus"],["upsilon","upsilon"],["varepsilon","epsilon"],["varnothing","diameter"],["varphi","phi"],["varpi","pi.alt"],["varrho","rho.alt"],["varsigma","sigma.alt"],["vartheta","theta.alt"],["vdash","tack.r"],["vdots","dots.v"],["vee","or"],["wedge","and"],["wr","wreath"],["xi","xi"],["yen","yen"],["zeta","zeta"],["mathscr","scr"],["LaTeX","#LaTeX"],["TeX","#TeX"]]),A2=new Map([["lparen","paren.l"],["lParen","paren.l.double"],["rparen","paren.r"],["rParen","paren.r.double"],["overparen","paren.t"],["underparen","paren.b"],["lbrace","brace.l"],["lBrace","brace.l.double"],["rbrace","brace.r"],["rBrace","brace.r.double"],["underbrace","brace.b"],["lbrack","bracket.l"],["lBrack","bracket.l.double"],["rbrack","bracket.r"],["rBrack","bracket.r.double"],["overbracket","bracket.t"],["underbracket","bracket.b"],["lbrbrak","shell.l"],["Lbrbrak","shell.l.double"],["rbrbrak","shell.r"],["Rbrbrak","shell.r.double"],["obrbrak","shell.t"],["ubrbrak","shell.b"],["vert","bar.v"],["Vert","bar.v.double"],["Vvert","bar.v.triple"],["circledvert","bar.v.circle"],["horizbar","bar.h"],["lvzigzag","fence.l"],["Lvzigzag","fence.l.double"],["rvzigzag","fence.r"],["Rvzigzag","fence.r.double"],["fourvdots","fence.dotted"],["angle","angle"],["langle","angle.l"],["lcurvyangle","angle.l.curly"],["langledot","angle.l.dot"],["rangle","angle.r"],["rcurvyangle","angle.r.curly"],["rangledot","angle.r.dot"],["angdnr","angle.acute"],["measuredangle","angle.arc"],["measuredangleleft","angle.arc.rev"],["wideangledown","angle.oblique"],["revangle","angle.rev"],["rightangle","angle.right"],["measuredrightangle","angle.right.arc"],["rightanglemdot","angle.right.dot"],["rightanglesqr","angle.right.sq"],["angles","angle.s"],["threedangle","angle.spatial"],["sphericalangle","angle.spheric"],["gtlpar","angle.spheric.rev"],["sphericalangleup","angle.spheric.top"],["lceil","ceil.l"],["rceil","ceil.r"],["lfloor","floor.l"],["rfloor","floor.r"],["mathampersand","amp"],["upand","amp.inv"],["ast","ast.op"],["circledast","ast.circle"],["boxast","ast.square"],["mathatsign","at"],["backslash","backslash"],["obslash","backslash.circle"],["rsolbar","backslash.not"],["mathcolon","colon"],["Colon","colon.double"],["coloneq","colon.eq"],["Coloneq","colon.double.eq"],["mathcomma","comma"],["dagger","dagger"],["ddagger","dagger.double"],["dashcolon","dash.colon"],["circleddash","dash.circle"],["hzigzag","dash.wave.double"],["cdot","dot.op"],["mathperiod","dot.basic"],["cdotp","dot.c"],["odot","dot.circle"],["bigodot","dot.circle.big"],["boxdot","dot.square"],["dddot","dot.triple"],["ddddot","dot.quad"],["mathexclam","excl"],["Exclam","excl.double"],["mathquestion","quest"],["Question","quest.double"],["mathoctothorpe","hash"],["mathpercent","percent"],["mathparagraph","pilcrow"],["mathsection","section"],["mathsemicolon","semi"],["mathslash","slash"],["sslash","slash.double"],["trslash","slash.triple"],["xsol","slash.big"],["unicodecdots","dots.h.c"],["unicodeellipsis","dots.h"],["vdots","dots.v"],["ddots","dots.down"],["adots","dots.up"],["sim","tilde.op"],["dotsim","tilde.dot"],["sime","tilde.eq"],["nsimeq","tilde.eq.not"],["backsimeq","tilde.eq.rev"],["cong","tilde.equiv"],["ncong","tilde.equiv.not"],["simneqq","tilde.nequiv"],["nsim","tilde.not"],["backsim","tilde.rev"],["backcong","tilde.rev.equiv"],["approxident","tilde.triple"],["caretinsert","caret"],["prime","prime"],["backprime","prime.rev"],["dprime","prime.double"],["backdprime","prime.double.rev"],["trprime","prime.triple"],["backtrprime","prime.triple.rev"],["qprime","prime.quad"],["mathplus","plus"],["oplus","plus.circle"],["rightarrowonoplus","plus.circle.arrow"],["bigoplus","plus.circle.big"],["dotplus","plus.dot"],["doubleplus","plus.double"],["pm","plus.minus"],["boxplus","plus.square"],["triangleplus","plus.triangle"],["tripleplus","plus.triple"],["minus","minus"],["ominus","minus.circle"],["dotminus","minus.dot"],["mp","minus.plus"],["boxminus","minus.square"],["eqsim","minus.tilde"],["triangleminus","minus.triangle"],["div","div"],["odiv","div.circle"],["times","times"],["bigtimes","times.big"],["otimes","times.circle"],["bigotimes","times.circle.big"],["divideontimes","times.div"],["leftthreetimes","times.three.l"],["rightthreetimes","times.three.r"],["ltimes","times.l"],["rtimes","times.r"],["boxtimes","times.square"],["triangletimes","times.triangle"],["mathratio","ratio"],["equal","eq"],["stareq","eq.star"],["circledequal","eq.circle"],["eqcolon","eq.colon"],["eqdef","eq.def"],["triangleq","eq.delta"],["veeeq","eq.equi"],["wedgeq","eq.est"],["eqgtr","eq.gt"],["eqless","eq.lt"],["measeq","eq.m"],["ne","eq.not"],["curlyeqprec","eq.prec"],["questeq","eq.quest"],["curlyeqsucc","eq.succ"],["equiv","eq.triple"],["Equiv","eq.quad"],["greater","gt"],["ogreaterthan","gt.circle"],["gtrdot","gt.dot"],["gtrapprox","gt.approx"],["gg","gt.double"],["geq","gt.eq"],["geqslant","gt.eq.slant"],["gtreqless","gt.eq.lt"],["ngeq","gt.eq.not"],["geqq","gt.equiv"],["gtrless","gt.lt"],["ngtrless","gt.lt.not"],["gneq","gt.neq"],["gnapprox","gt.napprox"],["gneqq","gt.nequiv"],["ngtr","gt.not"],["gnsim","gt.ntilde"],["gtrsim","gt.tilde"],["ngtrsim","gt.tilde.not"],["vartriangleright","gt.tri"],["trianglerighteq","gt.tri.eq"],["ntrianglerighteq","gt.tri.eq.not"],["nvartriangleright","gt.tri.not"],["ggg","gt.triple"],["gggnest","gt.triple.nested"],["less","lt"],["olessthan","lt.circle"],["lessdot","lt.dot"],["lessapprox","lt.approx"],["ll","lt.double"],["leq","lt.eq"],["leqslant","lt.eq.slant"],["lesseqgtr","lt.eq.gt"],["nleq","lt.eq.not"],["leqq","lt.equiv"],["lessgtr","lt.gt"],["nlessgtr","lt.gt.not"],["lneq","lt.neq"],["lnapprox","lt.napprox"],["lneqq","lt.nequiv"],["nless","lt.not"],["lnsim","lt.ntilde"],["lesssim","lt.tilde"],["nlesssim","lt.tilde.not"],["vartriangleleft","lt.tri"],["trianglelefteq","lt.tri.eq"],["ntrianglelefteq","lt.tri.eq.not"],["nvartriangleleft","lt.tri.not"],["lll","lt.triple"],["lllnest","lt.triple.nested"],["approx","approx"],["approxeq","approx.eq"],["napprox","approx.not"],["prec","prec"],["precapprox","prec.approx"],["preccurlyeq","prec.curly.eq"],["npreccurlyeq","prec.curly.eq.not"],["Prec","prec.double"],["preceq","prec.eq"],["preceqq","prec.equiv"],["precnapprox","prec.napprox"],["precneq","prec.neq"],["precneqq","prec.nequiv"],["nprec","prec.not"],["precnsim","prec.ntilde"],["precsim","prec.tilde"],["succ","succ"],["succapprox","succ.approx"],["succcurlyeq","succ.curly.eq"],["nsucccurlyeq","succ.curly.eq.not"],["Succ","succ.double"],["succeq","succ.eq"],["succeqq","succ.equiv"],["succnapprox","succ.napprox"],["succneq","succ.neq"],["succneqq","succ.nequiv"],["nsucc","succ.not"],["succnsim","succ.ntilde"],["succsim","succ.tilde"],["nequiv","equiv.not"],["propto","prop"],["origof","original"],["imageof","image"],["varnothing","emptyset"],["emptysetoarr","emptyset.arrow.r"],["emptysetoarrl","emptyset.arrow.l"],["emptysetobar","emptyset.bar"],["emptysetocirc","emptyset.circle"],["revemptyset","emptyset.rev"],["setminus","without"],["complement","complement"],["in","in"],["notin","in.not"],["ni","in.rev"],["nni","in.rev.not"],["smallni","in.rev.small"],["smallin","in.small"],["subset","subset"],["subsetdot","subset.dot"],["Subset","subset.double"],["subseteq","subset.eq"],["nsubseteq","subset.eq.not"],["sqsubseteq","subset.eq.sq"],["nsqsubseteq","subset.eq.sq.not"],["subsetneq","subset.neq"],["nsubset","subset.not"],["sqsubset","subset.sq"],["sqsubsetneq","subset.sq.neq"],["supset","supset"],["supsetdot","supset.dot"],["Supset","supset.double"],["supseteq","supset.eq"],["nsupseteq","supset.eq.not"],["sqsupseteq","supset.eq.sq"],["nsqsupseteq","supset.eq.sq.not"],["supsetneq","supset.neq"],["nsupset","supset.not"],["sqsupset","supset.sq"],["sqsupsetneq","supset.sq.neq"],["cup","union"],["cupleftarrow","union.arrow"],["bigcup","union.big"],["cupdot","union.dot"],["bigcupdot","union.dot.big"],["Cup","union.double"],["uminus","union.minus"],["cupvee","union.or"],["uplus","union.plus"],["biguplus","union.plus.big"],["sqcup","union.sq"],["bigsqcup","union.sq.big"],["Sqcup","union.sq.double"],["cap","sect"],["capwedge","sect.and"],["bigcap","sect.big"],["capdot","sect.dot"],["Cap","sect.double"],["sqcap","sect.sq"],["bigsqcap","sect.sq.big"],["Sqcap","sect.sq.double"],["infty","infinity"],["nvinfty","infinity.bar"],["iinfin","infinity.incomplete"],["tieinfty","infinity.tie"],["partial","diff"],["nabla","gradient"],["sum","sum"],["sumint","sum.integral"],["prod","product"],["coprod","product.co"],["int","integral"],["intlarhk","integral.arrow.hook"],["awint","integral.ccw"],["oint","integral.cont"],["ointctrclockwise","integral.cont.ccw"],["varointclockwise","integral.cont.cw"],["intclockwise","integral.cw"],["intbar","integral.dash"],["intBar","integral.dash.double"],["iint","integral.double"],["iiiint","integral.quad"],["intcap","integral.sect"],["fint","integral.slash"],["sqint","integral.square"],["oiint","integral.surf"],["intx","integral.times"],["iiint","integral.triple"],["intcup","integral.union"],["oiiint","integral.vol"],["increment","laplace"],["forall","forall"],["exists","exists"],["nexists","exists.not"],["top","top"],["bot","bot"],["neg","not"],["wedge","and"],["bigwedge","and.big"],["curlywedge","and.curly"],["wedgedot","and.dot"],["Wedge","and.double"],["vee","or"],["bigvee","or.big"],["curlyvee","or.curly"],["veedot","or.dot"],["Vee","or.double"],["models","models"],["Vdash","forces"],["nVdash","forces.not"],["therefore","therefore"],["because","because"],["QED","qed"],["vysmwhtcircle","compose"],["multimap","multimap"],["dualmap","multimap.double"],["tplus","tiny"],["tminus","miny"],["mid","divides"],["nmid","divides.not"],["wr","wreath"],["parallel","parallel"],["nhpar","parallel.struck"],["circledparallel","parallel.circle"],["equalparallel","parallel.eq"],["equivVert","parallel.equiv"],["nparallel","parallel.not"],["eparsl","parallel.slanted.eq"],["smeparsl","parallel.slanted.eq.tilde"],["eqvparsl","parallel.slanted.equiv"],["parsim","parallel.tilde"],["perp","perp"],["operp","perp.circle"],["diameter","diameter"],["Join","join"],["rightouterjoin","join.r"],["leftouterjoin","join.l"],["fullouterjoin","join.l.r"],["smashtimes","smash"],["mathdollar","dollar"],["euro","euro"],["mathsterling","pound"],["mathyen","yen"],["checkmark","checkmark"],["maltese","maltese"],["clubsuit","suit.club.filled"],["varclubsuit","suit.club.stroked"],["vardiamondsuit","suit.diamond.filled"],["diamondsuit","suit.diamond.stroked"],["varheartsuit","suit.heart.filled"],["heartsuit","suit.heart.stroked"],["spadesuit","suit.spade.filled"],["varspadesuit","suit.spade.stroked"],["quarternote","note.quarter.alt"],["eighthnote","note.eighth.alt"],["twonotes","note.eighth.beamed"],["natural","natural"],["flat","flat"],["sharp","sharp"],["smblkcircle","bullet"],["mdlgwhtcircle","circle.stroked"],["mdsmwhtcircle","circle.stroked.small"],["lgwhtcircle","circle.stroked.big"],["mdlgblkcircle","circle.filled"],["mdsmblkcircle","circle.filled.tiny"],["vysmblkcircle","circle.filled.small"],["lgblkcircle","circle.filled.big"],["dottedcircle","circle.dotted"],["circledcirc","circle.nested"],["whthorzoval","ellipse.stroked.h"],["whtvertoval","ellipse.stroked.v"],["blkhorzoval","ellipse.filled.h"],["blkvertoval","ellipse.filled.v"],["bigtriangleup","triangle.stroked.t"],["bigtriangledown","triangle.stroked.b"],["triangleright","triangle.stroked.r"],["triangleleft","triangle.stroked.l"],["lltriangle","triangle.stroked.bl"],["lrtriangle","triangle.stroked.br"],["ultriangle","triangle.stroked.tl"],["urtriangle","triangle.stroked.tr"],["vartriangle","triangle.stroked.small.t"],["triangledown","triangle.stroked.small.b"],["smalltriangleright","triangle.stroked.small.r"],["smalltriangleleft","triangle.stroked.small.l"],["whiteinwhitetriangle","triangle.stroked.nested"],["trianglecdot","triangle.stroked.dot"],["bigblacktriangleup","triangle.filled.t"],["bigblacktriangledown","triangle.filled.b"],["blacktriangleright","triangle.filled.r"],["blacktriangleleft","triangle.filled.l"],["llblacktriangle","triangle.filled.bl"],["lrblacktriangle","triangle.filled.br"],["ulblacktriangle","triangle.filled.tl"],["urblacktriangle","triangle.filled.tr"],["blacktriangle","triangle.filled.small.t"],["blacktriangledown","triangle.filled.small.b"],["smallblacktriangleright","triangle.filled.small.r"],["smallblacktriangleleft","triangle.filled.small.l"],["mdlgwhtsquare","square.stroked"],["smwhtsquare","square.stroked.tiny"],["mdsmwhtsquare","square.stroked.small"],["mdwhtsquare","square.stroked.medium"],["lgwhtsquare","square.stroked.big"],["dottedsquare","square.stroked.dotted"],["squoval","square.stroked.rounded"],["mdlgblksquare","square.filled"],["smblksquare","square.filled.tiny"],["mdsmblksquare","square.filled.small"],["mdblksquare","square.filled.medium"],["lgblksquare","square.filled.big"],["hrectangle","rect.stroked.h"],["vrectangle","rect.stroked.v"],["hrectangleblack","rect.filled.h"],["vrectangleblack","rect.filled.v"],["pentagon","penta.stroked"],["pentagonblack","penta.filled"],["varhexagon","hexa.stroked"],["varhexagonblack","hexa.filled"],["mdlgwhtdiamond","diamond.stroked"],["smwhtdiamond","diamond.stroked.small"],["mdwhtdiamond","diamond.stroked.medium"],["diamondcdot","diamond.stroked.dot"],["mdlgblkdiamond","diamond.filled"],["mdblkdiamond","diamond.filled.medium"],["smblkdiamond","diamond.filled.small"],["mdlgwhtlozenge","lozenge.stroked"],["smwhtlozenge","lozenge.stroked.small"],["mdwhtlozenge","lozenge.stroked.medium"],["mdlgblklozenge","lozenge.filled"],["smblklozenge","lozenge.filled.small"],["mdblklozenge","lozenge.filled.medium"],["parallelogram","parallelogram.stroked"],["parallelogramblack","parallelogram.filled"],["star","star.op"],["bigwhitestar","star.stroked"],["bigstar","star.filled"],["rightarrow","arrow.r"],["longmapsto","arrow.r.long.bar"],["mapsto","arrow.r.bar"],["rightdowncurvedarrow","arrow.r.curve"],["rightdasharrow","arrow.r.dashed"],["rightdotarrow","arrow.r.dotted"],["Rightarrow","arrow.r.double"],["Mapsto","arrow.r.double.bar"],["Longrightarrow","arrow.r.double.long"],["Longmapsto","arrow.r.double.long.bar"],["nRightarrow","arrow.r.double.not"],["hookrightarrow","arrow.r.hook"],["longrightarrow","arrow.r.long"],["longrightsquigarrow","arrow.r.long.squiggly"],["looparrowright","arrow.r.loop"],["nrightarrow","arrow.r.not"],["RRightarrow","arrow.r.quad"],["rightsquigarrow","arrow.r.squiggly"],["rightarrowbar","arrow.r.stop"],["rightwhitearrow","arrow.r.stroked"],["rightarrowtail","arrow.r.tail"],["similarrightarrow","arrow.r.tilde"],["Rrightarrow","arrow.r.triple"],["twoheadmapsto","arrow.r.twohead.bar"],["twoheadrightarrow","arrow.r.twohead"],["rightwavearrow","arrow.r.wave"],["leftarrow","arrow.l"],["mapsfrom","arrow.l.bar"],["leftdowncurvedarrow","arrow.l.curve"],["leftdasharrow","arrow.l.dashed"],["leftdotarrow","arrow.l.dotted"],["Leftarrow","arrow.l.double"],["Mapsfrom","arrow.l.double.bar"],["Longleftarrow","arrow.l.double.long"],["Longmapsfrom","arrow.l.double.long.bar"],["nLeftarrow","arrow.l.double.not"],["hookleftarrow","arrow.l.hook"],["longleftarrow","arrow.l.long"],["longmapsfrom","arrow.l.long.bar"],["longleftsquigarrow","arrow.l.long.squiggly"],["looparrowleft","arrow.l.loop"],["nleftarrow","arrow.l.not"],["LLeftarrow","arrow.l.quad"],["leftsquigarrow","arrow.l.squiggly"],["barleftarrow","arrow.l.stop"],["leftwhitearrow","arrow.l.stroked"],["leftarrowtail","arrow.l.tail"],["similarleftarrow","arrow.l.tilde"],["Lleftarrow","arrow.l.triple"],["twoheadmapsfrom","arrow.l.twohead.bar"],["twoheadleftarrow","arrow.l.twohead"],["leftwavearrow","arrow.l.wave"],["uparrow","arrow.t"],["mapsup","arrow.t.bar"],["uprightcurvearrow","arrow.t.curve"],["updasharrow","arrow.t.dashed"],["Uparrow","arrow.t.double"],["UUparrow","arrow.t.quad"],["baruparrow","arrow.t.stop"],["upwhitearrow","arrow.t.stroked"],["Uuparrow","arrow.t.triple"],["twoheaduparrow","arrow.t.twohead"],["downarrow","arrow.b"],["mapsdown","arrow.b.bar"],["downrightcurvedarrow","arrow.b.curve"],["downdasharrow","arrow.b.dashed"],["Downarrow","arrow.b.double"],["DDownarrow","arrow.b.quad"],["downarrowbar","arrow.b.stop"],["downwhitearrow","arrow.b.stroked"],["Ddownarrow","arrow.b.triple"],["twoheaddownarrow","arrow.b.twohead"],["leftrightarrow","arrow.l.r"],["Leftrightarrow","arrow.l.r.double"],["Longleftrightarrow","arrow.l.r.double.long"],["nLeftrightarrow","arrow.l.r.double.not"],["longleftrightarrow","arrow.l.r.long"],["nleftrightarrow","arrow.l.r.not"],["leftrightsquigarrow","arrow.l.r.wave"],["updownarrow","arrow.t.b"],["Updownarrow","arrow.t.b.double"],["nearrow","arrow.tr"],["Nearrow","arrow.tr.double"],["hknearrow","arrow.tr.hook"],["searrow","arrow.br"],["Searrow","arrow.br.double"],["hksearrow","arrow.br.hook"],["nwarrow","arrow.tl"],["Nwarrow","arrow.tl.double"],["hknwarrow","arrow.tl.hook"],["swarrow","arrow.bl"],["Swarrow","arrow.bl.double"],["hkswarrow","arrow.bl.hook"],["nwsearrow","arrow.tl.br"],["neswarrow","arrow.tr.bl"],["acwopencirclearrow","arrow.ccw"],["curvearrowleft","arrow.ccw.half"],["cwopencirclearrow","arrow.cw"],["curvearrowright","arrow.cw.half"],["downzigzagarrow","arrow.zigzag"],["rightrightarrows","arrows.rr"],["leftleftarrows","arrows.ll"],["upuparrows","arrows.tt"],["downdownarrows","arrows.bb"],["leftrightarrows","arrows.lr"],["barleftarrowrightarrowbar","arrows.lr.stop"],["rightleftarrows","arrows.rl"],["updownarrows","arrows.tb"],["downuparrows","arrows.bt"],["rightthreearrows","arrows.rrr"],["leftthreearrows","arrows.lll"],["rightharpoonup","harpoon.rt"],["barrightharpoonup","harpoon.rt.bar"],["rightharpoonupbar","harpoon.rt.stop"],["rightharpoondown","harpoon.rb"],["barrightharpoondown","harpoon.rb.bar"],["rightharpoondownbar","harpoon.rb.stop"],["leftharpoonup","harpoon.lt"],["leftharpoonupbar","harpoon.lt.bar"],["barleftharpoonup","harpoon.lt.stop"],["leftharpoondown","harpoon.lb"],["leftharpoondownbar","harpoon.lb.bar"],["barleftharpoondown","harpoon.lb.stop"],["upharpoonleft","harpoon.tl"],["upharpoonleftbar","harpoon.tl.bar"],["barupharpoonleft","harpoon.tl.stop"],["upharpoonright","harpoon.tr"],["upharpoonrightbar","harpoon.tr.bar"],["barupharpoonright","harpoon.tr.stop"],["downharpoonleft","harpoon.bl"],["bardownharpoonleft","harpoon.bl.bar"],["downharpoonleftbar","harpoon.bl.stop"],["downharpoonright","harpoon.br"],["bardownharpoonright","harpoon.br.bar"],["downharpoonrightbar","harpoon.br.stop"],["leftrightharpoonupup","harpoon.lt.rt"],["leftrightharpoondowndown","harpoon.lb.rb"],["leftrightharpoondownup","harpoon.lb.rt"],["leftrightharpoonupdown","harpoon.lt.rb"],["updownharpoonleftleft","harpoon.tl.bl"],["updownharpoonrightright","harpoon.tr.br"],["updownharpoonleftright","harpoon.tl.br"],["updownharpoonrightleft","harpoon.tr.bl"],["rightharpoonsupdown","harpoons.rtrb"],["downharpoonsleftright","harpoons.blbr"],["downupharpoonsleftright","harpoons.bltr"],["leftrightharpoonsdown","harpoons.lbrb"],["leftharpoonsupdown","harpoons.ltlb"],["leftrightharpoons","harpoons.ltrb"],["leftrightharpoonsup","harpoons.ltrt"],["rightleftharpoonsdown","harpoons.rblb"],["rightleftharpoons","harpoons.rtlb"],["rightleftharpoonsup","harpoons.rtlt"],["updownharpoonsleftright","harpoons.tlbr"],["upharpoonsleftright","harpoons.tltr"],["vdash","tack.r"],["nvdash","tack.r.not"],["vlongdash","tack.r.long"],["assert","tack.r.short"],["vDash","tack.r.double"],["nvDash","tack.r.double.not"],["dashv","tack.l"],["longdashv","tack.l.long"],["shortlefttack","tack.l.short"],["Dashv","tack.l.double"],["bigbot","tack.t.big"],["Vbar","tack.t.double"],["shortuptack","tack.t.short"],["bigtop","tack.b.big"],["barV","tack.b.double"],["shortdowntack","tack.b.short"],["dashVdash","tack.l.r"],["BbbA","AA"],["BbbB","BB"],["BbbC","CC"],["BbbD","DD"],["BbbE","EE"],["BbbF","FF"],["BbbG","GG"],["BbbH","HH"],["BbbI","II"],["BbbJ","JJ"],["BbbK","KK"],["BbbL","LL"],["BbbM","MM"],["BbbN","NN"],["BbbO","OO"],["BbbP","PP"],["BbbQ","QQ"],["BbbR","RR"],["BbbS","SS"],["BbbT","TT"],["BbbU","UU"],["BbbV","VV"],["BbbW","WW"],["BbbX","XX"],["BbbY","YY"],["BbbZ","ZZ"],["ell","ell"],["Planckconst","planck"],["hslash","planck.reduce"],["Angstrom","angstrom"],["Re","Re"],["Im","Im"],["imath","dotless.i"],["jmath","dotless.j"]]);for(let[q,J]of A2)if(!I.has(q))I.set(q,J);var L=new Map;for(let[q,J]of Array.from(I.entries()).reverse())L.set(J,q);L.set("dif","mathrm{d}");var B2=new Map([["top","top"],["frac","frac"],["tilde","tilde"],["hat","hat"],["upright","mathrm"],["bold","boldsymbol"],["hyph.minus","\\text{-}"]]);for(let[q,J]of B2)L.set(q,J);function d(q,J,z=0){for(let V=z;V<q.length;V++)if(q[V].eq(J))return V;return-1}function P(q,J){for(let z of q)if(z.eq(J))return!0;return!1}function a(q,J){let z=[],V=[];for(let Z of q)if(Z.eq(J))z.push(V),V=[];else V.push(Z);return z.push(V),z}class W{type;value;constructor(q,J){this.type=q,this.value=J}eq(q){return this.type===q.type&&this.value===q.value}toString(){switch(this.type){case 2:return`\\text{${this.value}}`;case 3:return`%${this.value}`;default:return this.value}}}function I2(q){if(["{","}","%"].includes(q))return"\\"+q;return q}class Q{type;content;args;data;constructor(q,J,z,V){this.type=q,this.content=J,this.args=z,this.data=V}eq(q){return this.type===q.type&&this.content===q.content}toString(){switch(this.type){case"text":return`\\text{${this.content}}`;default:throw new Error(`toString() is not implemented for type ${this.type}`)}}serialize(){switch(this.type){case"empty":return[];case"element":{let q=this.content;return q=I2(q),[new W(0,q)]}case"symbol":return[new W(1,this.content)];case"text":return[new W(2,this.content)];case"comment":return[new W(3,this.content)];case"whitespace":{let q=[];for(let J of this.content){let z=J===" "?4:5;q.push(new W(z,J))}return q}case"ordgroup":return this.args.map((q)=>q.serialize()).flat();case"unaryFunc":{let q=[];if(q.push(new W(1,this.content)),this.content==="\\sqrt"&&this.data)q.push(new W(0,"[")),q=q.concat(this.data.serialize()),q.push(new W(0,"]"));if(this.content==="\\operatorname"&&this.args.length===1&&this.args[0].type==="text"){let J=this.args[0].content;return q.push(new W(0,"{")),q.push(new W(1,J)),q.push(new W(0,"}")),q}return q.push(new W(0,"{")),q=q.concat(this.args[0].serialize()),q.push(new W(0,"}")),q}case"binaryFunc":{let q=[];return q.push(new W(1,this.content)),q.push(new W(0,"{")),q=q.concat(this.args[0].serialize()),q.push(new W(0,"}")),q.push(new W(0,"{")),q=q.concat(this.args[1].serialize()),q.push(new W(0,"}")),q}case"supsub":{let q=[],{base:J,sup:z,sub:V}=this.data;if(q=q.concat(J.serialize()),V)if(q.push(new W(6,"_")),V.type==="ordgroup"||V.type==="supsub"||V.type==="empty")q.push(new W(0,"{")),q=q.concat(V.serialize()),q.push(new W(0,"}"));else q=q.concat(V.serialize());if(z)if(q.push(new W(6,"^")),z.type==="ordgroup"||z.type==="supsub"||z.type==="empty")q.push(new W(0,"{")),q=q.concat(z.serialize()),q.push(new W(0,"}"));else q=q.concat(z.serialize());return q}case"control":return[new W(6,this.content)];case"beginend":{let q=[],J=this.data;q.push(new W(1,`\\begin{${this.content}}`)),q.push(new W(5,`
|
|
2
|
+
`));for(let z=0;z<J.length;z++){let V=J[z];for(let Z=0;Z<V.length;Z++){let X=V[Z];if(q=q.concat(X.serialize()),Z!==V.length-1)q.push(new W(6,"&"))}if(z!==J.length-1)q.push(new W(6,"\\\\"))}return q.push(new W(5,`
|
|
3
|
+
`)),q.push(new W(1,`\\end{${this.content}}`)),q}default:throw new Error("[TexNode.serialize] Unimplemented type: "+this.type)}}}class K{type;value;constructor(q,J){this.type=q,this.value=J}eq(q){return this.type===q.type&&this.value===q.value}isOneOf(q){return P(q,this)}toNode(){switch(this.type){case 2:return new j("text",this.value);case 3:return new j("comment",this.value);case 4:case 7:return new j("whitespace",this.value);case 1:return new j("atom",this.value);case 0:return new j("symbol",this.value);case 6:{let q=this.value;switch(q){case"":case"_":case"^":return new j("empty","");case"&":return new j("control","&");case"\\":return new j("control","\\");default:throw new Error(`Unexpected control character ${q}`)}}default:throw new Error(`Unexpected token type ${this.type}`)}}toString(){switch(this.type){case 2:return`"${this.value}"`;case 3:return`//${this.value}`;default:return this.value}}}class j{type;content;args;data;options;constructor(q,J,z,V){this.type=q,this.content=J,this.args=z,this.data=V}setOptions(q){this.options=q}eq(q){return this.type===q.type&&this.content===q.content}}function v(q){return"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".includes(q)}function w(q){return"0123456789".includes(q)}function O(q,J=""){if(!q)throw new Error(J)}var R2=["sqrt","text","bar","bold","boldsymbol","ddot","dot","hat","mathbb","mathbf","mathcal","mathfrak","mathit","mathrm","mathscr","mathsf","mathtt","operatorname","overbrace","overline","pmb","rm","tilde","underbrace","underline","vec","widehat","widetilde"],S2=["frac","tfrac","binom","dbinom","dfrac","tbinom","overset"],k=new Q("empty","");function v2(q){if(R2.includes(q))return 1;else if(S2.includes(q))return 2;else return 0}var u=new W(6,"{"),N=new W(6,"}"),z2=new W(0,"["),f2=new W(0,"]");function p(q,J){let z=J;while(z<q.length&&[4,5].includes(q[z].type))z++;return q.slice(J,z)}function J2(q,J){let z=q[J];if(z.type===0&&["(",")","[","]","|","\\{","\\}","."].includes(z.value))return z;else if(z.type===1&&["lfloor","rfloor","lceil","rceil","langle","rangle"].includes(z.value.slice(1)))return z;else return null}function h(q,J){let z=J;while(z<q.length&&q[z].eq(new W(0,"'")))z+=1;return z-J}function C2(q,J){let z=J;while(z<q.length&&v(q[z]))z+=1;return q.substring(J,z)}function m(q,J,z,V){O(q[J].eq(z));let Z=1,X=J+1;while(Z>0){if(X>=q.length)return-1;if(q[X].eq(z))Z+=1;else if(q[X].eq(V))Z-=1;X+=1}return X-1}var T=new W(1,"\\left"),b2=new W(1,"\\right");function L2(q,J){return m(q,J,T,b2)}var r=new W(1,"\\begin"),w2=new W(1,"\\end");function h2(q,J){return m(q,J,r,w2)}function g2(q,J){O(q[J]==="{");let z=1,V=J+1;while(z>0){if(V>=q.length)throw new H("Unmatched curly brackets");if(V+1<q.length&&["\\{","\\}"].includes(q.substring(V,V+2))){V+=2;continue}if(q[V]==="{")z+=1;else if(q[V]==="}")z-=1;V+=1}return V-1}function V2(q){let J=[],z=0;while(z<q.length){let V=q[z],Z;switch(V){case"%":{let X=z+1;while(X<q.length&&q[X]!==`
|
|
4
|
+
`)X+=1;Z=new W(3,q.slice(z+1,X)),z=X;break}case"{":case"}":case"_":case"^":case"&":Z=new W(6,V),z++;break;case`
|
|
5
|
+
`:Z=new W(5,V),z++;break;case"\r":{if(z+1<q.length&&q[z+1]===`
|
|
6
|
+
`)Z=new W(5,`
|
|
7
|
+
`),z+=2;else Z=new W(5,`
|
|
8
|
+
`),z++;break}case" ":{let X=z;while(X<q.length&&q[X]===" ")X+=1;Z=new W(4,q.slice(z,X)),z=X;break}case"\\":{if(z+1>=q.length)throw new H("Expecting command name after \\");let X=q.slice(z,z+2);if(["\\\\","\\,"].includes(X))Z=new W(6,X);else if(["\\{","\\}","\\%","\\$","\\&","\\#","\\_","\\|"].includes(X))Z=new W(0,X);else{let $=C2(q,z+1);Z=new W(1,"\\"+$)}z+=Z.value.length;break}default:{if(w(V)){let X=z;while(X<q.length&&w(q[X]))X+=1;Z=new W(0,q.slice(z,X))}else if(v(V))Z=new W(0,V);else if("+-*/='<>!.,;:?()[]|".includes(V))Z=new W(0,V);else Z=new W(7,V);z+=Z.value.length}}if(J.push(Z),Z.type===1&&["\\text","\\operatorname","\\begin","\\end"].includes(Z.value)){if(z>=q.length||q[z]!=="{")throw new H(`No content for ${Z.value} command`);J.push(new W(6,"{"));let X=g2(q,z);z++;let $=q.slice(z,X),G=["{","}","\\","$","&","#","_","%"];for(let F of G)$=$.replaceAll("\\"+F,F);J.push(new W(2,$)),J.push(new W(6,"}")),z=X+1}}return J}class H extends Error{constructor(q){super(q);this.name="LatexParserError"}}var n=new W(6,"_"),t=new W(6,"^");class X2{space_sensitive;newline_sensitive;constructor(q=!1,J=!0){this.space_sensitive=q,this.newline_sensitive=J}parse(q){let J=[],z=0;while(z<q.length){let V=[],Z=0;while(Z<q.length){let[X,$]=this.parseNextExpr(q,Z);if(Z=$,X.type==="whitespace"){if(!this.space_sensitive&&X.content.replace(/ /g,"").length===0)continue;if(!this.newline_sensitive&&X.content===`
|
|
9
|
+
`)continue}if(X.type==="control"&&X.content==="&")throw new H("Unexpected & outside of an alignment");V.push(X)}if(V.length===0)return k;else if(V.length===1)return V[0];else return new Q("ordgroup","",V)}if(J.length===0)return k;else if(J.length===1)return J[0];else return new Q("ordgroup","",J)}parseNextExpr(q,J){let[z,V]=this.parseNextExprWithoutSupSub(q,J),Z=null,X=null,$=0;if($+=h(q,V),V+=$,V<q.length&&q[V].eq(n)){if([Z,V]=this.parseNextExprWithoutSupSub(q,V+1),$+=h(q,V),V+=$,V<q.length&&q[V].eq(t)){if([X,V]=this.parseNextExprWithoutSupSub(q,V+1),h(q,V)>0)throw new H("Double superscript")}}else if(V<q.length&&q[V].eq(t)){if([X,V]=this.parseNextExprWithoutSupSub(q,V+1),h(q,V)>0)throw new H("Double superscript");if(V<q.length&&q[V].eq(n)){if([Z,V]=this.parseNextExprWithoutSupSub(q,V+1),h(q,V)>0)throw new H("Double superscript")}}if(Z!==null||X!==null||$>0){let G={base:z};if(Z)G.sub=Z;if($>0){G.sup=new Q("ordgroup","",[]);for(let F=0;F<$;F++)G.sup.args.push(new Q("element","'"));if(X)G.sup.args.push(X);if(G.sup.args.length===1)G.sup=G.sup.args[0]}else if(X)G.sup=X;return[new Q("supsub","",[],G),V]}else return[z,V]}parseNextExprWithoutSupSub(q,J){let z=q[J];switch(z.type){case 0:return[new Q("element",z.value),J+1];case 2:return[new Q("text",z.value),J+1];case 3:return[new Q("comment",z.value),J+1];case 4:case 5:return[new Q("whitespace",z.value),J+1];case 1:if(z.eq(r))return this.parseBeginEndExpr(q,J);else if(z.eq(T))return this.parseLeftRightExpr(q,J);else return this.parseCommandExpr(q,J);case 6:switch(z.value){case"{":let X=m(q,J,u,N);if(X===-1)throw new H("Unmatched '{'");let $=q.slice(J+1,X);return[this.parse($),X+1];case"}":throw new H("Unmatched '}'");case"\\\\":return[new Q("control","\\\\"),J+1];case"\\,":return[new Q("control","\\,"),J+1];case"_":case"^":return[k,J];case"&":return[new Q("control","&"),J+1];default:throw new H("Unknown control sequence")}default:throw new H("Unknown token type")}}parseCommandExpr(q,J){O(q[J].type===1);let z=q[J].value,V=J+1;if(["left","right","begin","end"].includes(z.slice(1)))throw new H("Unexpected command: "+z);switch(v2(z.slice(1))){case 0:if(!I.has(z.slice(1)))return[new Q("unknownMacro",z),V];return[new Q("symbol",z),V];case 1:{if(V>=q.length)throw new H("Expecting argument for "+z);if(z==="\\sqrt"&&V<q.length&&q[V].eq(z2)){let G=V,F=m(q,V,z2,f2);if(F===-1)throw new H("No matching right square bracket for [");let U=q.slice(G+1,F),D=this.parse(U),[b,R]=this.parseNextExprWithoutSupSub(q,F+1);return[new Q("unaryFunc",z,[b],D),R]}else if(z==="\\text"){if(V+2>=q.length)throw new H("Expecting content for \\text command");O(q[V].eq(u)),O(q[V+1].type===2),O(q[V+2].eq(N));let G=q[V+1].value;return[new Q("text",G),V+3]}let[X,$]=this.parseNextExprWithoutSupSub(q,V);return[new Q("unaryFunc",z,[X]),$]}case 2:{let[X,$]=this.parseNextExprWithoutSupSub(q,V),[G,F]=this.parseNextExprWithoutSupSub(q,$);return[new Q("binaryFunc",z,[X,G]),F]}default:throw new Error("Invalid number of parameters")}}parseLeftRightExpr(q,J){O(q[J].eq(T));let z=J+1;if(z+=p(q,z).length,z>=q.length)throw new H("Expecting delimiter after \\left");let V=J2(q,z);if(V===null)throw new H("Invalid delimiter after \\left");z++;let Z=z,X=L2(q,J);if(X===-1)throw new H("No matching \\right");let $=X;if(z=X+1,z+=p(q,z).length,z>=q.length)throw new H("Expecting \\right after \\left");let G=J2(q,z);if(G===null)throw new H("Invalid delimiter after \\right");z++;let F=q.slice(Z,$),U=this.parse(F),D=[new Q("element",V.value),U,new Q("element",G.value)];return[new Q("leftright","",D),z]}parseBeginEndExpr(q,J){O(q[J].eq(r));let z=J+1;O(q[z].eq(u)),O(q[z+1].type===2),O(q[z+2].eq(N));let V=q[z+1].value;z+=3,z+=p(q,z).length;let Z=z,X=h2(q,J);if(X===-1)throw new H("No matching \\end");let $=X;if(z=X+1,O(q[z].eq(u)),O(q[z+1].type===2),O(q[z+2].eq(N)),q[z+1].value!==V)throw new H("Mismatched \\begin and \\end environments");z+=3;let G=q.slice(Z,$);while(G.length>0&&[4,5].includes(G[G.length-1].type))G.pop();let F=this.parseAligned(G);return[new Q("beginend",V,[],F),z]}parseAligned(q){let J=0,z=[],V=[];z.push(V);let Z=new Q("ordgroup","",[]);V.push(Z);while(J<q.length){let[X,$]=this.parseNextExpr(q,J);if(J=$,X.type==="whitespace"){if(!this.space_sensitive&&X.content.replace(/ /g,"").length===0)continue;if(!this.newline_sensitive&&X.content===`
|
|
10
|
+
`)continue}if(X.type==="control"&&X.content==="\\\\")V=[],Z=new Q("ordgroup","",[]),V.push(Z),z.push(V);else if(X.type==="control"&&X.content==="&")Z=new Q("ordgroup","",[]),V.push(Z);else Z.args.push(X)}return z}}function E2(q){let J=(V)=>V.eq(n)||V.eq(t),z=[];for(let V=0;V<q.length;V++){if(q[V].type===4&&V+1<q.length&&J(q[V+1]))continue;if(q[V].type===4&&V-1>=0&&J(q[V-1]))continue;z.push(q[V])}return z}function P2(q,J){let z=[];for(let V of q)if(V.type===1&&J[V.value]){let Z=V2(J[V.value]);z=z.concat(Z)}else z.push(V);return z}function Z2(q,J){let z=new X2,V=V2(q);return V=E2(V),V=P2(V,J),z.parse(V)}var N2=["dim","id","im","mod","Pr","sech","csch"];function $2(q){return q.type==="atom"&&["(",")","[","]","{","}","|","⌊","⌋","⌈","⌉"].includes(q.content)}function m2(q){let[J,z]=q.args,V=($)=>{if($.eq(new Q("text","def")))return!0;if($.type==="ordgroup"&&$.args.length===3){let[G,F,U]=$.args,D=new Q("element","d"),b=new Q("element","e"),R=new Q("element","f");if(G.eq(D)&&F.eq(b)&&U.eq(R))return!0}return!1},Z=($)=>$.eq(new Q("element","="));if(V(J)&&Z(z))return new j("symbol","eq.def");let X=new j("funcCall","op",[Y(z)]);return X.setOptions({limits:"#true"}),new j("supsub","",[],{base:X,sup:Y(J)})}var s=new K(1,"("),l=new K(1,")"),l2=new K(1,","),c2=new K(0,`
|
|
11
|
+
`);class f extends Error{node;constructor(q,J){super(q);this.name="TypstWriterError",this.node=J}}class o{nonStrict;preferTypstIntrinsic;keepSpaces;buffer="";queue=[];insideFunctionDepth=0;constructor(q,J,z){this.nonStrict=q,this.preferTypstIntrinsic=J,this.keepSpaces=z}writeBuffer(q){let J=q.toString();if(J==="")return;let z=!1;if(z||=/[\(\[\|]$/.test(this.buffer)&&/^\w/.test(J),z||=/^[})\]\|]$/.test(J),z||=/^[(_^,;!]$/.test(J),z||=J==="'",z||=/[0-9]$/.test(this.buffer)&&/^[0-9]/.test(J),z||=/[\(\[{]\s*(-|\+)$/.test(this.buffer)||this.buffer==="-"||this.buffer==="+",z||=J.startsWith(`
|
|
12
|
+
`),z||=this.buffer==="",z||=/^\s/.test(J),z||=this.buffer.endsWith("&")&&J==="=",z||=/[\s_^{\(]$/.test(this.buffer),!z)this.buffer+=" ";this.buffer+=J}serialize(q){switch(q.type){case"empty":break;case"atom":{if(q.content===","&&this.insideFunctionDepth>0)this.queue.push(new K(0,"comma"));else this.queue.push(new K(1,q.content));break}case"symbol":this.queue.push(new K(0,q.content));break;case"text":this.queue.push(new K(2,q.content));break;case"comment":this.queue.push(new K(3,q.content));break;case"whitespace":for(let J of q.content)if(J===" "){if(this.keepSpaces)this.queue.push(new K(4,J))}else if(J===`
|
|
13
|
+
`)this.queue.push(new K(0,J));else throw new f(`Unexpected whitespace character: ${J}`,q);break;case"group":for(let J of q.args)this.serialize(J);break;case"supsub":{let{base:J,sup:z,sub:V}=q.data;this.appendWithBracketsIfNeeded(J);let Z=!1,X=z&&z.type==="atom"&&z.content==="'";if(X)this.queue.push(new K(1,"'")),Z=!1;if(V)this.queue.push(new K(1,"_")),Z=this.appendWithBracketsIfNeeded(V);if(z&&!X)this.queue.push(new K(1,"^")),Z=this.appendWithBracketsIfNeeded(z);if(Z)this.queue.push(new K(6," "));break}case"funcCall":{let J=new K(0,q.content);this.queue.push(J),this.insideFunctionDepth++,this.queue.push(s);for(let z=0;z<q.args.length;z++)if(this.serialize(q.args[z]),z<q.args.length-1)this.queue.push(new K(1,","));if(q.options)for(let[z,V]of Object.entries(q.options))this.queue.push(new K(0,`, ${z}: ${V}`));this.queue.push(l),this.insideFunctionDepth--;break}case"align":{let J=q.data;J.forEach((z,V)=>{if(z.forEach((Z,X)=>{if(X>0)this.queue.push(new K(1,"&"));this.serialize(Z)}),V<J.length-1)this.queue.push(new K(0,"\\"))});break}case"matrix":{let J=q.data;if(this.queue.push(new K(0,"mat")),this.insideFunctionDepth++,this.queue.push(s),q.options)for(let[z,V]of Object.entries(q.options))this.queue.push(new K(0,`${z}: ${V}, `));J.forEach((z,V)=>{z.forEach((Z,X)=>{if(this.serialize(Z),X<z.length-1)this.queue.push(new K(1,","));else if(V<J.length-1)this.queue.push(new K(1,";"))})}),this.queue.push(l),this.insideFunctionDepth--;break}case"unknown":{if(this.nonStrict)this.queue.push(new K(0,q.content));else throw new f(`Unknown macro: ${q.content}`,q);break}default:throw new f(`Unimplemented node type to append: ${q.type}`,q)}}appendWithBracketsIfNeeded(q){let J=["group","supsub","empty"].includes(q.type);if(q.type==="group"){let z=q.args[0],V=q.args[q.args.length-1];if($2(z)&&$2(V))J=!1}if(J)this.queue.push(s),this.serialize(q),this.queue.push(l);else this.serialize(q);return!J}flushQueue(){let q=new K(6," ");for(let J=0;J<this.queue.length;J++)if(this.queue[J].eq(q)){if(J===this.queue.length-1)this.queue[J].value="";else if(this.queue[J+1].isOneOf([l,l2,c2]))this.queue[J].value=""}this.queue.forEach((J)=>{this.writeBuffer(J)}),this.queue=[]}finalize(){this.flushQueue();let V=[function(Z){let X=Z.replace(/floor\.l\s*(.*?)\s*floor\.r/g,"floor($1)");return X=X.replace(/floor\(\)/g,'floor("")'),X},function(Z){let X=Z.replace(/ceil\.l\s*(.*?)\s*ceil\.r/g,"ceil($1)");return X=X.replace(/ceil\(\)/g,'ceil("")'),X},function(Z){let X=Z.replace(/floor\.l\s*(.*?)\s*ceil\.r/g,"round($1)");return X=X.replace(/round\(\)/g,'round("")'),X}];for(let Z of V)this.buffer=Z(this.buffer);return this.buffer}}function Y(q){switch(q.type){case"empty":return new j("empty","");case"whitespace":return new j("whitespace",q.content);case"ordgroup":return new j("group","",q.args.map(Y));case"element":return new j("atom",g(q.content));case"symbol":return new j("symbol",g(q.content));case"text":return new j("text",q.content);case"comment":return new j("comment",q.content);case"supsub":{let{base:J,sup:z,sub:V}=q.data;if(J&&J.type==="unaryFunc"&&J.content==="\\overbrace"&&z)return new j("funcCall","overbrace",[Y(J.args[0]),Y(z)]);else if(J&&J.type==="unaryFunc"&&J.content==="\\underbrace"&&V)return new j("funcCall","underbrace",[Y(J.args[0]),Y(V)]);let Z={base:Y(J)};if(Z.base.type==="empty")Z.base=new j("text","");if(z)Z.sup=Y(z);if(V)Z.sub=Y(V);return new j("supsub","",[],Z)}case"leftright":{let[J,z,V]=q.args,Z=new j("group","",q.args.map(Y));if(["[]","()","\\{\\}","\\lfloor\\rfloor","\\lceil\\rceil","\\lfloor\\rceil"].includes(J.content+V.content))return Z;if(V.content===".")return Z.args.pop(),Z;else if(J.content===".")return Z.args.shift(),new j("funcCall","lr",[Z]);return new j("funcCall","lr",[Z])}case"binaryFunc":{if(q.content==="\\overset")return m2(q);return new j("funcCall",g(q.content),q.args.map(Y))}case"unaryFunc":{let J=Y(q.args[0]);if(q.content==="\\sqrt"&&q.data){let z=Y(q.data);return new j("funcCall","root",[z,J])}if(q.content==="\\mathbf"){let z=new j("funcCall","bold",[J]);return new j("funcCall","upright",[z])}if(q.content==="\\mathbb"&&J.type==="atom"&&/^[A-Z]$/.test(J.content))return new j("symbol",J.content+J.content);if(q.content==="\\operatorname"){let z=q.args;if(z.length!==1||z[0].type!=="text")throw new f("Expecting body of \\operatorname to be text but got",q);let V=z[0].content;if(N2.includes(V))return new j("symbol",V);else return new j("funcCall","op",[new j("text",V)])}return new j("funcCall",g(q.content),q.args.map(Y))}case"beginend":{let z=q.data.map((V)=>V.map(Y));if(q.content.startsWith("align"))return new j("align","",[],z);else{let V=new j("matrix","",[],z);return V.setOptions({delim:"#none"}),V}}case"unknownMacro":return new j("unknown",g(q.content));case"control":if(q.content==="\\\\")return new j("symbol","\\");else if(q.content==="\\,")return new j("symbol","thin");else throw new f(`Unknown control sequence: ${q.content}`,q);default:throw new f(`Unimplemented node type: ${q.type}`,q)}}function g(q){if(/^[a-zA-Z0-9]$/.test(q))return q;else if(q==="/")return"\\/";else if(q==="\\|")return"parallel";else if(q==="\\\\")return"\\";else if(["\\$","\\#","\\&","\\_"].includes(q))return q;else if(q.startsWith("\\")){let J=q.slice(1);if(I.has(J))return I.get(J);else return J}return q}function Q2(q,J){let z=J;while(z<q.length&&q[z].eq(new K(1,"'")))z+=1;return z-J}function i2(q,J){let z=J;while(z<q.length&&(v(q[z])||q[z]==="."))z+=1;return q.substring(J,z)}var i=new j("empty","");function _2(q){let J=[],z=0;while(z<q.length){let V=q[z],Z;switch(V){case"_":case"^":case"&":Z=new K(6,V),z++;break;case`
|
|
14
|
+
`:Z=new K(7,V),z++;break;case"\r":{if(z+1<q.length&&q[z+1]===`
|
|
15
|
+
`)Z=new K(7,`
|
|
16
|
+
`),z+=2;else Z=new K(7,`
|
|
17
|
+
`),z++;break}case" ":{let X=z;while(X<q.length&&q[X]===" ")X++;Z=new K(4,q.substring(z,X)),z=X;break}case"/":{if(z<q.length&&q[z+1]==="/"){let X=z+2;while(X<q.length&&q[X]!==`
|
|
18
|
+
`)X++;Z=new K(3,q.slice(z+2,X)),z=X}else Z=new K(1,"/"),z++;break}case"\\":{if(z+1>=q.length)throw new Error("Expecting a character after \\");let X=q.substring(z,z+2);if(["\\$","\\&","\\#","\\_"].includes(X))Z=new K(1,X),z+=2;else if(X==="\\\n")Z=new K(6,"\\"),z+=1;else Z=new K(6,""),z++;break}case'"':{let X=z+1;while(X<q.length){if(q[X]==='"'&&q[X-1]!=="\\")break;X++}let $=q.substring(z+1,X),G=['"',"\\"];for(let F of G)$=$.replaceAll("\\"+F,F);Z=new K(2,$),z=X+1;break}default:{if(w(V)){let X=z;while(X<q.length&&w(q[X]))X+=1;Z=new K(1,q.slice(z,X))}else if("+-*/='<>!.,;?()[]|".includes(V))Z=new K(1,V);else if(v(V)){let X=i2(q,z),$=X.length===1?1:0;Z=new K($,X)}else Z=new K(1,V);z+=Z.value.length}}J.push(Z)}return J}function c(q,J){O(q[J].isOneOf([E,K2,F2]));let z=1,V=J+1;while(z>0){if(V>=q.length)throw new Error("Unmatched brackets");if(q[V].isOneOf([E,K2,F2]))z+=1;else if(q[V].isOneOf([a2,k2,p2]))z-=1;V+=1}return V-1}function x2(q,J){let z=new j("atom","("),V=new j("atom",")");O(q[J].eq(z));let Z=1,X=J+1;while(Z>0){if(X>=q.length)throw new Error("Unmatched brackets");if(q[X].eq(z))Z+=1;else if(q[X].eq(V))Z-=1;X+=1}return X-1}function j2(q){let J=[];for(let z=0;z<q;z++)J.push(new j("atom","'"));return J}var _=new j("atom","/");function y2(q,J){let z=J;while(z<q.length&&q[z].type==="whitespace")z++;return z===q.length?i:q[z]}function d2(q){let J=!1,z=[];for(let V=0;V<q.length;V++){let Z=q[V];if(Z.type==="whitespace"){if(J)continue;if(y2(q,V+1).eq(_))continue}if(Z.eq(_))J=!0;else J=!1;z.push(Z)}return z}function e(q,J=!1){q=d2(q);let z=new j("atom","("),V=new j("atom",")"),Z=[],X=[],$=0;while($<q.length){let G=q[$];if(G.eq(V))throw new C("Unexpected ')'");else if(G.eq(_))Z.push(G),$++;else{let F;if(G.eq(z)){let U=x2(q,$);F=e(q.slice($+1,U),!0),$=U+1}else F=G,$++;if(Z.length>0&&Z[Z.length-1].eq(_)){let U=F;if(X.length===0)throw new C("Unexpected '/' operator, no numerator before it");let D=X.pop();if(U.type==="group"&&U.content==="parenthesis")U.content="";if(D.type==="group"&&D.content==="parenthesis")D.content="";X.push(new j("fraction","",[D,U])),Z.pop()}else X.push(F)}}if(J)return new j("group","parenthesis",X);else if(X.length===0)return i;else if(X.length===1)return X[0];else return new j("group","",X)}class C extends Error{constructor(q){super(q);this.name="TypstParserError"}}var W2=new K(6,"_"),G2=new K(6,"^"),E=new K(1,"("),a2=new K(1,")"),K2=new K(1,"["),k2=new K(1,"]"),F2=new K(1,"{"),p2=new K(1,"}"),T2=new K(1,","),r2=new K(1,";"),n2=new K(4," ");class H2{space_sensitive;newline_sensitive;constructor(q=!0,J=!0){this.space_sensitive=q,this.newline_sensitive=J}parse(q){let[J,z]=this.parseGroup(q,0,q.length);return J}parseGroup(q,J,z,V=!1){let Z=[],X=J;while(X<z){let[G,F]=this.parseNextExpr(q,X);if(X=F,G.type==="whitespace"){if(!this.space_sensitive&&G.content.replace(/ /g,"").length===0)continue;if(!this.newline_sensitive&&G.content===`
|
|
19
|
+
`)continue}Z.push(G)}let $;if(V)$=e(Z,!0);else if(Z.length===0)$=i;else if(Z.length===1)$=Z[0];else $=e(Z);return[$,z+1]}parseNextExpr(q,J){let[z,V]=this.parseNextExprWithoutSupSub(q,J),Z=null,X=null,$=Q2(q,V);if($>0)z=new j("group","",[z].concat(j2($))),V+=$;if(V<q.length&&q[V].eq(W2)){if([Z,V]=this.parseSupOrSub(q,V+1),V<q.length&&q[V].eq(G2))[X,V]=this.parseSupOrSub(q,V+1)}else if(V<q.length&&q[V].eq(G2)){if([X,V]=this.parseSupOrSub(q,V+1),V<q.length&&q[V].eq(W2))[Z,V]=this.parseSupOrSub(q,V+1)}if(Z!==null||X!==null){let G={base:z};if(Z)G.sub=Z;if(X)G.sup=X;return[new j("supsub","",[],G),V]}else return[z,V]}parseSupOrSub(q,J){let z,V;if(q[J].eq(E)){let X=c(q,J);[z,V]=this.parseGroup(q,J+1,X)}else[z,V]=this.parseNextExprWithoutSupSub(q,J);let Z=Q2(q,V);if(Z>0)z=new j("group","",[z].concat(j2(Z))),V+=Z;return[z,V]}parseNextExprWithoutSupSub(q,J){let z=q[J],V=z.toNode();if(z.eq(E)){let Z=c(q,J);return this.parseGroup(q,J+1,Z,!0)}if(z.type===1&&!v(z.value[0]))return[V,J+1];if([1,0].includes(z.type)){if(J+1<q.length&&q[J+1].eq(E)){if(z.value==="mat"){let[G,F,U]=this.parseGroupsOfArguments(q,J+1),D=new j("matrix","",[],G);return D.setOptions(F),[D,U]}let[Z,X]=this.parseArguments(q,J+1),$=new j("funcCall",z.value);return $.args=Z,[$,X]}}return[V,J+1]}parseArguments(q,J){let z=c(q,J);return[this.parseCommaSeparatedArguments(q,J+1,z),z+1]}parseGroupsOfArguments(q,J){let z=c(q,J),V=[],Z={},X=J+1;while(X<z)while(X<z){let U=function(D){let b=new j("atom",":"),R={},y=[];for(let B=0;B<D.length;B++){if(D[B].type!=="group")continue;let M=D[B],S=d(M.args,b);if(S===-1||S===0)continue;if(y.push(B),M.args[S-1].eq(new j("symbol","delim")))if(M.args[S+1].type==="text"){if(R.delim=M.args[S+1].content,M.args.length!==3)throw new C("Invalid number of arguments for delim")}else if(M.args[S+1].eq(new j("atom","#"))){if(M.args.length!==4||!M.args[S+2].eq(new j("symbol","none")))throw new C("Invalid number of arguments for delim");R.delim="#none"}else throw new C("Not implemented for other types of delim");else throw new C("Not implemented for other named parameters")}for(let B=y.length-1;B>=0;B--)D.splice(y[B],1);return[D,R]},$=d(q,r2,X);if($===-1)$=z;let G=this.parseCommaSeparatedArguments(q,X,$),F={};[G,F]=U(G),V.push(G),Object.assign(Z,F),X=$+1}return[V,Z,z+1]}parseCommaSeparatedArguments(q,J,z){let V=[],Z=J;while(Z<z){let X=new j("group","",[]);while(Z<z){if(q[Z].eq(T2)){Z+=1;break}else if(q[Z].eq(n2)){Z+=1;continue}let[$,G]=this.parseNextExpr(q,Z);Z=G,X.args.push($)}if(X.args.length===0)X=i;else if(X.args.length===1)X=X.args[0];V.push(X)}return V}}function D2(q){let J=new H2,z=_2(q);return J.parse(z)}var t2=["sqrt","bold","arrow","upright","lr","op","macron","dot","dot.double","hat","tilde","overline","underline","bb","cal","frak"],s2=["frac","root","overbrace","underbrace"];function U2(q){if(["{","}","%"].includes(q))return"\\"+q;return q}class q2{buffer="";queue=[];writeBuffer(q){let J=q.toString(),z=!1;if(q.type===4)z=!0;else z||=/[{\(\[\|]$/.test(this.buffer),z||=/\\\w+$/.test(this.buffer)&&J==="[",z||=/^[\.,;:!\?\(\)\]{}_^]$/.test(J),z||=["\\{","\\}"].includes(J),z||=J==="'",z||=this.buffer.endsWith("_")||this.buffer.endsWith("^"),z||=/\s$/.test(this.buffer),z||=/^\s/.test(J),z||=this.buffer==="",z||=/[\(\[{]\s*(-|\+)$/.test(this.buffer)||this.buffer==="-"||this.buffer==="+",z||=this.buffer.endsWith("&")&&J==="=";if(!z)this.buffer+=" ";this.buffer+=J}append(q){let J=new Q("control","&"),z=new Q("control","\\\\");if(q.type==="ordgroup"&&P(q.args,J)){let V=a(q.args,z),Z=[];for(let X of V){let $=a(X,J);Z.push($.map((G)=>new Q("ordgroup","",G)))}q=new Q("beginend","aligned",[],Z)}this.queue=this.queue.concat(q.serialize())}flushQueue(){for(let q=0;q<this.queue.length;q++)this.writeBuffer(this.queue[q]);this.queue=[]}finalize(){return this.flushQueue(),this.buffer}}function A(q){if(q.eq(new j("symbol","eq.def")))return new Q("binaryFunc","\\overset",[new Q("text","def"),new Q("element","=")]);switch(q.type){case"empty":return new Q("empty","");case"whitespace":return new Q("whitespace",q.content);case"atom":return new Q("element",q.content);case"symbol":switch(q.content){case"comma":return new Q("element",",");case"hyph":case"hyph.minus":return new Q("text","-");default:return new Q("symbol",x(q.content))}case"text":return new Q("text",q.content);case"comment":return new Q("comment",q.content);case"group":{let J=q.args.map(A);if(q.content==="parenthesis")J.unshift(new Q("element","(")),J.push(new Q("element",")"));return new Q("ordgroup","",J)}case"funcCall":if(t2.includes(q.content)){if(q.content==="lr"){let z=q.args[0];if(z.type==="group"){let V=z.args[0].content,Z=z.args[z.args.length-1].content;return V=U2(V),Z=U2(Z),new Q("ordgroup","",[new Q("element","\\left"+V),...z.args.slice(1,z.args.length-1).map(A),new Q("element","\\right"+Z)])}}let J=x(q.content);return new Q("unaryFunc",J,q.args.map(A))}else if(s2.includes(q.content)){if(q.content==="root"){let[z,V]=q.args,Z=A(z);return new Q("unaryFunc","\\sqrt",[A(V)],Z)}if(q.content==="overbrace"||q.content==="underbrace"){let[z,V]=q.args,Z=new Q("unaryFunc","\\"+q.content,[A(z)]),X=A(V),$=q.content==="overbrace"?{base:Z,sup:X}:{base:Z,sub:X};return new Q("supsub","",[],$)}let J=x(q.content);return new Q("binaryFunc",J,q.args.map(A))}else return new Q("ordgroup","",[new Q("symbol",x(q.content)),new Q("element","("),...q.args.map(A),new Q("element",")")]);case"supsub":{let{base:J,sup:z,sub:V}=q.data,Z=A(J),X,$;if(z)X=A(z);if(V)$=A(V);return new Q("supsub","",[],{base:Z,sup:X,sub:$})}case"matrix":{let z=q.data.map(($)=>$.map(A)),V=new Q("beginend","matrix",[],z),Z="\\left(",X="\\right)";if(q.options){if("delim"in q.options)switch(q.options.delim){case"#none":return V;case"[":Z="\\left[",X="\\right]";break;case"]":Z="\\left]",X="\\right[";break;case"{":Z="\\left\\{",X="\\right\\}";break;case"}":Z="\\left\\}",X="\\right\\{";break;case"|":Z="\\left|",X="\\right|";break;case")":Z="\\left)",X="\\right(";case"(":default:Z="\\left(",X="\\right)";break}}return new Q("ordgroup","",[new Q("element",Z),V,new Q("element",X)])}case"control":switch(q.content){case"\\":return new Q("control","\\\\");case"&":return new Q("control","&");default:throw new Error("[convert_typst_node_to_tex] Unimplemented control: "+q.content)}case"fraction":{let[J,z]=q.args,V=A(J),Z=A(z);return new Q("binaryFunc","\\frac",[V,Z])}default:throw new Error("[convert_typst_node_to_tex] Unimplemented type: "+q.type)}}function x(q){if(/^[a-zA-Z0-9]$/.test(q))return q;else if(q==="thin")return"\\,";else if(L.has(q))return"\\"+L.get(q);return"\\"+q}function O2(q,J){let z={nonStrict:!0,preferTypstIntrinsic:!0,keepSpaces:!1,customTexMacros:{}};if(J){if(J.nonStrict)z.nonStrict=J.nonStrict;if(J.preferTypstIntrinsic)z.preferTypstIntrinsic=J.preferTypstIntrinsic;if(J.customTexMacros)z.customTexMacros=J.customTexMacros}let V=Z2(q,z.customTexMacros),Z=Y(V),X=new o(z.nonStrict,z.preferTypstIntrinsic,z.keepSpaces);return X.serialize(Z),X.finalize()}function Y2(q){let J=D2(q),z=A(J),V=new q2;return V.append(z),V.finalize()}if(typeof window!=="undefined")window.tex2typst=O2,window.typst2tex=Y2;
|
package/dist/types.d.ts
CHANGED
|
@@ -68,14 +68,15 @@ export interface TypstSupsubData {
|
|
|
68
68
|
}
|
|
69
69
|
export type TypstArrayData = TypstNode[][];
|
|
70
70
|
type TypstNodeType = 'atom' | 'symbol' | 'text' | 'control' | 'comment' | 'whitespace' | 'empty' | 'group' | 'supsub' | 'funcCall' | 'fraction' | 'align' | 'matrix' | 'unknown';
|
|
71
|
+
export type TypstNamedParams = {
|
|
72
|
+
[key: string]: string;
|
|
73
|
+
};
|
|
71
74
|
export declare class TypstNode {
|
|
72
75
|
type: TypstNodeType;
|
|
73
76
|
content: string;
|
|
74
77
|
args?: TypstNode[];
|
|
75
78
|
data?: TypstSupsubData | TypstArrayData;
|
|
76
|
-
options?:
|
|
77
|
-
[key: string]: string;
|
|
78
|
-
};
|
|
79
|
+
options?: TypstNamedParams;
|
|
79
80
|
constructor(type: TypstNodeType, content: string, args?: TypstNode[], data?: TypstSupsubData | TypstArrayData);
|
|
80
81
|
setOptions(options: {
|
|
81
82
|
[key: string]: string;
|
package/dist/typst-parser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TypstNode, TypstToken } from "./types";
|
|
1
|
+
import { TypstNamedParams, TypstNode, TypstToken } from "./types";
|
|
2
2
|
export declare function tokenize_typst(typst: string): TypstToken[];
|
|
3
3
|
export declare class TypstParserError extends Error {
|
|
4
4
|
constructor(message: string);
|
|
@@ -14,7 +14,7 @@ export declare class TypstParser {
|
|
|
14
14
|
parseSupOrSub(tokens: TypstToken[], start: number): TypstParseResult;
|
|
15
15
|
parseNextExprWithoutSupSub(tokens: TypstToken[], start: number): TypstParseResult;
|
|
16
16
|
parseArguments(tokens: TypstToken[], start: number): [TypstNode[], number];
|
|
17
|
-
parseGroupsOfArguments(tokens: TypstToken[], start: number): [TypstNode[][], number];
|
|
17
|
+
parseGroupsOfArguments(tokens: TypstToken[], start: number): [TypstNode[][], TypstNamedParams, number];
|
|
18
18
|
parseCommaSeparatedArguments(tokens: TypstToken[], start: number, end: number): TypstNode[];
|
|
19
19
|
}
|
|
20
20
|
export declare function parseTypst(typst: string): TypstNode;
|
package/package.json
CHANGED
package/src/map.ts
CHANGED
|
@@ -408,7 +408,7 @@ const map_from_official_docs: Map<string, string> = new Map([
|
|
|
408
408
|
['mathquestion', 'quest'],
|
|
409
409
|
['Question', 'quest.double'],
|
|
410
410
|
['mathoctothorpe', 'hash'],
|
|
411
|
-
['mathhyphen', 'hyph'],
|
|
411
|
+
// ['mathhyphen', 'hyph'],
|
|
412
412
|
['mathpercent', 'percent'],
|
|
413
413
|
['mathparagraph', 'pilcrow'],
|
|
414
414
|
['mathsection', 'section'],
|
|
@@ -1095,6 +1095,8 @@ const typst_to_tex_map = new Map<string, string>([
|
|
|
1095
1095
|
['hat', 'hat'],
|
|
1096
1096
|
['upright', 'mathrm'],
|
|
1097
1097
|
['bold', 'boldsymbol'],
|
|
1098
|
+
|
|
1099
|
+
['hyph.minus', '\\text{-}'],
|
|
1098
1100
|
]);
|
|
1099
1101
|
|
|
1100
1102
|
for(const [key, value] of typst_to_tex_map) {
|
package/src/tex-writer.ts
CHANGED
|
@@ -120,17 +120,19 @@ export function convert_typst_node_to_tex(node: TypstNode): TexNode {
|
|
|
120
120
|
case 'whitespace':
|
|
121
121
|
return new TexNode('whitespace', node.content);
|
|
122
122
|
case 'atom':
|
|
123
|
-
// special hook for colon
|
|
124
|
-
if (node.content === ':') {
|
|
125
|
-
return new TexNode('symbol', '\\colon');
|
|
126
|
-
}
|
|
127
123
|
return new TexNode('element', node.content);
|
|
128
124
|
case 'symbol':
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
switch(node.content) {
|
|
126
|
+
// special hook for comma
|
|
127
|
+
case 'comma':
|
|
128
|
+
return new TexNode('element', ',');
|
|
129
|
+
// special hook for hyph and hyph.minus
|
|
130
|
+
case 'hyph':
|
|
131
|
+
case 'hyph.minus':
|
|
132
|
+
return new TexNode('text', '-');
|
|
133
|
+
default:
|
|
134
|
+
return new TexNode('symbol', typst_token_to_tex(node.content));
|
|
132
135
|
}
|
|
133
|
-
return new TexNode('symbol', typst_token_to_tex(node.content));
|
|
134
136
|
case 'text':
|
|
135
137
|
return new TexNode('text', node.content);
|
|
136
138
|
case 'comment':
|
|
@@ -210,10 +212,48 @@ export function convert_typst_node_to_tex(node: TypstNode): TexNode {
|
|
|
210
212
|
const typst_data = node.data as TypstNode[][];
|
|
211
213
|
const tex_data = typst_data.map(row => row.map(convert_typst_node_to_tex));
|
|
212
214
|
const matrix = new TexNode('beginend', 'matrix', [], tex_data);
|
|
215
|
+
let left_delim = "\\left(";
|
|
216
|
+
let right_delim = "\\right)";
|
|
217
|
+
if (node.options) {
|
|
218
|
+
if('delim' in node.options) {
|
|
219
|
+
switch (node.options.delim) {
|
|
220
|
+
case '#none':
|
|
221
|
+
return matrix;
|
|
222
|
+
case '[':
|
|
223
|
+
left_delim = "\\left[";
|
|
224
|
+
right_delim = "\\right]";
|
|
225
|
+
break;
|
|
226
|
+
case ']':
|
|
227
|
+
left_delim = "\\left]";
|
|
228
|
+
right_delim = "\\right[";
|
|
229
|
+
break;
|
|
230
|
+
case '{':
|
|
231
|
+
left_delim = "\\left\\{";
|
|
232
|
+
right_delim = "\\right\\}";
|
|
233
|
+
break;
|
|
234
|
+
case '}':
|
|
235
|
+
left_delim = "\\left\\}";
|
|
236
|
+
right_delim = "\\right\\{";
|
|
237
|
+
break;
|
|
238
|
+
case '|':
|
|
239
|
+
left_delim = "\\left|";
|
|
240
|
+
right_delim = "\\right|";
|
|
241
|
+
break;
|
|
242
|
+
case ')':
|
|
243
|
+
left_delim = "\\left)";
|
|
244
|
+
right_delim = "\\right(";
|
|
245
|
+
case '(':
|
|
246
|
+
default:
|
|
247
|
+
left_delim = "\\left(";
|
|
248
|
+
right_delim = "\\right)";
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
213
253
|
return new TexNode('ordgroup', '', [
|
|
214
|
-
new TexNode('element',
|
|
254
|
+
new TexNode('element', left_delim),
|
|
215
255
|
matrix,
|
|
216
|
-
new TexNode('element',
|
|
256
|
+
new TexNode('element', right_delim)
|
|
217
257
|
]);
|
|
218
258
|
}
|
|
219
259
|
case 'control': {
|
package/src/types.ts
CHANGED
|
@@ -302,6 +302,7 @@ export type TypstArrayData = TypstNode[][];
|
|
|
302
302
|
type TypstNodeType = 'atom' | 'symbol' | 'text' | 'control' | 'comment' | 'whitespace'
|
|
303
303
|
| 'empty' | 'group' | 'supsub' | 'funcCall' | 'fraction' | 'align' | 'matrix' | 'unknown';
|
|
304
304
|
|
|
305
|
+
export type TypstNamedParams = { [key: string]: string };
|
|
305
306
|
|
|
306
307
|
export class TypstNode {
|
|
307
308
|
type: TypstNodeType;
|
|
@@ -309,7 +310,7 @@ export class TypstNode {
|
|
|
309
310
|
args?: TypstNode[];
|
|
310
311
|
data?: TypstSupsubData | TypstArrayData;
|
|
311
312
|
// Some Typst functions accept additional options. e.g. mat() has option "delim", op() has option "limits"
|
|
312
|
-
options?:
|
|
313
|
+
options?: TypstNamedParams;
|
|
313
314
|
|
|
314
315
|
constructor(type: TypstNodeType, content: string, args?: TypstNode[],
|
|
315
316
|
data?: TypstSupsubData | TypstArrayData) {
|
package/src/typst-parser.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { array_find } from "./generic";
|
|
3
|
-
import { TypstNode, TypstSupsubData, TypstToken, TypstTokenType } from "./types";
|
|
3
|
+
import { TypstNamedParams, TypstNode, TypstSupsubData, TypstToken, TypstTokenType } from "./types";
|
|
4
4
|
import { assert, isalpha, isdigit } from "./util";
|
|
5
5
|
|
|
6
6
|
// TODO: In Typst, y' ' is not the same as y''.
|
|
@@ -427,8 +427,9 @@ export class TypstParser {
|
|
|
427
427
|
if ([TypstTokenType.ELEMENT, TypstTokenType.SYMBOL].includes(firstToken.type)) {
|
|
428
428
|
if (start + 1 < tokens.length && tokens[start + 1].eq(LEFT_PARENTHESES)) {
|
|
429
429
|
if(firstToken.value === 'mat') {
|
|
430
|
-
const [matrix, newPos] = this.parseGroupsOfArguments(tokens, start + 1);
|
|
430
|
+
const [matrix, named_params, newPos] = this.parseGroupsOfArguments(tokens, start + 1);
|
|
431
431
|
const mat = new TypstNode('matrix', '', [], matrix);
|
|
432
|
+
mat.setOptions(named_params);
|
|
432
433
|
return [mat, newPos];
|
|
433
434
|
}
|
|
434
435
|
const [args, newPos] = this.parseArguments(tokens, start + 1);
|
|
@@ -449,10 +450,12 @@ export class TypstParser {
|
|
|
449
450
|
}
|
|
450
451
|
|
|
451
452
|
// start: the position of the left parentheses
|
|
452
|
-
parseGroupsOfArguments(tokens: TypstToken[], start: number): [TypstNode[][], number] {
|
|
453
|
+
parseGroupsOfArguments(tokens: TypstToken[], start: number): [TypstNode[][], TypstNamedParams, number] {
|
|
453
454
|
const end = find_closing_match(tokens, start);
|
|
454
455
|
|
|
455
456
|
const matrix: TypstNode[][] = [];
|
|
457
|
+
let named_params: TypstNamedParams = {};
|
|
458
|
+
|
|
456
459
|
let pos = start + 1;
|
|
457
460
|
while (pos < end) {
|
|
458
461
|
while(pos < end) {
|
|
@@ -460,13 +463,60 @@ export class TypstParser {
|
|
|
460
463
|
if (next_stop === -1) {
|
|
461
464
|
next_stop = end;
|
|
462
465
|
}
|
|
463
|
-
|
|
466
|
+
|
|
467
|
+
let row = this.parseCommaSeparatedArguments(tokens, pos, next_stop);
|
|
468
|
+
let np: TypstNamedParams = {};
|
|
469
|
+
|
|
470
|
+
function extract_named_params(arr: TypstNode[]): [TypstNode[], TypstNamedParams] {
|
|
471
|
+
const COLON = new TypstNode('atom', ':');
|
|
472
|
+
const np: TypstNamedParams = {};
|
|
473
|
+
|
|
474
|
+
const to_delete: number[] = [];
|
|
475
|
+
for(let i = 0; i < arr.length; i++) {
|
|
476
|
+
if(arr[i].type !== 'group') {
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const g = arr[i];
|
|
481
|
+
const pos_colon = array_find(g.args!, COLON);
|
|
482
|
+
if(pos_colon === -1 || pos_colon === 0) {
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
to_delete.push(i);
|
|
486
|
+
const param_name = g.args![pos_colon - 1];
|
|
487
|
+
if(param_name.eq(new TypstNode('symbol', 'delim'))) {
|
|
488
|
+
if(g.args![pos_colon + 1].type === 'text') {
|
|
489
|
+
np['delim'] = g.args![pos_colon + 1].content;
|
|
490
|
+
if(g.args!.length !== 3) {
|
|
491
|
+
throw new TypstParserError('Invalid number of arguments for delim');
|
|
492
|
+
}
|
|
493
|
+
} else if(g.args![pos_colon + 1].eq(new TypstNode('atom', '#'))) {
|
|
494
|
+
// TODO: should parse #none properly
|
|
495
|
+
if(g.args!.length !== 4 || !g.args![pos_colon + 2].eq(new TypstNode('symbol', 'none'))) {
|
|
496
|
+
throw new TypstParserError('Invalid number of arguments for delim');
|
|
497
|
+
}
|
|
498
|
+
np['delim'] = "#none";
|
|
499
|
+
} else {
|
|
500
|
+
throw new TypstParserError('Not implemented for other types of delim');
|
|
501
|
+
}
|
|
502
|
+
} else {
|
|
503
|
+
throw new TypstParserError('Not implemented for other named parameters');
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
for(let i = to_delete.length - 1; i >= 0; i--) {
|
|
507
|
+
arr.splice(to_delete[i], 1);
|
|
508
|
+
}
|
|
509
|
+
return [arr, np];
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
[row, np] = extract_named_params(row);
|
|
464
513
|
matrix.push(row);
|
|
514
|
+
Object.assign(named_params, np);
|
|
465
515
|
pos = next_stop + 1;
|
|
466
516
|
}
|
|
467
517
|
}
|
|
468
518
|
|
|
469
|
-
return [matrix, end + 1];
|
|
519
|
+
return [matrix, named_params, end + 1];
|
|
470
520
|
}
|
|
471
521
|
|
|
472
522
|
// start: the position of the first token of arguments
|
package/src/writer.ts
CHANGED
|
@@ -544,8 +544,6 @@ function convertToken(token: string): string {
|
|
|
544
544
|
} else if (token === '\\|') {
|
|
545
545
|
// \| in LaTeX is double vertical bar looks like ||
|
|
546
546
|
return 'parallel';
|
|
547
|
-
} else if (token === '\\colon') {
|
|
548
|
-
return ':';
|
|
549
547
|
} else if (token === '\\\\') {
|
|
550
548
|
return '\\';
|
|
551
549
|
} else if (['\\$', '\\#', '\\&', '\\_'].includes(token)) {
|