tex2typst 0.4.0 → 0.5.0

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 CHANGED
@@ -1,4 +1,4 @@
1
- // src/util.ts
1
+ // src/utils.ts
2
2
  function isalpha(char) {
3
3
  return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".includes(char);
4
4
  }
@@ -574,7 +574,8 @@ var TEX_UNARY_COMMANDS = [
574
574
  "mathinner",
575
575
  "mathrel",
576
576
  "mathbin",
577
- "mathop"
577
+ "mathop",
578
+ "not"
578
579
  ];
579
580
  var TEX_BINARY_COMMANDS = [
580
581
  "frac",
@@ -762,19 +763,7 @@ var LatexParser = class {
762
763
  this.newline_sensitive = newline_sensitive;
763
764
  }
764
765
  parse(tokens) {
765
- const token_displaystyle = new TexToken(2 /* COMMAND */, "\\displaystyle");
766
- const idx = array_find(tokens, token_displaystyle);
767
- if (idx === -1) {
768
- return this.parseGroup(tokens.slice(0));
769
- } else if (idx === 0) {
770
- const tree = this.parseGroup(tokens.slice(1));
771
- return new TexFuncCall(token_displaystyle, [tree]);
772
- } else {
773
- const tree1 = this.parseGroup(tokens.slice(0, idx));
774
- const tree2 = this.parseGroup(tokens.slice(idx + 1, tokens.length));
775
- const display = new TexFuncCall(token_displaystyle, [tree2]);
776
- return new TexGroup([tree1, display]);
777
- }
766
+ return this.parseGroup(tokens.slice(0));
778
767
  }
779
768
  parseGroup(tokens) {
780
769
  const [tree, _] = this.parseClosure(tokens, 0, null);
@@ -804,11 +793,12 @@ var LatexParser = class {
804
793
  if (pos >= tokens.length && closingToken !== null) {
805
794
  return [EMPTY_NODE, -1];
806
795
  }
796
+ const styledResults = this.applyStyleCommands(results);
807
797
  let node;
808
- if (results.length === 1) {
809
- node = results[0];
798
+ if (styledResults.length === 1) {
799
+ node = styledResults[0];
810
800
  } else {
811
- node = new TexGroup(results);
801
+ node = new TexGroup(styledResults);
812
802
  }
813
803
  return [node, pos + 1];
814
804
  }
@@ -1066,51 +1056,53 @@ var LatexParser = class {
1066
1056
  this.alignmentDepth++;
1067
1057
  let pos = start;
1068
1058
  pos += eat_whitespaces(tokens, pos).length;
1069
- const allRows = [];
1070
- let row = [];
1071
- allRows.push(row);
1072
- let group = new TexGroup([]);
1073
- row.push(group);
1074
- while (pos < tokens.length) {
1075
- if (tokens[pos].eq(closingToken)) {
1076
- break;
1059
+ let closure;
1060
+ [closure, pos] = this.parseClosure(tokens, pos, closingToken);
1061
+ if (pos === -1) {
1062
+ return [[], -1];
1063
+ }
1064
+ let allRows;
1065
+ if (closure.type === "ordgroup") {
1066
+ const elements = closure.items;
1067
+ while (elements.length > 0 && [5 /* SPACE */, 6 /* NEWLINE */].includes(elements[elements.length - 1].head.type)) {
1068
+ elements.pop();
1077
1069
  }
1078
- const [res, newPos] = this.parseNextExpr(tokens, pos);
1079
- pos = newPos;
1080
- if (res.head.type === 5 /* SPACE */ || res.head.type === 6 /* NEWLINE */) {
1081
- if (!this.space_sensitive && res.head.value.replace(/ /g, "").length === 0) {
1082
- continue;
1083
- }
1084
- if (!this.newline_sensitive && res.head.value === "\n") {
1085
- continue;
1070
+ allRows = array_split(elements, new TexToken(7 /* CONTROL */, "\\\\").toNode()).map((row) => {
1071
+ return array_split(row, new TexToken(7 /* CONTROL */, "&").toNode()).map((arr) => new TexGroup(arr));
1072
+ });
1073
+ } else {
1074
+ allRows = [[closure]];
1075
+ }
1076
+ this.alignmentDepth--;
1077
+ return [allRows, pos];
1078
+ }
1079
+ applyStyleCommands(nodes) {
1080
+ for (let i = 0; i < nodes.length; i++) {
1081
+ const styleToken = this.getStyleToken(nodes[i]);
1082
+ if (styleToken) {
1083
+ const before = this.applyStyleCommands(nodes.slice(0, i));
1084
+ const after = this.applyStyleCommands(nodes.slice(i + 1));
1085
+ let body;
1086
+ if (after.length === 0) {
1087
+ body = EMPTY_NODE;
1088
+ } else if (after.length === 1) {
1089
+ body = after[0];
1090
+ } else {
1091
+ body = new TexGroup(after);
1086
1092
  }
1087
- }
1088
- if (res.head.eq(new TexToken(7 /* CONTROL */, "\\\\"))) {
1089
- row = [];
1090
- group = new TexGroup([]);
1091
- row.push(group);
1092
- allRows.push(row);
1093
- } else if (res.head.eq(new TexToken(7 /* CONTROL */, "&"))) {
1094
- group = new TexGroup([]);
1095
- row.push(group);
1096
- } else {
1097
- group.items.push(res);
1093
+ const funcCall = new TexFuncCall(styleToken, [body]);
1094
+ return before.concat(funcCall);
1098
1095
  }
1099
1096
  }
1100
- if (pos >= tokens.length) {
1101
- return [[], -1];
1102
- }
1103
- if (allRows.length > 0 && allRows[allRows.length - 1].length > 0) {
1104
- const last_cell = allRows[allRows.length - 1][allRows[allRows.length - 1].length - 1];
1105
- if (last_cell.type === "ordgroup") {
1106
- const last_cell_items = last_cell.items;
1107
- while (last_cell_items.length > 0 && [5 /* SPACE */, 6 /* NEWLINE */].includes(last_cell_items[last_cell_items.length - 1].head.type)) {
1108
- last_cell_items.pop();
1109
- }
1097
+ return nodes;
1098
+ }
1099
+ getStyleToken(node) {
1100
+ if (node.type === "terminal") {
1101
+ if (node.head.eq(TexToken.COMMAND_DISPLAYSTYLE) || node.head.eq(TexToken.COMMAND_TEXTSTYLE)) {
1102
+ return node.head;
1110
1103
  }
1111
1104
  }
1112
- this.alignmentDepth--;
1113
- return [allRows, pos + 1];
1105
+ return null;
1114
1106
  }
1115
1107
  };
1116
1108
  function passIgnoreWhitespaceBeforeScriptMark(tokens) {
@@ -1149,6 +1141,7 @@ function parseTex(tex, customTexMacros = {}) {
1149
1141
 
1150
1142
  // src/typst-shorthands.ts
1151
1143
  var shorthandMap = /* @__PURE__ */ new Map([
1144
+ // The following snippet is generated with tools/make-short-hand-map.py
1152
1145
  ["arrow.l.r.double.long", "<==>"],
1153
1146
  ["arrow.l.r.long", "<-->"],
1154
1147
  ["arrow.r.bar", "|->"],
@@ -1163,7 +1156,6 @@ var shorthandMap = /* @__PURE__ */ new Map([
1163
1156
  ["arrow.l.long.squiggly", "<~~"],
1164
1157
  ["arrow.l.tail", "<-<"],
1165
1158
  ["arrow.l.twohead", "<<-"],
1166
- ["arrow.l.r", "<->"],
1167
1159
  ["arrow.l.r.double", "<=>"],
1168
1160
  ["colon.double.eq", "::="],
1169
1161
  ["dots.h", "..."],
@@ -1175,8 +1167,8 @@ var shorthandMap = /* @__PURE__ */ new Map([
1175
1167
  ["arrow.l", "<-"],
1176
1168
  ["arrow.l.squiggly", "<~"],
1177
1169
  ["bar.v.double", "||"],
1178
- ["bracket.l.double", "[|"],
1179
- ["bracket.r.double", "|]"],
1170
+ ["bracket.l.stroked", "[|"],
1171
+ ["bracket.r.stroked", "|]"],
1180
1172
  ["colon.eq", ":="],
1181
1173
  ["eq.colon", "=:"],
1182
1174
  ["eq.not", "!="],
@@ -1186,7 +1178,9 @@ var shorthandMap = /* @__PURE__ */ new Map([
1186
1178
  ["lt.eq", "<="],
1187
1179
  ["ast.op", "*"],
1188
1180
  ["minus", "-"],
1189
- ["tilde.op", "~"]
1181
+ ["tilde.op", "~"],
1182
+ // Typst's documentation doesn't include this. Wondering why
1183
+ ["arrow.l.r", "<->"]
1190
1184
  ]);
1191
1185
  var reverseShorthandMap = /* @__PURE__ */ new Map();
1192
1186
  for (const [key, value] of shorthandMap.entries()) {
@@ -1231,7 +1225,7 @@ var TypstToken = class _TypstToken {
1231
1225
  new _TypstToken(2 /* ELEMENT */, "["),
1232
1226
  new _TypstToken(2 /* ELEMENT */, "{"),
1233
1227
  new _TypstToken(2 /* ELEMENT */, "|"),
1234
- new _TypstToken(1 /* SYMBOL */, "angle.l"),
1228
+ new _TypstToken(1 /* SYMBOL */, "chevron.l"),
1235
1229
  new _TypstToken(1 /* SYMBOL */, "paren.l"),
1236
1230
  new _TypstToken(1 /* SYMBOL */, "brace.l")
1237
1231
  ];
@@ -1240,7 +1234,7 @@ var TypstToken = class _TypstToken {
1240
1234
  new _TypstToken(2 /* ELEMENT */, "]"),
1241
1235
  new _TypstToken(2 /* ELEMENT */, "}"),
1242
1236
  new _TypstToken(2 /* ELEMENT */, "|"),
1243
- new _TypstToken(1 /* SYMBOL */, "angle.r"),
1237
+ new _TypstToken(1 /* SYMBOL */, "chevron.r"),
1244
1238
  new _TypstToken(1 /* SYMBOL */, "paren.r"),
1245
1239
  new _TypstToken(1 /* SYMBOL */, "brace.r")
1246
1240
  ];
@@ -1668,6 +1662,20 @@ var symbolMap = /* @__PURE__ */ new Map([
1668
1662
  [":", "med"],
1669
1663
  [" ", "med"],
1670
1664
  [";", "thick"],
1665
+ ["blacktriangleleft", "triangle.filled.l"],
1666
+ ["blacktriangleright", "triangle.filled.r"],
1667
+ ["clubsuit", "suit.club.filled"],
1668
+ ["hookleftarrow", "arrow.l.hook"],
1669
+ ["hookrightarrow", "arrow.r.hook"],
1670
+ ["leftrightarrow", "arrow.l.r"],
1671
+ ["lgblksquare", "square.filled.big"],
1672
+ ["lgwhtsquare", "square.stroked.big"],
1673
+ ["nearrow", "arrow.tr"],
1674
+ ["nwarrow", "arrow.tl"],
1675
+ ["searrow", "arrow.br"],
1676
+ ["swarrow", "arrow.bl"],
1677
+ ["spadesuit", "suit.spade.filled"],
1678
+ ["updownarrow", "arrow.t.b"],
1671
1679
  /* textual operators */
1672
1680
  ["ln", "ln"],
1673
1681
  ["log", "log"],
@@ -1702,13 +1710,9 @@ var symbolMap = /* @__PURE__ */ new Map([
1702
1710
  ["quad", "quad"],
1703
1711
  ["qquad", "wide"],
1704
1712
  ["overbrace", "overbrace"],
1705
- // same
1706
1713
  ["underbrace", "underbrace"],
1707
- // same
1708
1714
  ["overline", "overline"],
1709
- // same
1710
1715
  ["underline", "underline"],
1711
- // same
1712
1716
  ["bar", "macron"],
1713
1717
  ["dbinom", "binom"],
1714
1718
  ["tbinom", "binom"],
@@ -1784,7 +1788,7 @@ var symbolMap = /* @__PURE__ */ new Map([
1784
1788
  ["geq", "gt.eq"],
1785
1789
  ["geqslant", "gt.eq.slant"],
1786
1790
  ["gg", "gt.double"],
1787
- ["hbar", "planck.reduce"],
1791
+ ["hbar", "planck"],
1788
1792
  ["imath", "dotless.i"],
1789
1793
  ["iiiint", "integral.quad"],
1790
1794
  ["iiint", "integral.triple"],
@@ -1799,7 +1803,7 @@ var symbolMap = /* @__PURE__ */ new Map([
1799
1803
  ["kappa", "kappa"],
1800
1804
  ["lambda", "lambda"],
1801
1805
  ["land", "and"],
1802
- ["langle", "angle.l"],
1806
+ ["langle", "chevron.l"],
1803
1807
  ["lbrace", "brace.l"],
1804
1808
  ["lbrack", "bracket.l"],
1805
1809
  ["ldots", "dots.h"],
@@ -1861,7 +1865,7 @@ var symbolMap = /* @__PURE__ */ new Map([
1861
1865
  ["prod", "product"],
1862
1866
  ["propto", "prop"],
1863
1867
  ["psi", "psi"],
1864
- ["rangle", "angle.r"],
1868
+ ["rangle", "chevron.r"],
1865
1869
  ["rbrace", "brace.r"],
1866
1870
  ["rbrack", "bracket.r"],
1867
1871
  ["rhd", "triangle"],
@@ -1934,6 +1938,7 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
1934
1938
  ["approxident", "tilde.triple"],
1935
1939
  ["assert", "tack.r.short"],
1936
1940
  ["ast", "ast.op"],
1941
+ ["astrosun", "sun"],
1937
1942
  ["asymp", "asymp"],
1938
1943
  ["awint", "integral.ccw"],
1939
1944
  ["backcong", "tilde.rev.equiv"],
@@ -1989,10 +1994,9 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
1989
1994
  ["bigcup", "union.big"],
1990
1995
  ["bigcupdot", "union.dot.big"],
1991
1996
  ["biginterleave", "interleave.big"],
1992
- ["bigodot", "dot.circle.big"],
1993
- ["bigoplus", "plus.circle.big"],
1994
- // or 'xor.big'
1995
- ["bigotimes", "times.circle.big"],
1997
+ ["bigodot", "dot.o.big"],
1998
+ ["bigoplus", "plus.o.big"],
1999
+ ["bigotimes", "times.o.big"],
1996
2000
  ["bigsqcap", "inter.sq.big"],
1997
2001
  ["bigsqcup", "union.sq.big"],
1998
2002
  ["bigstar", "star.filled"],
@@ -2009,8 +2013,6 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2009
2013
  ["blackhourglass", "hourglass.filled"],
2010
2014
  ["blacktriangle", "triangle.filled.small.t"],
2011
2015
  ["blacktriangledown", "triangle.filled.small.b"],
2012
- ["blacktriangleleft", "triangle.filled.l"],
2013
- ["blacktriangleright", "triangle.filled.r"],
2014
2016
  ["blkhorzoval", "ellipse.filled.h"],
2015
2017
  ["blkvertoval", "ellipse.filled.v"],
2016
2018
  ["bot", "bot"],
@@ -2027,13 +2029,14 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2027
2029
  ["cdot", "dot.op"],
2028
2030
  ["cdotp", "dot.c"],
2029
2031
  ["checkmark", "checkmark"],
2030
- ["circledast", "ast.circle"],
2031
- ["circledcirc", "circle.nested"],
2032
- ["circleddash", "dash.circle"],
2033
- ["circledequal", "eq.circle"],
2034
- ["circledparallel", "parallel.circle"],
2035
- ["circledvert", "bar.v.circle"],
2036
- ["clubsuit", "suit.club.filled"],
2032
+ ["circledast", "ast.op.o"],
2033
+ ["circledbullet", "bullet.o"],
2034
+ ["circledcirc", "compose.o"],
2035
+ ["circleddash", "dash.o"],
2036
+ ["circledequal", "cc.nd"],
2037
+ ["circledparallel", "parallel.o"],
2038
+ ["circledvert", "bar.v.o"],
2039
+ ["circledwhitebullet", "bullet.stroked.o"],
2037
2040
  ["Colon", "colon.double"],
2038
2041
  ["coloneq", "colon.eq"],
2039
2042
  ["Coloneq", "colon.double.eq"],
@@ -2084,6 +2087,7 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2084
2087
  ["downarrow", "arrow.b"],
2085
2088
  ["Downarrow", "arrow.b.double"],
2086
2089
  ["downarrowbar", "arrow.b.stop"],
2090
+ ["downarrowbarred", "arrow.b.struck"],
2087
2091
  ["downdasharrow", "arrow.b.dashed"],
2088
2092
  ["downdownarrows", "arrows.bb"],
2089
2093
  ["downharpoonleft", "harpoon.bl"],
@@ -2091,7 +2095,6 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2091
2095
  ["downharpoonright", "harpoon.br"],
2092
2096
  ["downharpoonrightbar", "harpoon.br.stop"],
2093
2097
  ["downharpoonsleftright", "harpoons.blbr"],
2094
- ["downrightcurvedarrow", "arrow.b.curve"],
2095
2098
  ["downuparrows", "arrows.bt"],
2096
2099
  ["downupharpoonsleftright", "harpoons.bltr"],
2097
2100
  ["downwhitearrow", "arrow.b.stroked"],
@@ -2124,13 +2127,13 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2124
2127
  ["errbardiamond", "errorbar.diamond.stroked"],
2125
2128
  ["errbarsquare", "errorbar.square.stroked"],
2126
2129
  ["euro", "euro"],
2127
- ["Exclam", "excl.double"],
2128
2130
  ["exists", "exists"],
2129
2131
  ["fallingdotseq", "eq.dots.down"],
2130
2132
  ["fint", "integral.slash"],
2131
2133
  ["flat", "flat"],
2132
2134
  ["forall", "forall"],
2133
2135
  ["fourvdots", "fence.dotted"],
2136
+ ["frown", "frown"],
2134
2137
  ["fullouterjoin", "join.l.r"],
2135
2138
  ["geq", "gt.eq"],
2136
2139
  ["geqq", "gt.equiv"],
@@ -2154,14 +2157,11 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2154
2157
  ["hknwarrow", "arrow.tl.hook"],
2155
2158
  ["hksearrow", "arrow.br.hook"],
2156
2159
  ["hkswarrow", "arrow.bl.hook"],
2157
- ["hookleftarrow", "arrow.l.hook"],
2158
- ["hookrightarrow", "arrow.r.hook"],
2159
2160
  ["horizbar", "bar.h"],
2160
2161
  ["hourglass", "hourglass.stroked"],
2161
2162
  ["hrectangle", "rect.stroked.h"],
2162
2163
  ["hrectangleblack", "rect.filled.h"],
2163
- ["hslash", "planck.reduce"],
2164
- ["hzigzag", "dash.wave.double"],
2164
+ ["hyphenbullet", "bullet.hyph"],
2165
2165
  ["iiiint", "integral.quad"],
2166
2166
  ["iiint", "integral.triple"],
2167
2167
  ["iinfin", "infinity.incomplete"],
@@ -2180,23 +2180,29 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2180
2180
  ["interleave", "interleave"],
2181
2181
  ["intlarhk", "integral.arrow.hook"],
2182
2182
  ["intx", "integral.times"],
2183
+ ["inversebullet", "bullet.hole"],
2183
2184
  ["Join", "join"],
2184
- ["langle", "angle.l"],
2185
- ["lAngle", "angle.l.double"],
2186
- ["langledot", "angle.l.dot"],
2185
+ ["langle", "chevron.l"],
2186
+ ["lAngle", "chevron.l.double"],
2187
+ ["langledot", "chevron.l.dot"],
2187
2188
  ["lat", "lat"],
2188
2189
  ["late", "lat.eq"],
2190
+ ["lbag", "bag.l"],
2191
+ ["lblkbrbrak", "shell.l.filled"],
2189
2192
  ["lbrace", "brace.l"],
2190
- ["lBrace", "brace.l.double"],
2193
+ ["lBrace", "brace.l.stroked"],
2191
2194
  ["lbrack", "bracket.l"],
2192
- ["lBrack", "bracket.l.double"],
2195
+ ["lBrack", "bracket.l.stroked"],
2196
+ ["lbracklltick", "bracket.l.tick.b"],
2197
+ ["lbrackultick", "bracket.l.tick.t"],
2193
2198
  ["lbrbrak", "shell.l"],
2194
- ["Lbrbrak", "shell.l.double"],
2199
+ ["Lbrbrak", "shell.l.stroked"],
2195
2200
  ["lceil", "ceil.l"],
2196
- ["lcurvyangle", "angle.l.curly"],
2201
+ ["lcurvyangle", "chevron.l.curly"],
2197
2202
  ["leftarrow", "arrow.l"],
2198
2203
  ["Leftarrow", "arrow.l.double"],
2199
2204
  ["leftarrowtail", "arrow.l.tail"],
2205
+ ["leftarrowtriangle", "arrow.l.open"],
2200
2206
  ["leftdasharrow", "arrow.l.dashed"],
2201
2207
  ["leftdotarrow", "arrow.l.dotted"],
2202
2208
  ["leftdowncurvedarrow", "arrow.l.curve"],
@@ -2207,9 +2213,9 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2207
2213
  ["leftharpoonupbar", "harpoon.lt.bar"],
2208
2214
  ["leftleftarrows", "arrows.ll"],
2209
2215
  ["leftouterjoin", "join.l"],
2210
- ["leftrightarrow", "arrow.l.r"],
2211
2216
  ["Leftrightarrow", "arrow.l.r.double"],
2212
2217
  ["leftrightarrows", "arrows.lr"],
2218
+ ["leftrightarrowtriangle", "arrow.l.r.open"],
2213
2219
  ["leftrightharpoondowndown", "harpoon.lb.rb"],
2214
2220
  ["leftrightharpoondownup", "harpoon.lb.rt"],
2215
2221
  ["leftrightharpoons", "harpoons.ltrb"],
@@ -2234,16 +2240,19 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2234
2240
  ["lesssim", "lt.tilde"],
2235
2241
  ["lfloor", "floor.l"],
2236
2242
  ["lgblkcircle", "circle.filled.big"],
2237
- ["lgblksquare", "square.filled.big"],
2243
+ ["lgroup", "paren.l.flat"],
2238
2244
  ["lgwhtcircle", "circle.stroked.big"],
2239
- ["lgwhtsquare", "square.stroked.big"],
2240
2245
  ["ll", "lt.double"],
2246
+ ["llangle", "chevron.l.closed"],
2241
2247
  ["llblacktriangle", "triangle.filled.bl"],
2248
+ ["llcorner", "corner.l.b"],
2242
2249
  ["LLeftarrow", "arrow.l.quad"],
2243
2250
  ["Lleftarrow", "arrow.l.triple"],
2244
2251
  ["lll", "lt.triple"],
2245
2252
  ["lllnest", "lt.triple.nested"],
2253
+ ["llparenthesis", "paren.l.closed"],
2246
2254
  ["lltriangle", "triangle.stroked.bl"],
2255
+ ["lmoustache", "mustache.l"],
2247
2256
  ["lnapprox", "lt.napprox"],
2248
2257
  ["lneq", "lt.neq"],
2249
2258
  ["lneqq", "lt.nequiv"],
@@ -2264,8 +2273,9 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2264
2273
  ["looparrowleft", "arrow.l.loop"],
2265
2274
  ["looparrowright", "arrow.r.loop"],
2266
2275
  ["lparen", "paren.l"],
2267
- ["lParen", "paren.l.double"],
2276
+ ["lParen", "paren.l.stroked"],
2268
2277
  ["lrblacktriangle", "triangle.filled.br"],
2278
+ ["lrcorner", "corner.r.b"],
2269
2279
  ["lrtriangle", "triangle.stroked.br"],
2270
2280
  ["ltimes", "times.l"],
2271
2281
  ["lvzigzag", "fence.l"],
@@ -2283,8 +2293,8 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2283
2293
  ["mathcomma", "comma"],
2284
2294
  ["mathdollar", "dollar"],
2285
2295
  ["mathexclam", "excl"],
2286
- // ['mathhyphen', 'hyph'], // \mathhyphen is not defined in standard amsmath package
2287
- ["mathoctothorpe", "hash"],
2296
+ ["mathhyphen", "hyph"],
2297
+ // \mathhyphen is not defined in standard amsmath package
2288
2298
  ["mathparagraph", "pilcrow"],
2289
2299
  ["mathpercent", "percent"],
2290
2300
  ["mathperiod", "dot.basic"],
@@ -2298,7 +2308,6 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2298
2308
  ["mathyen", "yen"],
2299
2309
  ["mdblkdiamond", "diamond.filled.medium"],
2300
2310
  ["mdblklozenge", "lozenge.filled.medium"],
2301
- ["mdblksquare", "square.filled.medium"],
2302
2311
  ["mdlgblkcircle", "circle.filled"],
2303
2312
  ["mdlgblkdiamond", "diamond.filled"],
2304
2313
  ["mdlgblklozenge", "lozenge.filled"],
@@ -2308,12 +2317,9 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2308
2317
  ["mdlgwhtlozenge", "lozenge.stroked"],
2309
2318
  ["mdlgwhtsquare", "square.stroked"],
2310
2319
  ["mdsmblkcircle", "circle.filled.tiny"],
2311
- ["mdsmblksquare", "square.filled.small"],
2312
2320
  ["mdsmwhtcircle", "circle.stroked.small"],
2313
- ["mdsmwhtsquare", "square.stroked.small"],
2314
2321
  ["mdwhtdiamond", "diamond.stroked.medium"],
2315
2322
  ["mdwhtlozenge", "lozenge.stroked.medium"],
2316
- ["mdwhtsquare", "square.stroked.medium"],
2317
2323
  ["measeq", "eq.m"],
2318
2324
  ["measuredangle", "angle.arc"],
2319
2325
  ["measuredangleleft", "angle.arc.rev"],
@@ -2374,6 +2380,7 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2374
2380
  ['mupvarpi', 'pi.alt'],
2375
2381
  ['mupvarrho', 'rho.alt'],
2376
2382
  ['mupvarsigma', 'sigma.alt'],
2383
+ ['mupvarTheta', 'Theta.alt'],
2377
2384
  ['mupvartheta', 'theta.alt'],
2378
2385
  ['mupXi', 'Xi'],
2379
2386
  ['mupxi', 'xi'],
@@ -2385,7 +2392,6 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2385
2392
  ["natural", "natural"],
2386
2393
  ["ncong", "tilde.equiv.not"],
2387
2394
  ["ne", "eq.not"],
2388
- ["nearrow", "arrow.tr"],
2389
2395
  ["Nearrow", "arrow.tr.double"],
2390
2396
  ["neg", "not"],
2391
2397
  ["nequiv", "equiv.not"],
@@ -2396,7 +2402,9 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2396
2402
  ["ngtr", "gt.not"],
2397
2403
  ["ngtrless", "gt.lt.not"],
2398
2404
  ["ngtrsim", "gt.tilde.not"],
2405
+ ["nHdownarrow", "arrow.b.dstruck"],
2399
2406
  ["nhpar", "parallel.struck"],
2407
+ ["nHuparrow", "arrow.t.dstruck"],
2400
2408
  ["nhVvert", "interleave.struck"],
2401
2409
  ["ni", "in.rev"],
2402
2410
  ["nLeftarrow", "arrow.l.double.not"],
@@ -2433,36 +2441,62 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2433
2441
  ["nvdash", "tack.r.not"],
2434
2442
  ["nvDash", "tack.r.double.not"],
2435
2443
  ["nvinfty", "infinity.bar"],
2436
- ["nwarrow", "arrow.tl"],
2444
+ ["nvLeftarrow", "arrow.l.double.struck"],
2445
+ ["nvleftarrow", "arrow.l.struck"],
2446
+ ["nVleftarrow", "arrow.l.dstruck"],
2447
+ ["nvleftarrowtail", "arrow.l.tail.struck"],
2448
+ ["nVleftarrowtail", "arrow.l.tail.dstruck"],
2449
+ ["nvLeftrightarrow", "arrow.l.r.double.struck"],
2450
+ ["nvleftrightarrow", "arrow.l.r.struck"],
2451
+ ["nVleftrightarrow", "arrow.l.r.dstruck"],
2452
+ ["nvRightarrow", "arrow.r.double.struck"],
2453
+ ["nvrightarrow", "arrow.r.struck"],
2454
+ ["nVrightarrow", "arrow.r.dstruck"],
2455
+ ["nvrightarrowtail", "arrow.r.tail.struck"],
2456
+ ["nVrightarrowtail", "arrow.r.tail.dstruck"],
2457
+ ["nvtwoheadleftarrow", "arrow.l.twohead.struck"],
2458
+ ["nVtwoheadleftarrow", "arrow.l.twohead.dstruck"],
2459
+ ["nvtwoheadleftarrowtail", "arrow.l.twohead.tail.struck"],
2460
+ ["nVtwoheadleftarrowtail", "arrow.l.twohead.tail.dstruck"],
2461
+ ["nvtwoheadrightarrow", "arrow.r.twohead.struck"],
2462
+ ["nVtwoheadrightarrow", "arrow.r.twohead.dstruck"],
2463
+ ["nvtwoheadrightarrowtail", "arrow.r.twohead.tail.struck"],
2464
+ ["nVtwoheadrightarrowtail", "arrow.r.twohead.tail.dstruck"],
2437
2465
  ["Nwarrow", "arrow.tl.double"],
2438
2466
  ["nwsearrow", "arrow.tl.br"],
2439
2467
  ["obrbrak", "shell.t"],
2440
- ["obslash", "backslash.circle"],
2441
- ["odiv", "div.circle"],
2442
- ["odot", "dot.circle"],
2443
- ["ogreaterthan", "gt.circle"],
2468
+ ["obslash", "backslash.o"],
2469
+ ["odiv", "div.o"],
2470
+ ["odot", "dot.o"],
2471
+ ["odotslashdot", "div.slanted.o"],
2472
+ ["ogreaterthan", "gt.o"],
2444
2473
  ["oiiint", "integral.vol"],
2445
2474
  ["oiint", "integral.surf"],
2446
2475
  ["oint", "integral.cont"],
2447
2476
  ["ointctrclockwise", "integral.cont.ccw"],
2448
- ["olessthan", "lt.circle"],
2449
- ["ominus", "minus.circle"],
2450
- ["operp", "perp.circle"],
2451
- ["oplus", "plus.circle"],
2477
+ ["olessthan", "lt.o"],
2478
+ ["ominus", "minus.o"],
2479
+ ["operp", "perp.o"],
2480
+ ["oplus", "plus.o"],
2481
+ ["opluslhrim", "plus.o.l"],
2482
+ ["oplusrhrim", "plus.o.r"],
2452
2483
  ["origof", "original"],
2453
- ["otimes", "times.circle"],
2484
+ ["oslash", "slash.o"],
2485
+ ["otimes", "times.o"],
2486
+ ["otimeshat", "times.o.hat"],
2487
+ ["otimeslhrim", "times.o.l"],
2488
+ ["otimesrhrim", "times.o.r"],
2454
2489
  // ['overbrace', 'brace.t'],
2455
- ["overbracket", "bracket.t"],
2456
- ["overparen", "paren.t"],
2490
+ // ['overbracket', 'bracket.t'],
2491
+ // ['overparen', 'paren.t'],
2457
2492
  ["parallel", "parallel"],
2458
2493
  ["parallelogram", "parallelogram.stroked"],
2459
2494
  ["parallelogramblack", "parallelogram.filled"],
2460
2495
  ["parsim", "parallel.tilde"],
2461
- ["partial", "diff"],
2496
+ ["partial", "partial"],
2462
2497
  ["pentagon", "penta.stroked"],
2463
2498
  ["pentagonblack", "penta.filled"],
2464
2499
  ["perp", "perp"],
2465
- ["Planckconst", "planck"],
2466
2500
  ["pm", "plus.minus"],
2467
2501
  ["prec", "prec"],
2468
2502
  ["Prec", "prec.double"],
@@ -2483,30 +2517,37 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2483
2517
  ["quarternote", "note.quarter.alt"],
2484
2518
  ["questeq", "eq.quest"],
2485
2519
  ["Question", "quest.double"],
2486
- ["rangle", "angle.r"],
2487
- ["rAngle", "angle.r.double"],
2488
- ["rangledot", "angle.r.dot"],
2520
+ ["rangle", "chevron.r"],
2521
+ ["rAngle", "chevron.r.double"],
2522
+ ["rangledot", "chevron.r.dot"],
2523
+ ["rangledownzigzagarrow", "angle.azimuth"],
2524
+ ["rbag", "bag.r"],
2525
+ ["rblkbrbrak", "shell.r.filled"],
2489
2526
  ["rbrace", "brace.r"],
2490
- ["rBrace", "brace.r.double"],
2527
+ ["rBrace", "brace.r.stroked"],
2491
2528
  ["rbrack", "bracket.r"],
2492
- ["rBrack", "bracket.r.double"],
2529
+ ["rBrack", "bracket.r.stroked"],
2530
+ ["rbracklrtick", "bracket.r.tick.b"],
2531
+ ["rbrackurtick", "bracket.r.tick.t"],
2493
2532
  ["rbrbrak", "shell.r"],
2494
- ["Rbrbrak", "shell.r.double"],
2533
+ ["Rbrbrak", "shell.r.stroked"],
2495
2534
  ["rceil", "ceil.r"],
2496
- ["rcurvyangle", "angle.r.curly"],
2535
+ ["rcurvyangle", "chevron.r.curly"],
2497
2536
  ["Re", "Re"],
2498
2537
  ["revangle", "angle.rev"],
2499
2538
  ["revemptyset", "emptyset.rev"],
2500
2539
  ["revnmid", "divides.not.rev"],
2501
2540
  ["rfloor", "floor.r"],
2541
+ ["rgroup", "paren.r.flat"],
2502
2542
  ["rightangle", "angle.right"],
2503
2543
  ["rightanglemdot", "angle.right.dot"],
2504
- ["rightanglesqr", "angle.right.sq"],
2544
+ ["rightanglesqr", "angle.right.square"],
2505
2545
  ["rightarrow", "arrow.r"],
2506
2546
  ["Rightarrow", "arrow.r.double"],
2507
2547
  ["rightarrowbar", "arrow.r.stop"],
2508
- ["rightarrowonoplus", "plus.circle.arrow"],
2548
+ ["rightarrowonoplus", "plus.o.arrow"],
2509
2549
  ["rightarrowtail", "arrow.r.tail"],
2550
+ ["rightarrowtriangle", "arrow.r.open"],
2510
2551
  ["rightdasharrow", "arrow.r.dashed"],
2511
2552
  ["rightdotarrow", "arrow.r.dotted"],
2512
2553
  ["rightdowncurvedarrow", "arrow.r.curve"],
@@ -2527,15 +2568,17 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2527
2568
  ["rightwavearrow", "arrow.r.wave"],
2528
2569
  ["rightwhitearrow", "arrow.r.stroked"],
2529
2570
  ["risingdotseq", "eq.dots.up"],
2571
+ ["rmoustache", "mustache.r"],
2530
2572
  ["rparen", "paren.r"],
2531
- ["rParen", "paren.r.double"],
2573
+ ["rParen", "paren.r.stroked"],
2574
+ ["rrangle", "chevron.r.closed"],
2532
2575
  ["RRightarrow", "arrow.r.quad"],
2533
2576
  ["Rrightarrow", "arrow.r.triple"],
2577
+ ["rrparenthesis", "paren.r.closed"],
2534
2578
  ["rsolbar", "backslash.not"],
2535
2579
  ["rtimes", "times.r"],
2536
2580
  ["rvzigzag", "fence.r"],
2537
2581
  ["Rvzigzag", "fence.r.double"],
2538
- ["searrow", "arrow.br"],
2539
2582
  ["Searrow", "arrow.br.double"],
2540
2583
  ["setminus", "without"],
2541
2584
  ["sharp", "sharp"],
@@ -2557,16 +2600,15 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2557
2600
  ["smblkcircle", "bullet"],
2558
2601
  ["smblkdiamond", "diamond.filled.small"],
2559
2602
  ["smblklozenge", "lozenge.filled.small"],
2560
- ["smblksquare", "square.filled.tiny"],
2561
2603
  ["smeparsl", "parallel.slanted.eq.tilde"],
2604
+ ["smile", "smile"],
2562
2605
  ["smt", "smt"],
2563
2606
  ["smte", "smt.eq"],
2607
+ ["smwhtcircle", "bullet.stroked"],
2564
2608
  ["smwhtdiamond", "diamond.stroked.small"],
2565
2609
  ["smwhtlozenge", "lozenge.stroked.small"],
2566
- ["smwhtsquare", "square.stroked.tiny"],
2567
- ["spadesuit", "suit.spade.filled"],
2568
2610
  ["sphericalangle", "angle.spheric"],
2569
- ["sphericalangleup", "angle.spheric.top"],
2611
+ ["sphericalangleup", "angle.spheric.t"],
2570
2612
  ["sqcap", "inter.sq"],
2571
2613
  ["Sqcap", "inter.sq.double"],
2572
2614
  ["sqcup", "union.sq"],
@@ -2605,7 +2647,6 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2605
2647
  ["supsetdot", "supset.dot"],
2606
2648
  ["supseteq", "supset.eq"],
2607
2649
  ["supsetneq", "supset.neq"],
2608
- ["swarrow", "arrow.bl"],
2609
2650
  ["Swarrow", "arrow.bl.double"],
2610
2651
  ["therefore", "therefore"],
2611
2652
  ["threedangle", "angle.spatial"],
@@ -2628,15 +2669,19 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2628
2669
  ["tripleplus", "plus.triple"],
2629
2670
  ["trprime", "prime.triple"],
2630
2671
  ["trslash", "slash.triple"],
2672
+ ["turnediota", "iota.inv"],
2631
2673
  ["twoheaddownarrow", "arrow.b.twohead"],
2632
2674
  ["twoheadleftarrow", "arrow.l.twohead"],
2675
+ ["twoheadleftarrowtail", "arrow.l.twohead.tail"],
2633
2676
  ["twoheadmapsfrom", "arrow.l.twohead.bar"],
2634
2677
  ["twoheadmapsto", "arrow.r.twohead.bar"],
2635
2678
  ["twoheadrightarrow", "arrow.r.twohead"],
2679
+ ["twoheadrightarrowtail", "arrow.r.twohead.tail"],
2636
2680
  ["twoheaduparrow", "arrow.t.twohead"],
2637
2681
  ["twonotes", "note.eighth.beamed"],
2638
2682
  ["ubrbrak", "shell.b"],
2639
2683
  ["ulblacktriangle", "triangle.filled.tl"],
2684
+ ["ulcorner", "corner.l.t"],
2640
2685
  ["ultriangle", "triangle.stroked.tl"],
2641
2686
  ["uminus", "union.minus"],
2642
2687
  ["underbrace", "brace.b"],
@@ -2647,8 +2692,11 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2647
2692
  ["upand", "amp.inv"],
2648
2693
  ["uparrow", "arrow.t"],
2649
2694
  ["Uparrow", "arrow.t.double"],
2695
+ ["uparrowbarred", "arrow.t.struck"],
2696
+ ["upbackepsilon", "epsilon.alt.rev"],
2650
2697
  ["updasharrow", "arrow.t.dashed"],
2651
- ["updownarrow", "arrow.t.b"],
2698
+ ["upDigamma", "Digamma"],
2699
+ ["updigamma", "digamma"],
2652
2700
  ["Updownarrow", "arrow.t.b.double"],
2653
2701
  ["updownarrows", "arrows.tb"],
2654
2702
  ["updownharpoonleftleft", "harpoon.tl.bl"],
@@ -2662,16 +2710,14 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2662
2710
  ["upharpoonrightbar", "harpoon.tr.bar"],
2663
2711
  ["upharpoonsleftright", "harpoons.tltr"],
2664
2712
  ["uplus", "union.plus"],
2665
- ["uprightcurvearrow", "arrow.t.curve"],
2666
2713
  ["upuparrows", "arrows.tt"],
2667
2714
  ["upwhitearrow", "arrow.t.stroked"],
2668
2715
  ["urblacktriangle", "triangle.filled.tr"],
2716
+ ["urcorner", "corner.r.t"],
2669
2717
  ["urtriangle", "triangle.stroked.tr"],
2670
2718
  ["UUparrow", "arrow.t.quad"],
2671
2719
  ["Uuparrow", "arrow.t.triple"],
2672
2720
  ["varclubsuit", "suit.club.stroked"],
2673
- ["vardiamondsuit", "suit.diamond.filled"],
2674
- ["varheartsuit", "suit.heart.filled"],
2675
2721
  ["varhexagon", "hexa.stroked"],
2676
2722
  ["varhexagonblack", "hexa.filled"],
2677
2723
  ["varnothing", "emptyset"],
@@ -2696,6 +2742,7 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2696
2742
  ["vrectangleblack", "rect.filled.v"],
2697
2743
  ["Vvert", "bar.v.triple"],
2698
2744
  ["vysmblkcircle", "circle.filled.small"],
2745
+ // or bullet.op
2699
2746
  ["vysmwhtcircle", "circle.stroked.tiny"],
2700
2747
  // or compose
2701
2748
  ["wedge", "and"],
@@ -2705,7 +2752,7 @@ var map_from_official_docs = /* @__PURE__ */ new Map([
2705
2752
  ["whiteinwhitetriangle", "triangle.stroked.nested"],
2706
2753
  ["whthorzoval", "ellipse.stroked.h"],
2707
2754
  ["whtvertoval", "ellipse.stroked.v"],
2708
- ["wideangledown", "angle.oblique"],
2755
+ ["wideangledown", "angle.obtuse"],
2709
2756
  ["wr", "wreath"],
2710
2757
  ["xsol", "slash.big"]
2711
2758
  ]);
@@ -2889,23 +2936,8 @@ function convert_tex_array_align_literal(alignLiteral) {
2889
2936
  }
2890
2937
  var TYPST_LEFT_PARENTHESIS3 = new TypstToken(2 /* ELEMENT */, "(");
2891
2938
  var TYPST_RIGHT_PARENTHESIS3 = new TypstToken(2 /* ELEMENT */, ")");
2892
- function is_delimiter(c) {
2893
- return c.head.type === 2 /* ELEMENT */ && ["(", ")", "[", "]", "{", "}", "|", "\u230A", "\u230B", "\u2308", "\u2309"].includes(c.head.value);
2894
- }
2895
2939
  function appendWithBracketsIfNeeded(node) {
2896
2940
  let need_to_wrap = ["group", "supsub", "matrixLike", "fraction", "empty"].includes(node.type);
2897
- if (node.type === "group") {
2898
- const group = node;
2899
- if (group.items.length === 0) {
2900
- need_to_wrap = true;
2901
- } else {
2902
- const first = group.items[0];
2903
- const last = group.items[group.items.length - 1];
2904
- if (is_delimiter(first) && is_delimiter(last)) {
2905
- need_to_wrap = false;
2906
- }
2907
- }
2908
- }
2909
2941
  if (need_to_wrap) {
2910
2942
  return new TypstLeftright(null, {
2911
2943
  left: TYPST_LEFT_PARENTHESIS3,
@@ -2950,7 +2982,6 @@ function convert_tex_node_to_typst(abstractNode, options) {
2950
2982
  sup: sup ? convert_tex_node_to_typst(sup, options) : null,
2951
2983
  sub: sub ? convert_tex_node_to_typst(sub, options) : null
2952
2984
  };
2953
- data.base = appendWithBracketsIfNeeded(data.base);
2954
2985
  if (data.sup) {
2955
2986
  data.sup = appendWithBracketsIfNeeded(data.sup);
2956
2987
  }
@@ -3083,6 +3114,20 @@ function convert_tex_node_to_typst(abstractNode, options) {
3083
3114
  { body: arg0, left: TypstToken.LEFT_BRACE, right: TypstToken.RIGHT_BRACE }
3084
3115
  );
3085
3116
  }
3117
+ if (node2.head.value === "\\not") {
3118
+ const sym = convert_tex_node_to_typst(node2.args[0], options);
3119
+ assert(sym.type === "terminal");
3120
+ if (sym.head.type === 1 /* SYMBOL */) {
3121
+ return new TypstToken(1 /* SYMBOL */, sym.head.value + ".not").toNode();
3122
+ } else {
3123
+ switch (sym.head.value) {
3124
+ case "=":
3125
+ return new TypstToken(1 /* SYMBOL */, "eq.not").toNode();
3126
+ default:
3127
+ throw new Error(`Not supported: \\not ${sym.head.value}`);
3128
+ }
3129
+ }
3130
+ }
3086
3131
  if (node2.head.value === "\\overset") {
3087
3132
  return convert_overset(node2, options);
3088
3133
  }
@@ -3182,12 +3227,28 @@ function typst_token_to_tex(token) {
3182
3227
  return TexToken.EMPTY;
3183
3228
  case 1 /* SYMBOL */: {
3184
3229
  const _typst_symbol_to_tex = function(symbol) {
3185
- if (reverseSymbolMap.has(symbol)) {
3186
- return "\\" + reverseSymbolMap.get(symbol);
3187
- } else {
3188
- return "\\" + symbol;
3230
+ switch (symbol) {
3231
+ case "eq":
3232
+ return "=";
3233
+ case "plus":
3234
+ return "+";
3235
+ case "minus":
3236
+ return "-";
3237
+ case "percent":
3238
+ return "%";
3239
+ default: {
3240
+ if (reverseSymbolMap.has(symbol)) {
3241
+ return "\\" + reverseSymbolMap.get(symbol);
3242
+ } else {
3243
+ return "\\" + symbol;
3244
+ }
3245
+ }
3189
3246
  }
3190
3247
  };
3248
+ if (token.value.endsWith(".not")) {
3249
+ const sym = _typst_symbol_to_tex(token.value.slice(0, -4));
3250
+ return new TexToken(2 /* COMMAND */, sym.startsWith("\\") ? `\\not${sym}` : `\\not ${sym}`);
3251
+ }
3191
3252
  return new TexToken(2 /* COMMAND */, _typst_symbol_to_tex(token.value));
3192
3253
  }
3193
3254
  case 2 /* ELEMENT */: {
@@ -3632,32 +3693,34 @@ function find_closing_match(tokens, start) {
3632
3693
  [RIGHT_PARENTHESES, RIGHT_BRACKET, RIGHT_CURLY_BRACKET2]
3633
3694
  );
3634
3695
  }
3635
- function find_closing_delim(tokens, start) {
3636
- return _find_closing_match(
3637
- tokens,
3638
- start,
3639
- TypstToken.LEFT_DELIMITERS,
3640
- TypstToken.RIGHT_DELIMITERS
3641
- );
3642
- }
3643
- function find_closing_parenthesis(nodes, start) {
3644
- const left_parenthesis = new TypstToken(2 /* ELEMENT */, "(").toNode();
3645
- const right_parenthesis = new TypstToken(2 /* ELEMENT */, ")").toNode();
3646
- assert(nodes[start].eq(left_parenthesis));
3647
- let count = 1;
3648
- let pos = start + 1;
3649
- while (count > 0) {
3650
- if (pos >= nodes.length) {
3651
- throw new Error("Unmatched '('");
3696
+ function extract_named_params(arr) {
3697
+ const COLON = new TypstToken(2 /* ELEMENT */, ":").toNode();
3698
+ const np = {};
3699
+ const to_delete = [];
3700
+ for (let i = 0; i < arr.length; i++) {
3701
+ if (arr[i].type !== "group") {
3702
+ continue;
3652
3703
  }
3653
- if (nodes[pos].eq(left_parenthesis)) {
3654
- count += 1;
3655
- } else if (nodes[pos].eq(right_parenthesis)) {
3656
- count -= 1;
3704
+ const g = arr[i];
3705
+ const pos_colon = array_find(g.items, COLON);
3706
+ if (pos_colon === -1 || pos_colon === 0) {
3707
+ continue;
3708
+ }
3709
+ to_delete.push(i);
3710
+ const param_name = g.items[pos_colon - 1];
3711
+ if (param_name.eq(new TypstToken(1 /* SYMBOL */, "delim").toNode())) {
3712
+ if (g.items.length !== 3) {
3713
+ throw new TypstParserError("Invalid number of arguments for delim");
3714
+ }
3715
+ np["delim"] = g.items[pos_colon + 1];
3716
+ } else {
3717
+ throw new TypstParserError("Not implemented for other named parameters");
3657
3718
  }
3658
- pos += 1;
3659
3719
  }
3660
- return pos - 1;
3720
+ for (let i = to_delete.length - 1; i >= 0; i--) {
3721
+ arr.splice(to_delete[i], 1);
3722
+ }
3723
+ return [arr, np];
3661
3724
  }
3662
3725
  function primes(num) {
3663
3726
  const res = [];
@@ -3696,30 +3759,16 @@ function trim_whitespace_around_operators(nodes) {
3696
3759
  }
3697
3760
  return res;
3698
3761
  }
3699
- function process_operators(nodes, parenthesis = false) {
3762
+ function process_operators(nodes) {
3700
3763
  nodes = trim_whitespace_around_operators(nodes);
3701
- const opening_bracket = LEFT_PARENTHESES.toNode();
3702
- const closing_bracket = RIGHT_PARENTHESES.toNode();
3703
3764
  const stack = [];
3704
3765
  const args = [];
3705
3766
  let pos = 0;
3706
3767
  while (pos < nodes.length) {
3707
- const current = nodes[pos];
3708
- if (current.eq(closing_bracket)) {
3709
- throw new TypstParserError("Unexpected ')'");
3710
- } else if (current.eq(DIV)) {
3711
- stack.push(current);
3712
- pos++;
3768
+ const current_tree = nodes[pos];
3769
+ if (current_tree.eq(DIV)) {
3770
+ stack.push(current_tree);
3713
3771
  } else {
3714
- let current_tree;
3715
- if (current.eq(opening_bracket)) {
3716
- const pos_closing = find_closing_parenthesis(nodes, pos);
3717
- current_tree = process_operators(nodes.slice(pos + 1, pos_closing), true);
3718
- pos = pos_closing + 1;
3719
- } else {
3720
- current_tree = current;
3721
- pos++;
3722
- }
3723
3772
  if (stack.length > 0 && stack[stack.length - 1].eq(DIV)) {
3724
3773
  let denominator = current_tree;
3725
3774
  if (args.length === 0) {
@@ -3738,13 +3787,9 @@ function process_operators(nodes, parenthesis = false) {
3738
3787
  args.push(current_tree);
3739
3788
  }
3740
3789
  }
3790
+ pos++;
3741
3791
  }
3742
- const body = args.length === 1 ? args[0] : new TypstGroup(args);
3743
- if (parenthesis) {
3744
- return new TypstLeftright(null, { body, left: LEFT_PARENTHESES, right: RIGHT_PARENTHESES });
3745
- } else {
3746
- return body;
3747
- }
3792
+ return args.length === 1 ? args[0] : new TypstGroup(args);
3748
3793
  }
3749
3794
  function parse_named_params(groups) {
3750
3795
  const COLON = new TypstToken(2 /* ELEMENT */, ":").toNode();
@@ -3772,7 +3817,6 @@ var LEFT_CURLY_BRACKET2 = new TypstToken(2 /* ELEMENT */, "{");
3772
3817
  var RIGHT_CURLY_BRACKET2 = new TypstToken(2 /* ELEMENT */, "}");
3773
3818
  var COMMA = new TypstToken(2 /* ELEMENT */, ",");
3774
3819
  var SEMICOLON = new TypstToken(2 /* ELEMENT */, ";");
3775
- var SINGLE_SPACE = new TypstToken(6 /* SPACE */, " ");
3776
3820
  var CONTROL_AND = new TypstToken(7 /* CONTROL */, "&");
3777
3821
  var TypstParser = class {
3778
3822
  space_sensitive;
@@ -3785,33 +3829,8 @@ var TypstParser = class {
3785
3829
  const [tree, _] = this.parseGroup(tokens, 0, tokens.length);
3786
3830
  return tree;
3787
3831
  }
3788
- parseGroup(tokens, start, end, parentheses = false) {
3789
- const results = [];
3790
- let pos = start;
3791
- while (pos < end) {
3792
- const [res, newPos] = this.parseNextExpr(tokens, pos);
3793
- pos = newPos;
3794
- if (res.head.type === 6 /* SPACE */ || res.head.type === 8 /* NEWLINE */) {
3795
- if (!this.space_sensitive && res.head.value.replace(/ /g, "").length === 0) {
3796
- continue;
3797
- }
3798
- if (!this.newline_sensitive && res.head.value === "\n") {
3799
- continue;
3800
- }
3801
- }
3802
- results.push(res);
3803
- }
3804
- let node;
3805
- if (parentheses) {
3806
- node = process_operators(results, true);
3807
- } else {
3808
- if (results.length === 1) {
3809
- node = results[0];
3810
- } else {
3811
- node = process_operators(results);
3812
- }
3813
- }
3814
- return [node, end + 1];
3832
+ parseGroup(tokens, start, end) {
3833
+ return this.parseUntil(tokens.slice(start, end), 0, null);
3815
3834
  }
3816
3835
  parseNextExpr(tokens, start) {
3817
3836
  let [base, pos] = this.parseNextExprWithoutSupSub(tokens, start);
@@ -3840,12 +3859,47 @@ var TypstParser = class {
3840
3859
  return [base, pos];
3841
3860
  }
3842
3861
  }
3862
+ // return pos: (position of stopToken) + 1
3863
+ // pos will be -1 if stopToken is not found
3864
+ parseUntil(tokens, start, stopToken, env = {}) {
3865
+ if (env.spaceSensitive === void 0) {
3866
+ env.spaceSensitive = this.space_sensitive;
3867
+ }
3868
+ if (env.newlineSensitive === void 0) {
3869
+ env.newlineSensitive = this.newline_sensitive;
3870
+ }
3871
+ const results = [];
3872
+ let pos = start;
3873
+ while (pos < tokens.length) {
3874
+ if (stopToken !== null && tokens[pos].eq(stopToken)) {
3875
+ break;
3876
+ }
3877
+ const [res, newPos] = this.parseNextExpr(tokens, pos);
3878
+ pos = newPos;
3879
+ if (res.head.type === 6 /* SPACE */ || res.head.type === 8 /* NEWLINE */) {
3880
+ if (!env.spaceSensitive && res.head.value.replace(/ /g, "").length === 0) {
3881
+ continue;
3882
+ }
3883
+ if (!env.newlineSensitive && res.head.value === "\n") {
3884
+ continue;
3885
+ }
3886
+ }
3887
+ results.push(res);
3888
+ }
3889
+ if (pos >= tokens.length && stopToken !== null) {
3890
+ return [TypstToken.NONE.toNode(), -1];
3891
+ }
3892
+ const node = process_operators(results);
3893
+ return [node, pos + 1];
3894
+ }
3843
3895
  parseSupOrSub(tokens, start) {
3844
3896
  let node;
3845
3897
  let end;
3846
3898
  if (tokens[start].eq(LEFT_PARENTHESES)) {
3847
- const pos_closing = find_closing_match(tokens, start);
3848
- [node, end] = this.parseGroup(tokens, start + 1, pos_closing);
3899
+ [node, end] = this.parseUntil(tokens, start + 1, RIGHT_PARENTHESES);
3900
+ if (end === -1) {
3901
+ throw new Error("Unmatched '('");
3902
+ }
3849
3903
  } else {
3850
3904
  [node, end] = this.parseNextExprWithoutSupSub(tokens, start);
3851
3905
  }
@@ -3860,8 +3914,12 @@ var TypstParser = class {
3860
3914
  const firstToken = tokens[start];
3861
3915
  const node = firstToken.toNode();
3862
3916
  if (firstToken.eq(LEFT_PARENTHESES)) {
3863
- const pos_closing = find_closing_match(tokens, start);
3864
- return this.parseGroup(tokens, start + 1, pos_closing, true);
3917
+ const [body, end] = this.parseUntil(tokens, start + 1, RIGHT_PARENTHESES);
3918
+ if (end === -1) {
3919
+ throw new Error("Unmatched '('");
3920
+ }
3921
+ const res = new TypstLeftright(null, { body, left: LEFT_PARENTHESES, right: RIGHT_PARENTHESES });
3922
+ return [res, end];
3865
3923
  }
3866
3924
  if (firstToken.type === 2 /* ELEMENT */ && !isalpha(firstToken.value[0])) {
3867
3925
  return [node, start + 1];
@@ -3909,70 +3967,41 @@ var TypstParser = class {
3909
3967
  }
3910
3968
  // start: the position of the left parentheses
3911
3969
  parseLrArguments(tokens, start) {
3912
- const lr_token = tokens[start];
3970
+ const lr_token = new TypstToken(1 /* SYMBOL */, "lr");
3913
3971
  const end = find_closing_match(tokens, start);
3914
- if (tokens[start + 1].isOneOf(TypstToken.LEFT_DELIMITERS)) {
3915
- const inner_start = start + 1;
3916
- const inner_end = find_closing_delim(tokens, inner_start);
3917
- const [inner_args, _] = this.parseGroup(tokens, inner_start + 1, inner_end);
3918
- return [
3919
- new TypstLeftright(lr_token, { body: inner_args, left: tokens[inner_start], right: tokens[inner_end] }),
3920
- end + 1
3921
- ];
3922
- } else {
3923
- const [inner_args, _] = this.parseGroup(tokens, start + 1, end - 1);
3924
- return [
3925
- new TypstLeftright(lr_token, { body: inner_args, left: null, right: null }),
3926
- end + 1
3927
- ];
3972
+ let left = null;
3973
+ let right = null;
3974
+ let inner_start = start + 1;
3975
+ let inner_end = end;
3976
+ if (inner_end > inner_start && tokens[inner_start].isOneOf(TypstToken.LEFT_DELIMITERS)) {
3977
+ left = tokens[inner_start];
3978
+ inner_start += 1;
3979
+ }
3980
+ if (inner_end - 1 > inner_start && tokens[inner_end - 1].isOneOf(TypstToken.RIGHT_DELIMITERS)) {
3981
+ right = tokens[inner_end - 1];
3982
+ inner_end -= 1;
3928
3983
  }
3984
+ const [inner_args, _] = this.parseGroup(tokens, inner_start, inner_end);
3985
+ return [
3986
+ new TypstLeftright(lr_token, { body: inner_args, left, right }),
3987
+ end + 1
3988
+ ];
3929
3989
  }
3930
3990
  // start: the position of the left parentheses
3931
3991
  parseMatrix(tokens, start, rowSepToken, cellSepToken) {
3932
3992
  const end = find_closing_match(tokens, start);
3933
- tokens = tokens.slice(0, end);
3934
3993
  const matrix = [];
3935
3994
  let named_params = {};
3936
3995
  let pos = start + 1;
3937
3996
  while (pos < end) {
3938
3997
  while (pos < end) {
3939
- let extract_named_params2 = function(arr) {
3940
- const COLON = new TypstToken(2 /* ELEMENT */, ":").toNode();
3941
- const np2 = {};
3942
- const to_delete = [];
3943
- for (let i = 0; i < arr.length; i++) {
3944
- if (arr[i].type !== "group") {
3945
- continue;
3946
- }
3947
- const g = arr[i];
3948
- const pos_colon = array_find(g.items, COLON);
3949
- if (pos_colon === -1 || pos_colon === 0) {
3950
- continue;
3951
- }
3952
- to_delete.push(i);
3953
- const param_name = g.items[pos_colon - 1];
3954
- if (param_name.eq(new TypstToken(1 /* SYMBOL */, "delim").toNode())) {
3955
- if (g.items.length !== 3) {
3956
- throw new TypstParserError("Invalid number of arguments for delim");
3957
- }
3958
- np2["delim"] = g.items[pos_colon + 1];
3959
- } else {
3960
- throw new TypstParserError("Not implemented for other named parameters");
3961
- }
3962
- }
3963
- for (let i = to_delete.length - 1; i >= 0; i--) {
3964
- arr.splice(to_delete[i], 1);
3965
- }
3966
- return [arr, np2];
3967
- };
3968
- var extract_named_params = extract_named_params2;
3969
3998
  let next_stop = array_find(tokens, rowSepToken, pos);
3970
- if (next_stop === -1) {
3999
+ if (next_stop === -1 || next_stop > end) {
3971
4000
  next_stop = end;
3972
4001
  }
3973
4002
  let row = this.parseArgumentsWithSeparator(tokens, pos, next_stop, cellSepToken);
3974
4003
  let np = {};
3975
- [row, np] = extract_named_params2(row);
4004
+ [row, np] = extract_named_params(row);
3976
4005
  matrix.push(row);
3977
4006
  Object.assign(named_params, np);
3978
4007
  pos = next_stop + 1;
@@ -3985,26 +4014,15 @@ var TypstParser = class {
3985
4014
  const args = [];
3986
4015
  let pos = start;
3987
4016
  while (pos < end) {
3988
- let nodes = [];
3989
- while (pos < end) {
3990
- if (tokens[pos].eq(sepToken)) {
3991
- pos += 1;
3992
- break;
3993
- } else if (tokens[pos].eq(SINGLE_SPACE)) {
3994
- pos += 1;
3995
- continue;
3996
- }
3997
- const [argItem, newPos] = this.parseNextExpr(tokens, pos);
3998
- pos = newPos;
3999
- nodes.push(argItem);
4000
- }
4001
4017
  let arg;
4002
- if (nodes.length === 1) {
4003
- arg = nodes[0];
4004
- } else {
4005
- arg = process_operators(nodes);
4018
+ let newPos;
4019
+ const env = { spaceSensitive: false, newlineSensitive: true };
4020
+ [arg, newPos] = this.parseUntil(tokens.slice(0, end), pos, sepToken, env);
4021
+ if (newPos == -1) {
4022
+ [arg, newPos] = this.parseUntil(tokens.slice(0, end), pos, null, env);
4006
4023
  }
4007
4024
  args.push(arg);
4025
+ pos = newPos;
4008
4026
  }
4009
4027
  return args;
4010
4028
  }