tex2typst 0.5.2 → 0.5.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 +128 -38
- package/dist/tex2typst.min.js +11 -12
- package/package.json +1 -1
- package/src/typst-types.ts +153 -9
- package/src/typst-writer.ts +6 -47
package/dist/index.js
CHANGED
|
@@ -1225,6 +1225,8 @@ var TypstToken = class _TypstToken {
|
|
|
1225
1225
|
static EMPTY = new _TypstToken(2 /* ELEMENT */, "");
|
|
1226
1226
|
static LEFT_BRACE = new _TypstToken(2 /* ELEMENT */, "{");
|
|
1227
1227
|
static RIGHT_BRACE = new _TypstToken(2 /* ELEMENT */, "}");
|
|
1228
|
+
static PLUS = new _TypstToken(2 /* ELEMENT */, "+");
|
|
1229
|
+
static MINUS = new _TypstToken(2 /* ELEMENT */, "-");
|
|
1228
1230
|
static LEFT_DELIMITERS = [
|
|
1229
1231
|
new _TypstToken(2 /* ELEMENT */, "("),
|
|
1230
1232
|
new _TypstToken(2 /* ELEMENT */, "["),
|
|
@@ -1280,6 +1282,39 @@ var TypstTerminal = class extends TypstNode {
|
|
|
1280
1282
|
isOverHigh() {
|
|
1281
1283
|
return false;
|
|
1282
1284
|
}
|
|
1285
|
+
isLeftSpaceful() {
|
|
1286
|
+
switch (this.head.type) {
|
|
1287
|
+
case 6 /* SPACE */:
|
|
1288
|
+
case 8 /* NEWLINE */:
|
|
1289
|
+
return false;
|
|
1290
|
+
case 4 /* TEXT */:
|
|
1291
|
+
return true;
|
|
1292
|
+
case 1 /* SYMBOL */:
|
|
1293
|
+
case 2 /* ELEMENT */: {
|
|
1294
|
+
if (["(", "!", "}", "]"].includes(this.head.value)) {
|
|
1295
|
+
return false;
|
|
1296
|
+
}
|
|
1297
|
+
return true;
|
|
1298
|
+
}
|
|
1299
|
+
default:
|
|
1300
|
+
return true;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
isRightSpaceful() {
|
|
1304
|
+
switch (this.head.type) {
|
|
1305
|
+
case 6 /* SPACE */:
|
|
1306
|
+
case 8 /* NEWLINE */:
|
|
1307
|
+
return false;
|
|
1308
|
+
case 4 /* TEXT */:
|
|
1309
|
+
return true;
|
|
1310
|
+
case 1 /* SYMBOL */:
|
|
1311
|
+
case 2 /* ELEMENT */: {
|
|
1312
|
+
return ["+", "=", ",", "\\/", "dot", "dot.op", "arrow", "arrow.r"].includes(this.head.value);
|
|
1313
|
+
}
|
|
1314
|
+
default:
|
|
1315
|
+
return false;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1283
1318
|
toString() {
|
|
1284
1319
|
return this.head.toString();
|
|
1285
1320
|
}
|
|
@@ -1326,13 +1361,48 @@ var TypstGroup = class extends TypstNode {
|
|
|
1326
1361
|
isOverHigh() {
|
|
1327
1362
|
return this.items.some((n) => n.isOverHigh());
|
|
1328
1363
|
}
|
|
1364
|
+
isLeftSpaceful() {
|
|
1365
|
+
if (this.items.length === 0) {
|
|
1366
|
+
return false;
|
|
1367
|
+
}
|
|
1368
|
+
return this.items[0].isLeftSpaceful();
|
|
1369
|
+
}
|
|
1370
|
+
isRightSpaceful() {
|
|
1371
|
+
if (this.items.length === 0) {
|
|
1372
|
+
return false;
|
|
1373
|
+
}
|
|
1374
|
+
return this.items.at(-1).isRightSpaceful();
|
|
1375
|
+
}
|
|
1329
1376
|
serialize(env, options) {
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1377
|
+
if (this.items.length === 0) {
|
|
1378
|
+
return [];
|
|
1379
|
+
}
|
|
1380
|
+
const queue = [];
|
|
1381
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
1382
|
+
const n = this.items[i];
|
|
1383
|
+
const tokens = n.serialize(env, options);
|
|
1384
|
+
if (n.isLeftSpaceful() && i > 0) {
|
|
1385
|
+
if (queue.length > 0) {
|
|
1386
|
+
const top = queue.at(-1);
|
|
1387
|
+
let no_need_space = false;
|
|
1388
|
+
no_need_space ||= top.eq(SOFT_SPACE);
|
|
1389
|
+
no_need_space ||= ["{", "["].includes(top.value);
|
|
1390
|
+
if (!no_need_space) {
|
|
1391
|
+
queue.push(SOFT_SPACE);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
queue.push(...tokens);
|
|
1396
|
+
if (n.isRightSpaceful() && i < this.items.length - 1) {
|
|
1397
|
+
if (!queue.at(-1)?.eq(SOFT_SPACE)) {
|
|
1398
|
+
queue.push(SOFT_SPACE);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1333
1401
|
}
|
|
1334
|
-
if (queue.length > 0 && queue[
|
|
1335
|
-
queue.
|
|
1402
|
+
if (queue.length > 0 && (queue[0].eq(TypstToken.MINUS) || queue[0].eq(TypstToken.PLUS))) {
|
|
1403
|
+
while (queue.length > 1 && queue[1].eq(SOFT_SPACE)) {
|
|
1404
|
+
queue.splice(1, 1);
|
|
1405
|
+
}
|
|
1336
1406
|
}
|
|
1337
1407
|
return queue;
|
|
1338
1408
|
}
|
|
@@ -1350,6 +1420,12 @@ var TypstSupsub = class extends TypstNode {
|
|
|
1350
1420
|
isOverHigh() {
|
|
1351
1421
|
return this.base.isOverHigh();
|
|
1352
1422
|
}
|
|
1423
|
+
isLeftSpaceful() {
|
|
1424
|
+
return true;
|
|
1425
|
+
}
|
|
1426
|
+
isRightSpaceful() {
|
|
1427
|
+
return true;
|
|
1428
|
+
}
|
|
1353
1429
|
serialize(env, options) {
|
|
1354
1430
|
const queue = [];
|
|
1355
1431
|
let { base, sup, sub } = this;
|
|
@@ -1366,7 +1442,6 @@ var TypstSupsub = class extends TypstNode {
|
|
|
1366
1442
|
queue.push(new TypstToken(2 /* ELEMENT */, "^"));
|
|
1367
1443
|
queue.push(...sup.serialize(env, options));
|
|
1368
1444
|
}
|
|
1369
|
-
queue.push(SOFT_SPACE);
|
|
1370
1445
|
return queue;
|
|
1371
1446
|
}
|
|
1372
1447
|
};
|
|
@@ -1382,6 +1457,12 @@ var TypstFuncCall = class extends TypstNode {
|
|
|
1382
1457
|
}
|
|
1383
1458
|
return this.args.some((n) => n.isOverHigh());
|
|
1384
1459
|
}
|
|
1460
|
+
isLeftSpaceful() {
|
|
1461
|
+
return true;
|
|
1462
|
+
}
|
|
1463
|
+
isRightSpaceful() {
|
|
1464
|
+
return !["op", "bold", "dot"].includes(this.head.value);
|
|
1465
|
+
}
|
|
1385
1466
|
serialize(env, options) {
|
|
1386
1467
|
const queue = [];
|
|
1387
1468
|
const func_symbol = this.head;
|
|
@@ -1392,6 +1473,7 @@ var TypstFuncCall = class extends TypstNode {
|
|
|
1392
1473
|
queue.push(...this.args[i].serialize(env, options));
|
|
1393
1474
|
if (i < this.args.length - 1) {
|
|
1394
1475
|
queue.push(new TypstToken(2 /* ELEMENT */, ","));
|
|
1476
|
+
queue.push(SOFT_SPACE);
|
|
1395
1477
|
}
|
|
1396
1478
|
}
|
|
1397
1479
|
if (this.options) {
|
|
@@ -1413,14 +1495,18 @@ var TypstFraction = class extends TypstNode {
|
|
|
1413
1495
|
isOverHigh() {
|
|
1414
1496
|
return true;
|
|
1415
1497
|
}
|
|
1498
|
+
isLeftSpaceful() {
|
|
1499
|
+
return true;
|
|
1500
|
+
}
|
|
1501
|
+
isRightSpaceful() {
|
|
1502
|
+
return true;
|
|
1503
|
+
}
|
|
1416
1504
|
serialize(env, options) {
|
|
1417
1505
|
const queue = [];
|
|
1418
1506
|
const [numerator, denominator] = this.args;
|
|
1419
|
-
queue.push(SOFT_SPACE);
|
|
1420
1507
|
queue.push(...numerator.serialize(env, options));
|
|
1421
1508
|
queue.push(new TypstToken(2 /* ELEMENT */, "/"));
|
|
1422
1509
|
queue.push(...denominator.serialize(env, options));
|
|
1423
|
-
queue.push(SOFT_SPACE);
|
|
1424
1510
|
return queue;
|
|
1425
1511
|
}
|
|
1426
1512
|
};
|
|
@@ -1440,6 +1526,12 @@ var TypstLeftright = class extends TypstNode {
|
|
|
1440
1526
|
isOverHigh() {
|
|
1441
1527
|
return this.body.isOverHigh();
|
|
1442
1528
|
}
|
|
1529
|
+
isLeftSpaceful() {
|
|
1530
|
+
return true;
|
|
1531
|
+
}
|
|
1532
|
+
isRightSpaceful() {
|
|
1533
|
+
return true;
|
|
1534
|
+
}
|
|
1443
1535
|
serialize(env, options) {
|
|
1444
1536
|
const queue = [];
|
|
1445
1537
|
const LR = new TypstToken(1 /* SYMBOL */, "lr");
|
|
@@ -1450,9 +1542,15 @@ var TypstLeftright = class extends TypstNode {
|
|
|
1450
1542
|
}
|
|
1451
1543
|
if (left) {
|
|
1452
1544
|
queue.push(left);
|
|
1545
|
+
if (isalpha(left.value[0])) {
|
|
1546
|
+
queue.push(SOFT_SPACE);
|
|
1547
|
+
}
|
|
1453
1548
|
}
|
|
1454
1549
|
queue.push(...this.body.serialize(env, options));
|
|
1455
1550
|
if (right) {
|
|
1551
|
+
if (isalpha(right.value[0])) {
|
|
1552
|
+
queue.push(SOFT_SPACE);
|
|
1553
|
+
}
|
|
1456
1554
|
queue.push(right);
|
|
1457
1555
|
}
|
|
1458
1556
|
if (this.head.eq(LR)) {
|
|
@@ -1471,6 +1569,12 @@ var TypstMatrixLike = class _TypstMatrixLike extends TypstNode {
|
|
|
1471
1569
|
isOverHigh() {
|
|
1472
1570
|
return true;
|
|
1473
1571
|
}
|
|
1572
|
+
isLeftSpaceful() {
|
|
1573
|
+
return true;
|
|
1574
|
+
}
|
|
1575
|
+
isRightSpaceful() {
|
|
1576
|
+
return false;
|
|
1577
|
+
}
|
|
1474
1578
|
serialize(env, options) {
|
|
1475
1579
|
const queue = [];
|
|
1476
1580
|
let cell_sep;
|
|
@@ -1499,10 +1603,16 @@ var TypstMatrixLike = class _TypstMatrixLike extends TypstNode {
|
|
|
1499
1603
|
row.forEach((cell, j) => {
|
|
1500
1604
|
queue.push(...cell.serialize(env, options));
|
|
1501
1605
|
if (j < row.length - 1) {
|
|
1606
|
+
queue.push(SOFT_SPACE);
|
|
1502
1607
|
queue.push(cell_sep);
|
|
1608
|
+
queue.push(SOFT_SPACE);
|
|
1503
1609
|
} else {
|
|
1504
1610
|
if (i < this.matrix.length - 1) {
|
|
1611
|
+
if (row_sep.value === "\\") {
|
|
1612
|
+
queue.push(SOFT_SPACE);
|
|
1613
|
+
}
|
|
1505
1614
|
queue.push(row_sep);
|
|
1615
|
+
queue.push(SOFT_SPACE);
|
|
1506
1616
|
}
|
|
1507
1617
|
}
|
|
1508
1618
|
});
|
|
@@ -1532,6 +1642,12 @@ var TypstMarkupFunc = class extends TypstNode {
|
|
|
1532
1642
|
isOverHigh() {
|
|
1533
1643
|
return this.fragments.some((n) => n.isOverHigh());
|
|
1534
1644
|
}
|
|
1645
|
+
isLeftSpaceful() {
|
|
1646
|
+
return true;
|
|
1647
|
+
}
|
|
1648
|
+
isRightSpaceful() {
|
|
1649
|
+
return true;
|
|
1650
|
+
}
|
|
1535
1651
|
serialize(env, options) {
|
|
1536
1652
|
const queue = [];
|
|
1537
1653
|
queue.push(this.head);
|
|
@@ -1572,41 +1688,15 @@ var TypstWriter = class {
|
|
|
1572
1688
|
constructor(options) {
|
|
1573
1689
|
this.options = options;
|
|
1574
1690
|
}
|
|
1575
|
-
writeBuffer(previousToken, token) {
|
|
1576
|
-
const str = token.toString();
|
|
1577
|
-
if (str === "") {
|
|
1578
|
-
return;
|
|
1579
|
-
}
|
|
1580
|
-
let no_need_space = false;
|
|
1581
|
-
no_need_space ||= /[\(\[\|]$/.test(this.buffer) && /^\w/.test(str);
|
|
1582
|
-
no_need_space ||= /^[})\]\|]$/.test(str);
|
|
1583
|
-
no_need_space ||= /[^=]$/.test(this.buffer) && str === "(";
|
|
1584
|
-
no_need_space ||= /^[_^,;!]$/.test(str);
|
|
1585
|
-
no_need_space ||= str === "'";
|
|
1586
|
-
no_need_space ||= /[\(\[{]\s*(-|\+)$/.test(this.buffer) || this.buffer === "-" || this.buffer === "+";
|
|
1587
|
-
no_need_space ||= str.startsWith("\n");
|
|
1588
|
-
no_need_space ||= this.buffer === "";
|
|
1589
|
-
no_need_space ||= /\s$/.test(this.buffer) || /^\s/.test(str);
|
|
1590
|
-
no_need_space ||= this.buffer.endsWith("&") && str === "=";
|
|
1591
|
-
no_need_space ||= this.buffer.endsWith("/") || str === "/";
|
|
1592
|
-
no_need_space ||= token.type === 3 /* LITERAL */;
|
|
1593
|
-
no_need_space ||= /[\s_^{\(]$/.test(this.buffer);
|
|
1594
|
-
if (previousToken !== null) {
|
|
1595
|
-
no_need_space ||= previousToken.type === 3 /* LITERAL */;
|
|
1596
|
-
}
|
|
1597
|
-
if (!no_need_space) {
|
|
1598
|
-
this.buffer += " ";
|
|
1599
|
-
}
|
|
1600
|
-
this.buffer += str;
|
|
1601
|
-
}
|
|
1602
1691
|
// Serialize a tree of TypstNode into a list of TypstToken
|
|
1603
1692
|
serialize(abstractNode) {
|
|
1604
1693
|
const env = { insideFunctionDepth: 0 };
|
|
1605
1694
|
this.queue.push(...abstractNode.serialize(env, this.options));
|
|
1606
1695
|
}
|
|
1607
1696
|
flushQueue() {
|
|
1697
|
+
const queue1 = this.queue.filter((token) => token.value !== "");
|
|
1608
1698
|
let qu = [];
|
|
1609
|
-
for (const token of
|
|
1699
|
+
for (const token of queue1) {
|
|
1610
1700
|
if (token.eq(SOFT_SPACE2) && qu.length > 0 && qu[qu.length - 1].eq(SOFT_SPACE2)) {
|
|
1611
1701
|
continue;
|
|
1612
1702
|
}
|
|
@@ -1625,8 +1715,7 @@ var TypstWriter = class {
|
|
|
1625
1715
|
qu = qu.filter((token) => !token.eq(dummy_token));
|
|
1626
1716
|
for (let i = 0; i < qu.length; i++) {
|
|
1627
1717
|
let token = qu[i];
|
|
1628
|
-
|
|
1629
|
-
this.writeBuffer(previous_token, token);
|
|
1718
|
+
this.buffer += token.toString();
|
|
1630
1719
|
}
|
|
1631
1720
|
this.queue = [];
|
|
1632
1721
|
}
|
|
@@ -1653,6 +1742,7 @@ var TypstWriter = class {
|
|
|
1653
1742
|
this.buffer = pass(this.buffer);
|
|
1654
1743
|
}
|
|
1655
1744
|
}
|
|
1745
|
+
this.buffer = this.buffer.replace(/& =/g, "&=");
|
|
1656
1746
|
return this.buffer;
|
|
1657
1747
|
}
|
|
1658
1748
|
};
|
package/dist/tex2typst.min.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
"use strict";(()=>{function
|
|
2
|
-
`));for(let t=0;t<r.length;t++){let
|
|
3
|
-
`)),e.push(new l(2,"\\end")),e.push(new l(1,"{")),e=e.concat(this.head),e.push(new l(1,"}")),e}};function
|
|
4
|
-
`)-1):this._col+=u,
|
|
5
|
-
`)],[String.raw`\s+`,
|
|
6
|
-
`))&&
|
|
7
|
-
`)t.push(new i(1,
|
|
8
|
-
`),we=new i(7," ");var te=class{buffer="";queue=[];options;constructor(e){this.options=e}writeBuffer(e,r){let t=r.toString();if(t==="")return;let s=!1;s||=/[\(\[\|]$/.test(this.buffer)&&/^\w/.test(t),s||=/^[})\]\|]$/.test(t),s||=/[^=]$/.test(this.buffer)&&t==="(",s||=/^[_^,;!]$/.test(t),s||=t==="'",s||=/[\(\[{]\s*(-|\+)$/.test(this.buffer)||this.buffer==="-"||this.buffer==="+",s||=t.startsWith(`
|
|
9
|
-
`),s||=this.buffer==="",s||=/\s$/.test(this.buffer)||/^\s/.test(t),s||=this.buffer.endsWith("&")&&t==="=",s||=this.buffer.endsWith("/")||t==="/",s||=r.type===3,s||=/[\s_^{\(]$/.test(this.buffer),e!==null&&(s||=e.type===3),s||(this.buffer+=" "),this.buffer+=t}serialize(e){let r={insideFunctionDepth:0};this.queue.push(...e.serialize(r,this.options))}flushQueue(){let e=[];for(let t of this.queue)t.eq(we)&&e.length>0&&e[e.length-1].eq(we)||e.push(t);let r=new i(1,"");for(let t=0;t<e.length;t++)e[t].eq(we)&&(t===0||t===e.length-1||e[t-1].type===6||e[t-1].isOneOf([st,De])||e[t+1].isOneOf([ot,at,De]))&&(e[t]=r);e=e.filter(t=>!t.eq(r));for(let t=0;t<e.length;t++){let s=e[t],o=t===0?null:e[t-1];this.writeBuffer(o,s)}this.queue=[]}finalize(){this.flushQueue();let e=function(s){let o=s.replace(/floor\.l\s*(.*?)\s*floor\.r/g,"floor($1)");return o=o.replace(/floor\(\)/g,'floor("")'),o},r=function(s){let o=s.replace(/ceil\.l\s*(.*?)\s*ceil\.r/g,"ceil($1)");return o=o.replace(/ceil\(\)/g,'ceil("")'),o},t=function(s){let o=s.replace(/floor\.l\s*(.*?)\s*ceil\.r/g,"round($1)");return o=o.replace(/round\(\)/g,'round("")'),o};if(this.options.optimize){let s=[e,r,t];for(let o of s)this.buffer=o(this.buffer)}return this.buffer}};var E=new Map([["displaystyle","display"],["textstyle","inline"],["hspace","#h"],["|","bar.v.double"],[",","thin"],[":","med"],[" ","med"],[";","thick"],[">","med"],["~","space.nobreak"],["blacktriangleleft","triangle.filled.l"],["blacktriangleright","triangle.filled.r"],["clubsuit","suit.club.filled"],["hookleftarrow","arrow.l.hook"],["hookrightarrow","arrow.r.hook"],["leftrightarrow","arrow.l.r"],["lgblksquare","square.filled.big"],["lgwhtsquare","square.stroked.big"],["nearrow","arrow.tr"],["nwarrow","arrow.tl"],["searrow","arrow.br"],["swarrow","arrow.bl"],["spadesuit","suit.spade.filled"],["updownarrow","arrow.t.b"],["ln","ln"],["log","log"],["cos","cos"],["sin","sin"],["tan","tan"],["cot","cot"],["sec","sec"],["csc","csc"],["mod","mod"],["omicron","omicron"],["Xi","Xi"],["Upsilon","Upsilon"],["lim","lim"],["binom","binom"],["tilde","tilde"],["hat","hat"],["sqrt","sqrt"],["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"],["operatorname*","op"],["boldsymbol","bold"],["mathbb","bb"],["mathbf","bold"],["mathcal","cal"],["mathscr","scr"],["mathit","italic"],["mathfrak","frak"],["mathrm","upright"],["mathsf","sans"],["mathtt","mono"],["rm","upright"],["pmb","bold"],["leadsto","arrow.r.squiggly"],["P","pilcrow"],["S","section"],["aleph","alef"],["infin","infinity"],["Delta","Delta"],["Gamma","Gamma"],["Lambda","Lambda"],["Omega","Omega"],["Phi","Phi"],["Pi","Pi"],["Psi","Psi"],["Sigma","Sigma"],["Theta","Theta"],["alpha","alpha"],["beta","beta"],["bigcirc","circle.big"],["bullet","bullet"],["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"],["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"],["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","chevron.l"],["lbrace","brace.l"],["lbrack","bracket.l"],["ldots","dots.h"],["le","lt.eq"],["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"],["odot","dot.circle"],["oint","integral.cont"],["oiint","integral.surf"],["oiiint","integral.vol"],["omega","omega"],["ominus","minus.circle"],["otimes","times.circle"],["parallel","parallel"],["partial","partial"],["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","chevron.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"],["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"],["tau","tau"],["theta","theta"],["times","times"],["to","arrow.r"],["top","top"],["triangle","triangle.t"],["twoheadrightarrow","arrow.r.twohead"],["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"],["intop","limits(integral)"],["LaTeX","#LaTeX"],["TeX","#TeX"]]),it=new Map([["acwopencirclearrow","arrow.ccw"],["adots","dots.up"],["angdnr","angle.acute"],["angle","angle"],["angles","angle.s"],["approx","approx"],["approxeq","approx.eq"],["approxident","tilde.triple"],["assert","tack.r.short"],["ast","ast.op"],["astrosun","sun"],["asymp","asymp"],["awint","integral.ccw"],["backcong","tilde.rev.equiv"],["backdprime","prime.double.rev"],["backprime","prime.rev"],["backsim","tilde.rev"],["backsimeq","tilde.eq.rev"],["backslash","backslash"],["backtrprime","prime.triple.rev"],["bardownharpoonleft","harpoon.bl.bar"],["bardownharpoonright","harpoon.br.bar"],["barleftarrow","arrow.l.stop"],["barleftarrowrightarrowbar","arrows.lr.stop"],["barleftharpoondown","harpoon.lb.stop"],["barleftharpoonup","harpoon.lt.stop"],["barrightharpoondown","harpoon.rb.bar"],["barrightharpoonup","harpoon.rt.bar"],["baruparrow","arrow.t.stop"],["barupharpoonleft","harpoon.tl.stop"],["barupharpoonright","harpoon.tr.stop"],["barV","tack.b.double"],["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"],["because","because"],["bigblacktriangledown","triangle.filled.b"],["bigblacktriangleup","triangle.filled.t"],["bigbot","tack.t.big"],["bigcap","inter.big"],["bigcup","union.big"],["bigcupdot","union.dot.big"],["biginterleave","interleave.big"],["bigodot","dot.o.big"],["bigoplus","plus.o.big"],["bigotimes","times.o.big"],["bigsqcap","inter.sq.big"],["bigsqcup","union.sq.big"],["bigstar","star.filled"],["bigtimes","times.big"],["bigtop","tack.b.big"],["bigtriangledown","triangle.stroked.b"],["bigtriangleup","triangle.stroked.t"],["biguplus","union.plus.big"],["bigvee","or.big"],["bigwedge","and.big"],["bigwhitestar","star.stroked"],["blackhourglass","hourglass.filled"],["blacktriangle","triangle.filled.small.t"],["blacktriangledown","triangle.filled.small.b"],["blkhorzoval","ellipse.filled.h"],["blkvertoval","ellipse.filled.v"],["bot","bot"],["boxast","ast.square"],["boxdot","dot.square"],["boxminus","minus.square"],["boxplus","plus.square"],["boxtimes","times.square"],["cap","inter"],["Cap","inter.double"],["capdot","inter.dot"],["capwedge","inter.and"],["caretinsert","caret"],["cdot","dot.op"],["cdotp","dot.c"],["checkmark","checkmark"],["circledast","ast.op.o"],["circledbullet","bullet.o"],["circledcirc","compose.o"],["circleddash","dash.o"],["circledequal","cc.nd"],["circledparallel","parallel.o"],["circledvert","bar.v.o"],["circledwhitebullet","bullet.stroked.o"],["Colon","colon.double"],["coloneq","colon.eq"],["Coloneq","colon.double.eq"],["complement","complement"],["cong","tilde.equiv"],["coprod","product.co"],["cup","union"],["Cup","union.double"],["cupdot","union.dot"],["cupleftarrow","union.arrow"],["cupvee","union.or"],["curlyeqprec","eq.prec"],["curlyeqsucc","eq.succ"],["curlyvee","or.curly"],["curlywedge","and.curly"],["curvearrowleft","arrow.ccw.half"],["curvearrowright","arrow.cw.half"],["cwopencirclearrow","arrow.cw"],["dagger","dagger"],["dashcolon","dash.colon"],["dashv","tack.l"],["Dashv","tack.l.double"],["dashVdash","tack.l.r"],["ddagger","dagger.double"],["ddddot","dot.quad"],["dddot","dot.triple"],["ddots","dots.down"],["DDownarrow","arrow.b.quad"],["Ddownarrow","arrow.b.triple"],["diameter","diameter"],["diamondcdot","diamond.stroked.dot"],["diamondsuit","suit.diamond.stroked"],["dicei","die.one"],["diceii","die.two"],["diceiii","die.three"],["diceiv","die.four"],["dicev","die.five"],["dicevi","die.six"],["div","div"],["divideontimes","times.div"],["Doteq","eq.dots"],["dotminus","minus.dot"],["dotplus","plus.dot"],["dotsim","tilde.dot"],["dottedcircle","circle.dotted"],["dottedsquare","square.stroked.dotted"],["doubleplus","plus.double"],["downarrow","arrow.b"],["Downarrow","arrow.b.double"],["downarrowbar","arrow.b.stop"],["downarrowbarred","arrow.b.struck"],["downdasharrow","arrow.b.dashed"],["downdownarrows","arrows.bb"],["downharpoonleft","harpoon.bl"],["downharpoonleftbar","harpoon.bl.stop"],["downharpoonright","harpoon.br"],["downharpoonrightbar","harpoon.br.stop"],["downharpoonsleftright","harpoons.blbr"],["downuparrows","arrows.bt"],["downupharpoonsleftright","harpoons.bltr"],["downwhitearrow","arrow.b.stroked"],["downzigzagarrow","arrow.zigzag"],["dprime","prime.double"],["dualmap","multimap.double"],["eighthnote","note.eighth.alt"],["ell","ell"],["emptysetoarr","emptyset.arrow.r"],["emptysetoarrl","emptyset.arrow.l"],["emptysetobar","emptyset.bar"],["emptysetocirc","emptyset.circle"],["eparsl","parallel.slanted.eq"],["eqcolon","eq.colon"],["eqdef","eq.def"],["eqgtr","eq.gt"],["eqless","eq.lt"],["eqsim","minus.tilde"],["equal","eq"],["equalparallel","parallel.eq"],["equiv","eq.triple"],["Equiv","eq.quad"],["equivVert","parallel.equiv"],["eqvparsl","parallel.slanted.equiv"],["errbarblackcircle","errorbar.circle.filled"],["errbarblackdiamond","errorbar.diamond.filled"],["errbarblacksquare","errorbar.square.filled"],["errbarcircle","errorbar.circle.stroked"],["errbardiamond","errorbar.diamond.stroked"],["errbarsquare","errorbar.square.stroked"],["euro","euro"],["exists","exists"],["fallingdotseq","eq.dots.down"],["fint","integral.slash"],["flat","flat"],["forall","forall"],["fourvdots","fence.dotted"],["frown","frown"],["fullouterjoin","join.l.r"],["geq","gt.eq"],["geqq","gt.equiv"],["geqslant","gt.eq.slant"],["gg","gt.double"],["ggg","gt.triple"],["gggnest","gt.triple.nested"],["gnapprox","gt.napprox"],["gneq","gt.neq"],["gneqq","gt.nequiv"],["gnsim","gt.ntilde"],["greater","gt"],["gtlpar","angle.spheric.rev"],["gtrapprox","gt.approx"],["gtrdot","gt.dot"],["gtreqless","gt.eq.lt"],["gtrless","gt.lt"],["gtrsim","gt.tilde"],["heartsuit","suit.heart.stroked"],["hknearrow","arrow.tr.hook"],["hknwarrow","arrow.tl.hook"],["hksearrow","arrow.br.hook"],["hkswarrow","arrow.bl.hook"],["horizbar","bar.h"],["hourglass","hourglass.stroked"],["hrectangle","rect.stroked.h"],["hrectangleblack","rect.filled.h"],["hyphenbullet","bullet.hyph"],["iiiint","integral.quad"],["iiint","integral.triple"],["iinfin","infinity.incomplete"],["iint","integral.double"],["Im","Im"],["imageof","image"],["in","in"],["increment","laplace"],["infty","infinity"],["int","integral"],["intbar","integral.dash"],["intBar","integral.dash.double"],["intcap","integral.inter"],["intclockwise","integral.cw"],["intcup","integral.union"],["interleave","interleave"],["intlarhk","integral.arrow.hook"],["intx","integral.times"],["inversebullet","bullet.hole"],["Join","join"],["langle","chevron.l"],["lAngle","chevron.l.double"],["langledot","chevron.l.dot"],["lat","lat"],["late","lat.eq"],["lbag","bag.l"],["lblkbrbrak","shell.l.filled"],["lbrace","brace.l"],["lBrace","brace.l.stroked"],["lbrack","bracket.l"],["lBrack","bracket.l.stroked"],["lbracklltick","bracket.l.tick.b"],["lbrackultick","bracket.l.tick.t"],["lbrbrak","shell.l"],["Lbrbrak","shell.l.stroked"],["lceil","ceil.l"],["lcurvyangle","chevron.l.curly"],["leftarrow","arrow.l"],["Leftarrow","arrow.l.double"],["leftarrowtail","arrow.l.tail"],["leftarrowtriangle","arrow.l.open"],["leftdasharrow","arrow.l.dashed"],["leftdotarrow","arrow.l.dotted"],["leftdowncurvedarrow","arrow.l.curve"],["leftharpoondown","harpoon.lb"],["leftharpoondownbar","harpoon.lb.bar"],["leftharpoonsupdown","harpoons.ltlb"],["leftharpoonup","harpoon.lt"],["leftharpoonupbar","harpoon.lt.bar"],["leftleftarrows","arrows.ll"],["leftouterjoin","join.l"],["Leftrightarrow","arrow.l.r.double"],["leftrightarrows","arrows.lr"],["leftrightarrowtriangle","arrow.l.r.open"],["leftrightharpoondowndown","harpoon.lb.rb"],["leftrightharpoondownup","harpoon.lb.rt"],["leftrightharpoons","harpoons.ltrb"],["leftrightharpoonsdown","harpoons.lbrb"],["leftrightharpoonsup","harpoons.ltrt"],["leftrightharpoonupdown","harpoon.lt.rb"],["leftrightharpoonupup","harpoon.lt.rt"],["leftrightsquigarrow","arrow.l.r.wave"],["leftsquigarrow","arrow.l.squiggly"],["leftthreearrows","arrows.lll"],["leftthreetimes","times.three.l"],["leftwavearrow","arrow.l.wave"],["leftwhitearrow","arrow.l.stroked"],["leq","lt.eq"],["leqq","lt.equiv"],["leqslant","lt.eq.slant"],["less","lt"],["lessapprox","lt.approx"],["lessdot","lt.dot"],["lesseqgtr","lt.eq.gt"],["lessgtr","lt.gt"],["lesssim","lt.tilde"],["lfloor","floor.l"],["lgblkcircle","circle.filled.big"],["lgroup","paren.l.flat"],["lgwhtcircle","circle.stroked.big"],["ll","lt.double"],["llangle","chevron.l.closed"],["llblacktriangle","triangle.filled.bl"],["llcorner","corner.l.b"],["LLeftarrow","arrow.l.quad"],["Lleftarrow","arrow.l.triple"],["lll","lt.triple"],["lllnest","lt.triple.nested"],["llparenthesis","paren.l.closed"],["lltriangle","triangle.stroked.bl"],["lmoustache","mustache.l"],["lnapprox","lt.napprox"],["lneq","lt.neq"],["lneqq","lt.nequiv"],["lnsim","lt.ntilde"],["longdashv","tack.l.long"],["Longleftarrow","arrow.l.double.long"],["longleftarrow","arrow.l.long"],["Longleftrightarrow","arrow.l.r.double.long"],["longleftrightarrow","arrow.l.r.long"],["longleftsquigarrow","arrow.l.long.squiggly"],["Longmapsfrom","arrow.l.double.long.bar"],["longmapsfrom","arrow.l.long.bar"],["longmapsto","arrow.r.long.bar"],["Longmapsto","arrow.r.double.long.bar"],["Longrightarrow","arrow.r.double.long"],["longrightarrow","arrow.r.long"],["longrightsquigarrow","arrow.r.long.squiggly"],["looparrowleft","arrow.l.loop"],["looparrowright","arrow.r.loop"],["lparen","paren.l"],["lParen","paren.l.stroked"],["lrblacktriangle","triangle.filled.br"],["lrcorner","corner.r.b"],["lrtriangle","triangle.stroked.br"],["ltimes","times.l"],["lvzigzag","fence.l"],["Lvzigzag","fence.l.double"],["maltese","maltese"],["mapsdown","arrow.b.bar"],["mapsfrom","arrow.l.bar"],["Mapsfrom","arrow.l.double.bar"],["mapsto","arrow.r.bar"],["Mapsto","arrow.r.double.bar"],["mapsup","arrow.t.bar"],["mathampersand","amp"],["mathatsign","at"],["mathcolon","colon"],["mathcomma","comma"],["mathdollar","dollar"],["mathexclam","excl"],["mathhyphen","hyph"],["mathparagraph","pilcrow"],["mathpercent","percent"],["mathperiod","dot.basic"],["mathplus","plus"],["mathquestion","quest"],["mathratio","ratio"],["mathsection","section"],["mathsemicolon","semi"],["mathslash","slash"],["mathsterling","pound"],["mathyen","yen"],["mdblkdiamond","diamond.filled.medium"],["mdblklozenge","lozenge.filled.medium"],["mdlgblkcircle","circle.filled"],["mdlgblkdiamond","diamond.filled"],["mdlgblklozenge","lozenge.filled"],["mdlgblksquare","square.filled"],["mdlgwhtcircle","circle.stroked"],["mdlgwhtdiamond","diamond.stroked"],["mdlgwhtlozenge","lozenge.stroked"],["mdlgwhtsquare","square.stroked"],["mdsmblkcircle","circle.filled.tiny"],["mdsmwhtcircle","circle.stroked.small"],["mdwhtdiamond","diamond.stroked.medium"],["mdwhtlozenge","lozenge.stroked.medium"],["measeq","eq.m"],["measuredangle","angle.arc"],["measuredangleleft","angle.arc.rev"],["measuredrightangle","angle.right.arc"],["mho","Omega.inv"],["mid","divides"],["minus","minus"],["models","models"],["mp","minus.plus"],["multimap","multimap"],["nabla","gradient"],["napprox","approx.not"],["nasymp","asymp.not"],["natural","natural"],["ncong","tilde.equiv.not"],["ne","eq.not"],["Nearrow","arrow.tr.double"],["neg","not"],["nequiv","equiv.not"],["neswarrow","arrow.tr.bl"],["nexists","exists.not"],["ngeq","gt.eq.not"],["ngtr","gt.not"],["ngtrless","gt.lt.not"],["ngtrsim","gt.tilde.not"],["nHdownarrow","arrow.b.dstruck"],["nhpar","parallel.struck"],["nHuparrow","arrow.t.dstruck"],["nhVvert","interleave.struck"],["ni","in.rev"],["nLeftarrow","arrow.l.double.not"],["nleftarrow","arrow.l.not"],["nLeftrightarrow","arrow.l.r.double.not"],["nleftrightarrow","arrow.l.r.not"],["nleq","lt.eq.not"],["nless","lt.not"],["nlessgtr","lt.gt.not"],["nlesssim","lt.tilde.not"],["nmid","divides.not"],["nni","in.rev.not"],["notin","in.not"],["nparallel","parallel.not"],["nprec","prec.not"],["npreccurlyeq","prec.curly.eq.not"],["nRightarrow","arrow.r.double.not"],["nrightarrow","arrow.r.not"],["nsim","tilde.not"],["nsimeq","tilde.eq.not"],["nsqsubseteq","subset.eq.sq.not"],["nsqsupseteq","supset.eq.sq.not"],["nsubset","subset.not"],["nsubseteq","subset.eq.not"],["nsucc","succ.not"],["nsucccurlyeq","succ.curly.eq.not"],["nsupset","supset.not"],["nsupseteq","supset.eq.not"],["ntrianglelefteq","lt.tri.eq.not"],["ntrianglerighteq","gt.tri.eq.not"],["nvartriangleleft","lt.tri.not"],["nvartriangleright","gt.tri.not"],["nVdash","forces.not"],["nvdash","tack.r.not"],["nvDash","tack.r.double.not"],["nvinfty","infinity.bar"],["nvLeftarrow","arrow.l.double.struck"],["nvleftarrow","arrow.l.struck"],["nVleftarrow","arrow.l.dstruck"],["nvleftarrowtail","arrow.l.tail.struck"],["nVleftarrowtail","arrow.l.tail.dstruck"],["nvLeftrightarrow","arrow.l.r.double.struck"],["nvleftrightarrow","arrow.l.r.struck"],["nVleftrightarrow","arrow.l.r.dstruck"],["nvRightarrow","arrow.r.double.struck"],["nvrightarrow","arrow.r.struck"],["nVrightarrow","arrow.r.dstruck"],["nvrightarrowtail","arrow.r.tail.struck"],["nVrightarrowtail","arrow.r.tail.dstruck"],["nvtwoheadleftarrow","arrow.l.twohead.struck"],["nVtwoheadleftarrow","arrow.l.twohead.dstruck"],["nvtwoheadleftarrowtail","arrow.l.twohead.tail.struck"],["nVtwoheadleftarrowtail","arrow.l.twohead.tail.dstruck"],["nvtwoheadrightarrow","arrow.r.twohead.struck"],["nVtwoheadrightarrow","arrow.r.twohead.dstruck"],["nvtwoheadrightarrowtail","arrow.r.twohead.tail.struck"],["nVtwoheadrightarrowtail","arrow.r.twohead.tail.dstruck"],["Nwarrow","arrow.tl.double"],["nwsearrow","arrow.tl.br"],["obrbrak","shell.t"],["obslash","backslash.o"],["odiv","div.o"],["odot","dot.o"],["odotslashdot","div.slanted.o"],["ogreaterthan","gt.o"],["oiiint","integral.vol"],["oiint","integral.surf"],["oint","integral.cont"],["ointctrclockwise","integral.cont.ccw"],["olessthan","lt.o"],["ominus","minus.o"],["operp","perp.o"],["oplus","plus.o"],["opluslhrim","plus.o.l"],["oplusrhrim","plus.o.r"],["origof","original"],["oslash","slash.o"],["otimes","times.o"],["otimeshat","times.o.hat"],["otimeslhrim","times.o.l"],["otimesrhrim","times.o.r"],["parallel","parallel"],["parallelogram","parallelogram.stroked"],["parallelogramblack","parallelogram.filled"],["parsim","parallel.tilde"],["partial","partial"],["pentagon","penta.stroked"],["pentagonblack","penta.filled"],["perp","perp"],["pm","plus.minus"],["prec","prec"],["Prec","prec.double"],["precapprox","prec.approx"],["preccurlyeq","prec.curly.eq"],["preceq","prec.eq"],["preceqq","prec.equiv"],["precnapprox","prec.napprox"],["precneq","prec.neq"],["precneqq","prec.nequiv"],["precnsim","prec.ntilde"],["precsim","prec.tilde"],["prime","prime"],["prod","product"],["propto","prop"],["QED","qed"],["qprime","prime.quad"],["quarternote","note.quarter.alt"],["questeq","eq.quest"],["Question","quest.double"],["rangle","chevron.r"],["rAngle","chevron.r.double"],["rangledot","chevron.r.dot"],["rangledownzigzagarrow","angle.azimuth"],["rbag","bag.r"],["rblkbrbrak","shell.r.filled"],["rbrace","brace.r"],["rBrace","brace.r.stroked"],["rbrack","bracket.r"],["rBrack","bracket.r.stroked"],["rbracklrtick","bracket.r.tick.b"],["rbrackurtick","bracket.r.tick.t"],["rbrbrak","shell.r"],["Rbrbrak","shell.r.stroked"],["rceil","ceil.r"],["rcurvyangle","chevron.r.curly"],["Re","Re"],["revangle","angle.rev"],["revemptyset","emptyset.rev"],["revnmid","divides.not.rev"],["rfloor","floor.r"],["rgroup","paren.r.flat"],["rightangle","angle.right"],["rightanglemdot","angle.right.dot"],["rightanglesqr","angle.right.square"],["rightarrow","arrow.r"],["Rightarrow","arrow.r.double"],["rightarrowbar","arrow.r.stop"],["rightarrowonoplus","plus.o.arrow"],["rightarrowtail","arrow.r.tail"],["rightarrowtriangle","arrow.r.open"],["rightdasharrow","arrow.r.dashed"],["rightdotarrow","arrow.r.dotted"],["rightdowncurvedarrow","arrow.r.curve"],["rightharpoondown","harpoon.rb"],["rightharpoondownbar","harpoon.rb.stop"],["rightharpoonsupdown","harpoons.rtrb"],["rightharpoonup","harpoon.rt"],["rightharpoonupbar","harpoon.rt.stop"],["rightleftarrows","arrows.rl"],["rightleftharpoons","harpoons.rtlb"],["rightleftharpoonsdown","harpoons.rblb"],["rightleftharpoonsup","harpoons.rtlt"],["rightouterjoin","join.r"],["rightrightarrows","arrows.rr"],["rightsquigarrow","arrow.r.squiggly"],["rightthreearrows","arrows.rrr"],["rightthreetimes","times.three.r"],["rightwavearrow","arrow.r.wave"],["rightwhitearrow","arrow.r.stroked"],["risingdotseq","eq.dots.up"],["rmoustache","mustache.r"],["rparen","paren.r"],["rParen","paren.r.stroked"],["rrangle","chevron.r.closed"],["RRightarrow","arrow.r.quad"],["Rrightarrow","arrow.r.triple"],["rrparenthesis","paren.r.closed"],["rsolbar","backslash.not"],["rtimes","times.r"],["rvzigzag","fence.r"],["Rvzigzag","fence.r.double"],["Searrow","arrow.br.double"],["setminus","without"],["sharp","sharp"],["shortdowntack","tack.b.short"],["shortlefttack","tack.l.short"],["shortuptack","tack.t.short"],["sim","tilde.op"],["sime","tilde.eq"],["similarleftarrow","arrow.l.tilde"],["similarrightarrow","arrow.r.tilde"],["simneqq","tilde.nequiv"],["smallblacktriangleleft","triangle.filled.small.l"],["smallblacktriangleright","triangle.filled.small.r"],["smallin","in.small"],["smallni","in.rev.small"],["smalltriangleleft","triangle.stroked.small.l"],["smalltriangleright","triangle.stroked.small.r"],["smashtimes","smash"],["smblkcircle","bullet"],["smblkdiamond","diamond.filled.small"],["smblklozenge","lozenge.filled.small"],["smeparsl","parallel.slanted.eq.tilde"],["smile","smile"],["smt","smt"],["smte","smt.eq"],["smwhtcircle","bullet.stroked"],["smwhtdiamond","diamond.stroked.small"],["smwhtlozenge","lozenge.stroked.small"],["sphericalangle","angle.spheric"],["sphericalangleup","angle.spheric.t"],["sqcap","inter.sq"],["Sqcap","inter.sq.double"],["sqcup","union.sq"],["Sqcup","union.sq.double"],["sqint","integral.square"],["sqsubset","subset.sq"],["sqsubseteq","subset.eq.sq"],["sqsubsetneq","subset.sq.neq"],["sqsupset","supset.sq"],["sqsupseteq","supset.eq.sq"],["sqsupsetneq","supset.sq.neq"],["squoval","square.stroked.rounded"],["sslash","slash.double"],["star","star.op"],["stareq","eq.star"],["subset","subset"],["Subset","subset.double"],["subsetdot","subset.dot"],["subseteq","subset.eq"],["subsetneq","subset.neq"],["succ","succ"],["Succ","succ.double"],["succapprox","succ.approx"],["succcurlyeq","succ.curly.eq"],["succeq","succ.eq"],["succeqq","succ.equiv"],["succnapprox","succ.napprox"],["succneq","succ.neq"],["succneqq","succ.nequiv"],["succnsim","succ.ntilde"],["succsim","succ.tilde"],["sum","sum"],["sumint","sum.integral"],["supset","supset"],["Supset","supset.double"],["supsetdot","supset.dot"],["supseteq","supset.eq"],["supsetneq","supset.neq"],["Swarrow","arrow.bl.double"],["therefore","therefore"],["threedangle","angle.spatial"],["threedotcolon","colon.tri.op"],["tieinfty","infinity.tie"],["times","times"],["tminus","miny"],["top","tack.b"],["tplus","tiny"],["trianglecdot","triangle.stroked.dot"],["triangledown","triangle.stroked.small.b"],["triangleleft","triangle.stroked.l"],["trianglelefteq","lt.tri.eq"],["triangleminus","minus.triangle"],["triangleplus","plus.triangle"],["triangleq","eq.delta"],["triangleright","triangle.stroked.r"],["trianglerighteq","gt.tri.eq"],["triangletimes","times.triangle"],["tripleplus","plus.triple"],["trprime","prime.triple"],["trslash","slash.triple"],["turnediota","iota.inv"],["twoheaddownarrow","arrow.b.twohead"],["twoheadleftarrow","arrow.l.twohead"],["twoheadleftarrowtail","arrow.l.twohead.tail"],["twoheadmapsfrom","arrow.l.twohead.bar"],["twoheadmapsto","arrow.r.twohead.bar"],["twoheadrightarrow","arrow.r.twohead"],["twoheadrightarrowtail","arrow.r.twohead.tail"],["twoheaduparrow","arrow.t.twohead"],["twonotes","note.eighth.beamed"],["ubrbrak","shell.b"],["ulblacktriangle","triangle.filled.tl"],["ulcorner","corner.l.t"],["ultriangle","triangle.stroked.tl"],["uminus","union.minus"],["underbrace","brace.b"],["underbracket","bracket.b"],["underparen","paren.b"],["unicodecdots","dots.h.c"],["unicodeellipsis","dots.h"],["upand","amp.inv"],["uparrow","arrow.t"],["Uparrow","arrow.t.double"],["uparrowbarred","arrow.t.struck"],["upbackepsilon","epsilon.alt.rev"],["updasharrow","arrow.t.dashed"],["upDigamma","Digamma"],["updigamma","digamma"],["Updownarrow","arrow.t.b.double"],["updownarrows","arrows.tb"],["updownharpoonleftleft","harpoon.tl.bl"],["updownharpoonleftright","harpoon.tl.br"],["updownharpoonrightleft","harpoon.tr.bl"],["updownharpoonrightright","harpoon.tr.br"],["updownharpoonsleftright","harpoons.tlbr"],["upharpoonleft","harpoon.tl"],["upharpoonleftbar","harpoon.tl.bar"],["upharpoonright","harpoon.tr"],["upharpoonrightbar","harpoon.tr.bar"],["upharpoonsleftright","harpoons.tltr"],["uplus","union.plus"],["upuparrows","arrows.tt"],["upwhitearrow","arrow.t.stroked"],["urblacktriangle","triangle.filled.tr"],["urcorner","corner.r.t"],["urtriangle","triangle.stroked.tr"],["UUparrow","arrow.t.quad"],["Uuparrow","arrow.t.triple"],["varclubsuit","suit.club.stroked"],["varhexagon","hexa.stroked"],["varhexagonblack","hexa.filled"],["varnothing","emptyset"],["varointclockwise","integral.cont.cw"],["varspadesuit","suit.spade.stroked"],["vartriangle","triangle.stroked.small.t"],["vartriangleleft","lt.tri"],["vartriangleright","gt.tri"],["Vbar","tack.t.double"],["Vdash","forces"],["vdash","tack.r"],["vDash","tack.r.double"],["vdots","dots.v"],["vee","or"],["Vee","or.double"],["veedot","or.dot"],["veeeq","eq.equi"],["vert","bar.v"],["Vert","bar.v.double"],["vlongdash","tack.r.long"],["vrectangle","rect.stroked.v"],["vrectangleblack","rect.filled.v"],["Vvert","bar.v.triple"],["vysmblkcircle","circle.filled.small"],["vysmwhtcircle","circle.stroked.tiny"],["wedge","and"],["Wedge","and.double"],["wedgedot","and.dot"],["wedgeq","eq.est"],["whiteinwhitetriangle","triangle.stroked.nested"],["whthorzoval","ellipse.stroked.h"],["whtvertoval","ellipse.stroked.v"],["wideangledown","angle.obtuse"],["wr","wreath"],["xsol","slash.big"]]),lt=new Map([["gets","leftarrow"],["iff","Longleftrightarrow"],["implies","Longrightarrow"]]);for(let[n,e]of it)E.has(n)||E.set(n,e);var B=new Map;for(let[n,e]of Array.from(E.entries()).reverse())B.set(e,n);B.set("oo","infty");var ut=new Map([["top","top"],["frac","frac"],["tilde","tilde"],["hat","hat"],["upright","mathrm"],["bold","boldsymbol"],["infinity","infty"],["diff","partial"]]);for(let[n,e]of ut)B.set(n,e);for(let[n,e]of lt)E.has(n)||E.set(n,E.get(e));var Y=class extends Error{node;constructor(e,r=null){super(e),this.name="ConverterError",this.node=r}},pt=i.NONE.toNode(),ct=["dim","id","im","mod","Pr","sech","csch"];function ht(n){if(/^[a-zA-Z0-9]$/.test(n))return n;if(n==="/")return"\\/";if(["\\\\","\\{","\\}","\\%"].includes(n))return n.substring(1);if(["\\$","\\#","\\&","\\_"].includes(n))return n;if(n.startsWith("\\")){let e=n.slice(1);return E.has(e)?E.get(e):null}return n}function P(n,e){let r;switch(n.type){case 0:return i.NONE;case 2:r=1;break;case 1:r=2;break;case 3:r=3;break;case 4:r=5;break;case 5:r=6;break;case 6:r=8;break;case 7:{if(n.value==="\\\\")return new i(7,"\\");if(n.value==="\\!")return new i(1,"#h(-math.thin.amount)");if(n.value==="~"){let s=E.get("~");return new i(1,s)}else if(E.has(n.value.substring(1))){let s=E.get(n.value.substring(1));return new i(1,s)}else throw new Error(`Unknown control sequence: ${n.value}`)}default:throw Error(`Unknown token type: ${n.type}`)}let t=ht(n.value);if(t===null){if(e.nonStrict)return new i(r,n.value.substring(1));throw new Y(`Unknown token: ${n.value}`,n)}return new i(r,t)}function dt(n,e){let[r,t]=n.args;if(e.optimize&&["\\overset{\\text{def}}{=}","\\overset{d e f}{=}"].includes(n.toString()))return new i(1,"eq.def").toNode();let s=new m(new i(1,"limits"),[b(t,e)]);return new _({base:s,sup:b(r,e),sub:null})}function Tt(n,e){let[r,t]=n.args,s=new m(new i(1,"limits"),[b(t,e)]);return new _({base:s,sub:b(r,e),sup:null})}function gt(n){let e={},r={l:"#left",c:"#center",r:"#right"},t=Array.from(n),s=[],o=0;for(let u of t)u==="|"?s.push(o):(u==="l"||u==="c"||u==="r")&&o++;if(s.length>0){let u;s.length===1?u=`#${s[0]}`:u=`#(vline: (${s.join(", ")}))`,e.augment=new i(3,u).toNode()}let a=t.map(u=>r[u]).filter(u=>u!==void 0).map(u=>new i(3,u).toNode());if(a.length>0){let u=a.every(p=>p.eq(a[0]));e.align=u?a[0]:new i(3,"#center").toNode()}return e}var wt=new i(2,"("),bt=new i(2,")");function me(n){return["group","supsub","matrixLike","fraction","empty"].includes(n.type)?new q(null,{left:wt,right:bt,body:n}):n}function b(n,e){switch(n.type){case"terminal":return P(n.head,e).toNode();case"text":{let t=n;return new i(4,t.head.value).toNode()}case"ordgroup":let r=n;return new M(r.items.map(t=>b(t,e)));case"supsub":{let t=n,{base:s,sup:o,sub:a}=t;if(s&&s.type==="funcCall"&&s.head.value==="\\overbrace"&&o)return new m(new i(1,"overbrace"),[b(s.args[0],e),b(o,e)]);if(s&&s.type==="funcCall"&&s.head.value==="\\underbrace"&&a)return new m(new i(1,"underbrace"),[b(s.args[0],e),b(a,e)]);let u={base:b(s,e),sup:o?b(o,e):null,sub:a?b(a,e):null};return u.sup&&(u.sup=me(u.sup)),u.sub&&(u.sub=me(u.sub)),new _(u)}case"leftright":{let t=n,{left:s,right:o}=t,a=b(t.body,e);if(e.optimize&&s!==null&&o!==null){let h=P(s,e),d=P(o,e);if(s.value==="\\|"&&o.value==="\\|")return new m(new i(1,"norm"),[a]);if(["[]","()","\\{\\}","\\lfloor\\rfloor","\\lceil\\rceil","\\lfloor\\rceil"].includes(s.value+o.value))return new M([h.toNode(),a,d.toNode()])}let u=function(h){return["(",")","{","["].includes(h.value)?new i(2,"\\"+h.value):h},p=s?P(s,e):null,c=o?P(o,e):null;return p===null&&c!==null&&(c=u(c)),c===null&&p!==null&&(p=u(p)),new q(new i(1,"lr"),{body:a,left:p,right:c})}case"funcCall":{let t=n,s=b(t.args[0],e);if(t.head.value==="\\sqrt"&&t.data){let o=b(t.data,e);return new m(new i(1,"root"),[o,s])}if(t.head.value==="\\mathbf"){let o=new m(new i(1,"bold"),[s]);return new m(new i(1,"upright"),[o])}if(t.head.value==="\\overrightarrow")return new m(new i(1,"arrow"),[s]);if(t.head.value==="\\overleftarrow")return new m(new i(1,"accent"),[s,new i(1,"arrow.l").toNode()]);if(t.head.value==="\\operatorname"||t.head.value==="\\operatorname*"){if(e.optimize&&ct.includes(s.head.value))return new i(1,s.head.value).toNode();let o=new m(new i(1,"op"),[new i(4,s.head.value).toNode()]);return t.head.value==="\\operatorname*"&&o.setOptions({limits:new i(3,"#true").toNode()}),o}if(t.head.value==="\\textcolor"){let o=new I(new i(1,"#text"),[b(t.args[1],e)]);return o.setOptions({fill:s}),o}if(t.head.value==="\\substack"||t.head.value==="\\displaylines"||t.head.value==="\\mathinner")return s;if(t.head.value==="\\mathrel")return new m(new i(1,"class"),[new i(4,"relation").toNode(),s]);if(t.head.value==="\\mathbin")return new m(new i(1,"class"),[new i(4,"binary").toNode(),s]);if(t.head.value==="\\mathop")return new m(new i(1,"class"),[new i(4,"large").toNode(),s]);if(t.head.value==="\\set")return new q(null,{body:s,left:i.LEFT_BRACE,right:i.RIGHT_BRACE});if(t.head.value==="\\not"){let o=b(t.args[0],e);if(T(o.type==="terminal"),o.head.type===1)return new i(1,o.head.value+".not").toNode();switch(o.head.value){case"=":return new i(1,"eq.not").toNode();default:throw new Error(`Not supported: \\not ${o.head.value}`)}}if(t.head.value==="\\overset")return dt(t,e);if(t.head.value==="\\underset")return Tt(t,e);if(t.head.value==="\\frac"&&e.fracToSlash)return new D(t.args.map(o=>b(o,e)).map(me));if(e.optimize){if(t.head.value==="\\mathbb"&&/^\\mathbb{[A-Z]}$/.test(t.toString()))return new i(1,s.head.value.repeat(2)).toNode();if(t.head.value==="\\mathrm"&&t.toString()==="\\mathrm{d}")return new i(1,"dif").toNode()}return new m(P(t.head,e),t.args.map(o=>b(o,e)))}case"beginend":{let t=n,s=t.matrix.map(o=>o.map(a=>b(a,e)));if(t.head.value.startsWith("align"))return new y(null,s);if(t.head.value==="cases")return new y(y.CASES,s);if(t.head.value==="subarray"){if(t.data)switch(t.data.head.value){case"r":s.forEach(a=>a.push(i.EMPTY.toNode()));break;case"l":s.forEach(a=>a.unshift(i.EMPTY.toNode()));break;default:break}return new y(null,s)}if(t.head.value==="array"){let o={delim:pt};T(t.data!==null&&t.head.type===3);let a=gt(t.data.head.value);Object.assign(o,a);let u=new y(y.MAT,s);return u.setOptions(o),u}if(t.head.value.endsWith("matrix")){let o=new y(y.MAT,s),a;switch(t.head.value){case"matrix":a=i.NONE;break;case"pmatrix":return o;case"bmatrix":a=new i(4,"[");break;case"Bmatrix":a=new i(4,"{");break;case"vmatrix":a=new i(4,"|");break;case"Vmatrix":{a=new i(1,"bar.v.double");break}default:throw new Y(`Unimplemented beginend: ${t.head}`,t)}return o.setOptions({delim:a.toNode()}),o}throw new Y(`Unimplemented beginend: ${t.head}`,t)}default:throw new Y(`Unimplemented node type: ${n.type}`,n)}}function A(n){switch(n.type){case 0:return l.EMPTY;case 1:{let e=function(r){switch(r){case"eq":return"=";case"plus":return"+";case"minus":return"-";case"percent":return"%";default:return B.has(r)?"\\"+B.get(r):"\\"+r}};if(n.value.endsWith(".not")){let r=e(n.value.slice(0,-4));return new l(2,r.startsWith("\\")?`\\not${r}`:`\\not ${r}`)}return new l(2,e(n.value))}case 2:{let e;return["{","}","%"].includes(n.value)?e="\\"+n.value:e=n.value,new l(1,e)}case 3:return new l(3,n.value);case 4:return new l(3,n.value);case 5:return new l(4,n.value);case 6:return new l(5,n.value);case 7:{let e;switch(n.value){case"\\":e="\\\\";break;case"&":e="&";break;default:throw new Error(`[typst_token_to_tex]Unimplemented control sequence: ${n.value}`)}return new l(7,e)}case 8:return new l(6,n.value);default:throw new Error(`Unimplemented token type: ${n.type}`)}}var mt=new l(1,",").toNode();function fe(n,e){let r=t=>fe(t,e);switch(n.type){case"terminal":{let t=n;if(t.head.type===1){if(t.head.value==="eq.def")return new w(new l(2,"\\overset"),[new L(new l(3,"def")),new l(1,"=").toNode()]);if(t.head.value==="comma")return new l(1,",").toNode();if(t.head.value==="dif")return new w(new l(2,"\\mathrm"),[new l(1,"d").toNode()]);if(t.head.value==="hyph"||t.head.value==="hyph.minus")return new L(new l(3,"-"));if(/^([A-Z])\1$/.test(t.head.value))return new w(new l(2,"\\mathbb"),[new l(1,t.head.value[0]).toNode()])}return t.head.type===4?new L(new l(3,t.head.value)):A(t.head).toNode()}case"group":{let s=n.items.map(r),o=new l(7,"&").toNode(),a=new l(7,"\\\\").toNode();if(V(s,o)){let u=C(s,a),p=[];for(let c of u){let h=C(c,o);p.push(h.map(d=>new f(d)))}return new v(new l(3,"aligned"),p)}return new f(s)}case"leftright":{let t=n,s=r(t.body),o=t.left?A(t.left):new l(1,"."),a=t.right?A(t.right):new l(1,".");return t.isOverHigh()&&(o.value="\\left"+o.value,a.value="\\right"+a.value),new f([o.toNode(),s,a.toNode()])}case"funcCall":{let t=n;switch(t.head.value){case"norm":{let s=t.args[0],o=r(s);return t.isOverHigh()?new S({body:o,left:new l(2,"\\|"),right:new l(2,"\\|")}):o}case"floor":case"ceil":{let s="\\l"+t.head.value,o="\\r"+t.head.value,a=t.args[0],u=r(a),p=new l(2,s),c=new l(2,o);return t.isOverHigh()?new S({body:u,left:p,right:c}):new f([p.toNode(),u,c.toNode()])}case"root":{let[s,o]=t.args,a=r(s);return new w(new l(2,"\\sqrt"),[r(o)],a)}case"overbrace":case"underbrace":{let[s,o]=t.args,a=new w(A(t.head),[r(s)]),u=r(o),p=t.head.value==="overbrace"?{base:a,sup:u,sub:null}:{base:a,sub:u,sup:null};return new O(p)}case"vec":{let s=t.args.map(o=>[r(o)]);return new v(new l(3,"pmatrix"),s)}case"op":{let s=t.args[0];return T(s.head.type===4),new w(A(t.head),[new l(3,s.head.value).toNode()])}case"class":{let s=t.args[0];T(s.head.type===4);let o;switch(s.head.value){case"relation":o="\\mathrel";break;case"binary":o="\\mathbin";break;case"large":o="\\mathop";break;default:throw new Error(`Unimplemented class: ${s.head.value}`)}return new w(new l(2,o),[r(t.args[1])])}case"display":{let s=t.args[0],o=new f([l.COMMAND_DISPLAYSTYLE.toNode(),r(s)]);return e.blockMathMode||o.items.push(l.COMMAND_TEXTSTYLE.toNode()),o}case"inline":{let s=t.args[0],o=new f([l.COMMAND_TEXTSTYLE.toNode(),r(s)]);return e.blockMathMode&&o.items.push(l.COMMAND_DISPLAYSTYLE.toNode()),o}default:{let s=A(t.head),o=z.includes(s.value.substring(1))||W.includes(s.value.substring(1));return s.value.length>0&&o?new w(s,t.args.map(r)):new f([A(t.head).toNode(),new l(1,"(").toNode(),...Me(t.args.map(r),mt),new l(1,")").toNode()])}}}case"markupFunc":{let t=n;switch(t.head.value){case"#text":if(t.options&&t.options.fill){let s=t.options.fill;return new w(new l(2,"\\textcolor"),[r(s),r(t.fragments[0])])}case"#heading":default:throw new Error(`Unimplemented markup function: ${t.head.value}`)}}case"supsub":{let t=n,{base:s,sup:o,sub:a}=t,u=o?r(o):null,p=a?r(a):null;if(s.head.eq(new i(1,"limits"))){let x=r(s.args[0]);if(u!==null&&p===null)return new w(new l(2,"\\overset"),[u,x]);if(u===null&&p!==null)return new w(new l(2,"\\underset"),[p,x]);{let oe=new w(new l(2,"\\underset"),[p,x]);return new w(new l(2,"\\overset"),[u,oe])}}let c=r(s);return new O({base:c,sup:u,sub:p})}case"matrixLike":{let t=n,s=t.matrix.map(o=>o.map(r));if(t.head.eq(y.MAT)){let o="pmatrix";if(t.options&&"delim"in t.options){let a=t.options.delim;switch(a.head.value){case"#none":o="matrix";break;case"[":case"]":o="bmatrix";break;case"(":case")":o="pmatrix";break;case"{":case"}":o="Bmatrix";break;case"|":o="vmatrix";break;case"bar":case"bar.v":o="vmatrix";break;case"bar.v.double":o="Vmatrix";break;default:throw new Error(`Unexpected delimiter ${a.head}`)}}return new v(new l(3,o),s)}else{if(t.head.eq(y.CASES))return new v(new l(3,"cases"),s);throw new Error(`Unexpected matrix type ${t.head}`)}}case"fraction":{let t=n,[s,o]=t.args,a=r(s),u=r(o);return new w(new l(2,"\\frac"),[a,u])}default:throw new Error("[convert_typst_node_to_tex] Unimplemented type: "+n.type)}}var ft=Array.from(Q.keys());function yt(){return`(${ft.map(e=>(e=e.replaceAll("|","\\|"),e=e.replaceAll(".","\\."),e=e.replaceAll("[","\\["),e=e.replaceAll("]","\\]"),e)).join("|")})`}var Et=yt(),Nt=new Map([[String.raw`//[^\n]*`,n=>new i(5,n.text().substring(2))],[String.raw`/`,n=>new i(2,n.text())],[String.raw`[_^&]`,n=>new i(7,n.text())],[String.raw`\r?\n`,n=>new i(8,`
|
|
10
|
-
`)],[String.raw
|
|
11
|
-
`)
|
|
12
|
-
`))&&o.push(p)}return a>=e.length&&t!==null?[i.NONE.toNode(),-1]:[qt(o),a+1]}parseSupOrSub(e,r){let t,s;if(e[r].eq(X)){if([t,s]=this.parseUntil(e,r+1,re),s===-1)throw new Error("Unmatched '('")}else[t,s]=this.parseNextExprWithoutSupSub(e,r);let o=Be(e,s);return o>0&&(t=new M([t].concat(Pe(o))),s+=o),[t,s]}parseNextExprWithoutSupSub(e,r){let t=e[r],s=t.toNode();if(t.eq(X)){let[o,a]=this.parseUntil(e,r+1,re);if(a===-1)throw new Error("Unmatched '('");return[new q(null,{body:o,left:X,right:re}),a]}if(t.type===2&&!ke(t.value[0]))return[s,r+1];if([2,1].includes(t.type)&&r+1<e.length&&e[r+1].eq(X)){if(t.value==="mat"){let[p,c,h]=this.parseMatrix(e,r+1,St,Ee),d=new y(t,p);return d.setOptions(c),[d,h]}if(t.value==="cases"){let[p,c,h]=this.parseMatrix(e,r+1,Ee,At),d=new y(t,p);return d.setOptions(c),[d,h]}if(t.value==="lr")return this.parseLrArguments(e,r+1);if(["#heading","#text"].includes(t.value)){let[p,c]=this.parseArguments(e,r+1),h=Lt(p);T(e[c].eq(Ue));let d=new i(2,"$"),x=We(e,c+1,[d],[d]),[oe,Ct]=this.parseGroup(e,c+2,x);T(e[x+1].eq(He));let xe=new I(t,[oe]);return xe.setOptions(h),[xe,x+2]}let[o,a]=this.parseArguments(e,r+1);return[new m(t,o),a]}return[s,r+1]}parseArguments(e,r){let t=ye(e,r);return[this.parseArgumentsWithSeparator(e,r+1,t,Ee),t+1]}parseLrArguments(e,r){let t=new i(1,"lr"),s=ye(e,r),o=null,a=null,u=r+1,p=s;p>u&&e[u].isOneOf(i.LEFT_DELIMITERS)&&(o=e[u],u+=1),p-1>u&&e[p-1].isOneOf(i.RIGHT_DELIMITERS)&&(a=e[p-1],p-=1);let[c,h]=this.parseGroup(e,u,p);return[new q(t,{body:c,left:o,right:a}),s+1]}parseMatrix(e,r,t,s){let o=ye(e,r),a=[],u={},p=r+1;for(;p<o;)for(;p<o;){let c=le(e,t,p);(c===-1||c>o)&&(c=o);let h=this.parseArgumentsWithSeparator(e,p,c,s),d={};[h,d]=kt(h),a.push(h),Object.assign(u,d),p=c+1}return[a,u,o+1]}parseArgumentsWithSeparator(e,r,t,s){let o=[],a=r;for(;a<t;){let u,p,c={spaceSensitive:!1,newlineSensitive:!0};[u,p]=this.parseUntil(e.slice(0,t),a,s,c),p==-1&&([u,p]=this.parseUntil(e.slice(0,t),a,null,c)),o.push(u),a=p}return o}};function $e(n){let e=new Ne,r=Ie(n);return e.parse(r)}var se=class{buffer="";queue=[];append(e){this.queue=this.queue.concat(e.serialize())}flushQueue(){for(;this.queue.length>0;){let e=this.queue[this.queue.length-1];if(e.eq(l.COMMAND_DISPLAYSTYLE)||e.eq(l.COMMAND_TEXTSTYLE))this.queue.pop();else break}for(let e=0;e<this.queue.length;e++)this.buffer=ie(this.buffer,this.queue[e]);this.queue=[]}finalize(){return this.flushQueue(),this.buffer}};function Fe(n,e={}){let r={nonStrict:!0,preferShorthands:!0,keepSpaces:!1,fracToSlash:!0,inftyToOo:!1,optimize:!0,customTexMacros:{}};if(typeof e!="object")throw new Error("options must be an object");for(let a in r)a in e&&(r[a]=e[a]);let t=Re(n,r.customTexMacros),s=b(t,r),o=new te(r);return o.serialize(s),o.finalize()}function Ge(n,e={}){let r={blockMathMode:!0};if(typeof e!="object")throw new Error("options must be an object");for(let a in r)a in e&&(r[a]=e[a]);let t=$e(n),s=fe(t,r),o=new se;return o.append(s),o.finalize()}window.tex2typst=Fe;window.typst2tex=Ge;})();
|
|
1
|
+
"use strict";(()=>{function U(s){return"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".includes(s)}function T(s,e="Assertion failed."){if(!s)throw new Error(e)}var l=class s{type;value;constructor(e,r){this.type=e,this.value=r}eq(e){return this.type===e.type&&this.value===e.value}toString(){switch(this.type){case 4:return"%"+this.value;default:return this.value}}toNode(){return new ie(this)}static EMPTY=new s(0,"");static COMMAND_DISPLAYSTYLE=new s(2,"\\displaystyle");static COMMAND_TEXTSTYLE=new s(2,"\\textstyle")},v=class{type;head;constructor(e,r){this.type=e,this.head=r||l.EMPTY}eq(e){return this.type===e.type&&this.head.eq(e.head)}toString(){return this.serialize().reduce(le,"")}},ie=class extends v{constructor(e){super("terminal",e)}serialize(){switch(this.head.type){case 0:return[];case 1:case 2:case 3:case 4:case 7:return[this.head];case 5:case 6:{let e=[];for(let r of this.head.value){let t=r===" "?5:6;e.push(new l(t,r))}return e}default:throw new Error(`Unknown terminal token type: ${this.head.type}`)}}},_=class extends v{constructor(e){T(e.type===3),super("text",e)}serialize(){return[new l(2,"\\text"),new l(1,"{"),this.head,new l(1,"}")]}},f=class extends v{items;constructor(e){super("ordgroup",l.EMPTY),this.items=e}serialize(){return this.items.map(e=>e.serialize()).flat()}},S=class extends v{base;sup;sub;constructor(e){super("supsub",l.EMPTY),this.base=e.base,this.sup=e.sup,this.sub=e.sub}serialize(){let e=[],{base:r,sup:t,sub:n}=this;e=e.concat(r.serialize());function o(a){return a.type==="ordgroup"||a.type==="supsub"||a.head.type===0?!0:!!(a.head.type===1&&/\d+(\.\d+)?/.test(a.head.value)&&a.head.value.length>1)}return n&&(e.push(new l(7,"_")),o(n)?(e.push(new l(1,"{")),e=e.concat(n.serialize()),e.push(new l(1,"}"))):e=e.concat(n.serialize())),t&&(e.push(new l(7,"^")),o(t)?(e.push(new l(1,"{")),e=e.concat(t.serialize()),e.push(new l(1,"}"))):e=e.concat(t.serialize())),e}},w=class extends v{args;data;constructor(e,r,t=null){super("funcCall",e),this.args=r,this.data=t}serialize(){let e=[];e.push(this.head),this.head.value==="\\sqrt"&&this.data&&(e.push(new l(1,"[")),e=e.concat(this.data.serialize()),e.push(new l(1,"]")));for(let r of this.args)e.push(new l(1,"{")),e=e.concat(r.serialize()),e.push(new l(1,"}"));return e}},A=class extends v{body;left;right;constructor(e){super("leftright",l.EMPTY),this.body=e.body,this.left=e.left,this.right=e.right}serialize(){let e=[];return e.push(new l(2,"\\left")),e.push(new l(1,this.left?this.left.value:".")),e=e.concat(this.body.serialize()),e.push(new l(2,"\\right")),e.push(new l(1,this.right?this.right.value:".")),e}},M=class extends v{matrix;data;constructor(e,r,t=null){T(e.type===3),super("beginend",e),this.matrix=r,this.data=t}serialize(){let e=[],r=this.matrix;e.push(new l(2,"\\begin")),e.push(new l(1,"{")),e=e.concat(this.head),e.push(new l(1,"}")),e.push(new l(6,`
|
|
2
|
+
`));for(let t=0;t<r.length;t++){let n=r[t];for(let o=0;o<n.length;o++){let a=n[o];e=e.concat(a.serialize()),o!==n.length-1&&e.push(new l(7,"&"))}t!==r.length-1&&e.push(new l(7,"\\\\"))}return e.push(new l(6,`
|
|
3
|
+
`)),e.push(new l(2,"\\end")),e.push(new l(1,"{")),e=e.concat(this.head),e.push(new l(1,"}")),e}};function le(s,e){let r=e.toString(),t=!1;return e.type===5?t=!0:(t||=/[{\(\[\|]$/.test(s),t||=/\\\w+$/.test(s)&&r==="[",t||=/^[\.,;:!\?\(\)\]{}_^]$/.test(r),t||=["\\{","\\}"].includes(r),t||=r==="'",t||=s.endsWith("_")||s.endsWith("^"),t||=/\s$/.test(s),t||=/^\s/.test(r),t||=s==="",t||=/[\(\[{]\s*(-|\+)$/.test(s)||s==="-"||s==="+",t||=s.endsWith("&")&&r==="=",t||=/\d$/.test(s)&&/^[a-zA-Z]$/.test(r)),t||(s+=" "),s+r}function ue(s,e,r=0){let t=s.slice(r).findIndex(n=>n.eq(e));return t===-1?-1:t+r}function K(s,e){return s.some(r=>r.eq(e))}function R(s,e){let r=[],t=[];for(let n of s)n.eq(e)?(r.push(t),t=[]):t.push(n);return r.push(t),r}function ve(s,e){return s.flatMap((r,t)=>t!==s.length-1?[...r,e]:r)}function Me(s,e){return s.flatMap((r,t)=>t!==s.length-1?[r,e]:[r])}var Le={};function Xe(s,e){let r=s.reMatchArray[0].length,t=e.reMatchArray[0].length;return t!==r?t-r:s.index-e.index}var pe=class{_input;_lexer;_pos=0;_line=0;_col=0;_offset=0;_less=null;_go=!1;_newstate=null;_state;_text=null;_leng=null;_reMatchArray=null;constructor(e,r){this._input=e,this._lexer=r,this._state=r.states[0]}text(){return this._text}leng(){return this._leng}reMatchArray(){return this._reMatchArray}pos(){return this._pos}line(){return this._line}column(){return this._col}input(){return this._input.charAt(this._pos+this._leng+this._offset++)}unput(){return this._offset=this._offset>0?this._offset--:0}less(e){return this._less=e,this._offset=0,this._text=this._text.substring(0,e),this._leng=this._text.length}pushback(e){return this.less(this._leng-e)}reject(){this._go=!0}begin(e){if(this._lexer.specification[e])return this._newstate=e;let r=this._lexer.states[parseInt(e)];if(r)return this._newstate=r;throw"Unknown state '"+e+"' requested"}state(){return this._state}scan(){if(this._pos>=this._input.length)return Le;let e=this._input.substring(this._pos),r=this._lexer.specification[this._state],t=[];for(let c=0;c<r.length;c++){let h=r[c],d=e.match(h.re);d!==null&&d[0].length>0&&t.push({index:c,rule:h,reMatchArray:d})}if(t.length===0)throw new Error("No match found for input '"+e+"'");t.sort(Xe),this._go=!0;let n,o;for(let c=0,h=t.length;c<h&&this._go;c++){this._offset=0,this._less=null,this._go=!1,this._newstate=null;let d=t[c];if(o=d.reMatchArray[0],this._text=o,this._leng=o.length,this._reMatchArray=d.reMatchArray,n=d.rule.action(this),this._newstate&&this._newstate!=this._state){this._state=this._newstate;break}}let a=this._less===null?o:o.substring(0,this._less),u=a.length;this._pos+=u+this._offset;let p=a.match(/\n/g);return p!==null?(this._line+=p.length,this._col=u-a.lastIndexOf(`
|
|
4
|
+
`)-1):this._col+=u,n}},D=class{states;specification;constructor(e){this.states=Object.keys(e),this.specification={};for(let r of this.states){let t=e[r];if(r in this.specification)throw"Duplicate state declaration encountered for state '"+r+"'";this.specification[r]=[];for(let[n,o]of t.entries()){let a;try{a=new RegExp("^"+n)}catch(u){throw"Invalid regexp '"+n+"' in state '"+r+"' ("+u.message+")"}this.specification[r].push({re:a,action:o})}}}scanner(e){return new pe(e,this)}lex(e,r){let t=this.scanner(e);for(;;){let n=t.scan();if(n===Le)return;n!==void 0&&r(n)}}collect(e){let r=[],t=function(n){Array.isArray(n)?r.push(...n):r.push(n)};return this.lex(e,t),r}};var W=["sqrt","text","bar","bold","boldsymbol","ddot","dot","hat","mathbb","mathbf","mathcal","mathfrak","mathit","mathrm","mathscr","mathsf","mathtt","operatorname","operatorname*","overbrace","overline","pmb","rm","tilde","underbrace","underline","vec","widehat","widetilde","overleftarrow","overrightarrow","hspace","substack","set","displaylines","mathinner","mathrel","mathbin","mathop","not"],H=["frac","tfrac","binom","dbinom","dfrac","tbinom","overset","underset","textcolor"];function je(s){let e=["{","}","\\","$","&","#","_","%"];for(let r of e)s=s.replaceAll("\\"+r,r);return s}var Ve=new Map([[String.raw`\\begin{(array|subarry)}{(.+?)}`,s=>{let e=s.reMatchArray();return[new l(2,"\\begin"),new l(7,"{"),new l(3,e[1]),new l(7,"}"),new l(7,"{"),new l(3,e[2]),new l(7,"}")]}],[String.raw`\\(text|operatorname\*?|textcolor|begin|end|hspace|array){(.+?)}`,s=>{let e=s.reMatchArray();return[new l(2,"\\"+e[1]),new l(7,"{"),new l(3,je(e[2])),new l(7,"}")]}],[String.raw`%[^\n]*`,s=>new l(4,s.text().substring(1))],[String.raw`[{}_^&]`,s=>new l(7,s.text())],[String.raw`\\[\\,:;!> ]`,s=>new l(7,s.text())],[String.raw`~`,s=>new l(7,s.text())],[String.raw`\r?\n`,s=>new l(6,`
|
|
5
|
+
`)],[String.raw`\s+`,s=>new l(5,s.text())],[String.raw`\\[{}%$&#_|]`,s=>new l(1,s.text())],[String.raw`(\\[a-zA-Z]+)(\s*\d|\s+[a-zA-Z])\s*([0-9a-zA-Z])`,s=>{let e=s.reMatchArray(),r=e[1];if(H.includes(r.substring(1))){let t=e[2].trimStart(),n=e[3];return[new l(2,r),new l(1,t),new l(1,n)]}else return s.reject(),[]}],[String.raw`(\\[a-zA-Z]+)(\s*\d|\s+[a-zA-Z])`,s=>{let e=s.reMatchArray(),r=e[1];if(W.includes(r.substring(1))){let t=e[2].trimStart();return[new l(2,r),new l(1,t)]}else return s.reject(),[]}],[String.raw`\\[a-zA-Z]+`,s=>new l(2,s.text())],[String.raw`[0-9]+(\.[0-9]+)?`,s=>new l(1,s.text())],[String.raw`[a-zA-Z]`,s=>new l(1,s.text())],[String.raw`[+\-*/='<>!.,;:?()\[\]|]`,s=>new l(1,s.text())],[String.raw`[^\x00-\x7F]`,s=>new l(1,s.text())],[String.raw`.`,s=>new l(8,s.text())]]),Ke={start:Ve};function ce(s){return new D(Ke).collect(s)}var Ze=["bigl","bigr","bigm","biggl","biggr","biggm","Bigl","Bigr","Bigm","Biggl","Biggr","Biggm"],he=l.EMPTY.toNode();function Qe(s){return W.includes(s)?1:H.includes(s)?2:0}var Z=new l(7,"{"),F=new l(7,"}"),Je=new l(1,"["),et=new l(1,"]");function Q(s,e){let r=e;for(;r<s.length&&[5,6].includes(s[r].type);)r++;return s.slice(e,r)}function _e(s,e){let r=s[e];return r.type===1&&["(",")","[","]","|","\\{","\\}",".","\\|"].includes(r.value)||r.type===2&&["lfloor","rfloor","lceil","rceil","langle","rangle","lparen","rparen","lbrace","rbrace"].includes(r.value.slice(1))?r:null}function $(s,e){let r=e;for(;r<s.length&&s[r].eq(new l(1,"'"));)r+=1;return r-e}var Oe=new l(2,"\\left"),Se=new l(2,"\\right"),Ae=new l(2,"\\begin"),Ce=new l(2,"\\end"),tt=new l(7,"\\\\"),g=class s extends Error{constructor(e){super(e),this.name="LatexParserError"}static UNMATCHED_LEFT_BRACE=new s("Unmatched '\\{'");static UNMATCHED_RIGHT_BRACE=new s("Unmatched '\\}'");static UNMATCHED_LEFT_BRACKET=new s("Unmatched '\\['");static UNMATCHED_RIGHT_BRACKET=new s("Unmatched '\\]'");static UNMATCHED_COMMAND_BEGIN=new s("Unmatched '\\begin'");static UNMATCHED_COMMAND_END=new s("Unmatched '\\end'");static UNMATCHED_COMMAND_LEFT=new s("Unmatched '\\left'");static UNMATCHED_COMMAND_RIGHT=new s("Unmatched '\\right'")},de=new l(7,"_"),Te=new l(7,"^"),ge=class{space_sensitive;newline_sensitive;alignmentDepth=0;constructor(e=!1,r=!0){this.space_sensitive=e,this.newline_sensitive=r}parse(e){return this.parseGroup(e.slice(0))}parseGroup(e){let[r,t]=this.parseClosure(e,0,null);return r}parseClosure(e,r,t){let n=[],o=r;for(;o<e.length&&!(t!==null&&e[o].eq(t));){let[p,c]=this.parseNextExpr(e,o);o=c,!((p.head.type===5||p.head.type===6)&&(!this.space_sensitive&&p.head.value.replace(/ /g,"").length===0||!this.newline_sensitive&&p.head.value===`
|
|
6
|
+
`))&&n.push(p)}if(o>=e.length&&t!==null)return[he,-1];let a=this.applyStyleCommands(n),u;return a.length===1?u=a[0]:u=new f(a),[u,o+1]}parseNextExpr(e,r){let[t,n]=this.parseNextExprWithoutSupSub(e,r),o=null,a=null,u=0;if(u+=$(e,n),n+=u,n<e.length){let p=e[n];if(p.eq(de)){[o,n]=this.parseNextExprWithoutSupSub(e,n+1);let c=$(e,n);if(u+=c,n+=c,n<e.length&&e[n].eq(Te)&&([a,n]=this.parseNextExprWithoutSupSub(e,n+1),$(e,n)>0))throw new g("Double superscript")}else if(p.eq(Te)){if([a,n]=this.parseNextExprWithoutSupSub(e,n+1),$(e,n)>0)throw new g("Double superscript");if(n<e.length&&e[n].eq(de)&&([o,n]=this.parseNextExprWithoutSupSub(e,n+1),$(e,n)>0))throw new g("Double superscript")}}if(o!==null||a!==null||u>0){let p={base:t,sup:null,sub:null};if(o&&(p.sub=o),u>0){let c=[];for(let h=0;h<u;h++)c.push(new l(1,"'").toNode());a&&c.push(a),p.sup=c.length===1?c[0]:new f(c)}else a&&(p.sup=a);return[new S(p),n]}else return[t,n]}parseNextExprWithoutSupSub(e,r){if(r>=e.length)throw new g("Unexpected end of input");let t=e[r];switch(t.type){case 1:case 3:case 4:case 5:case 6:return[t.toNode(),r+1];case 2:let n=t.value.slice(1);if(Ze.includes(n))return this.parseNextExprWithoutSupSub(e,r+1);if(t.eq(Ae))return this.parseBeginEndExpr(e,r);if(t.eq(Ce))throw g.UNMATCHED_COMMAND_END;if(t.eq(Oe))return this.parseLeftRightExpr(e,r);if(t.eq(Se))throw g.UNMATCHED_COMMAND_RIGHT;return this.parseCommandExpr(e,r);case 7:switch(t.value){case"{":let[a,u]=this.parseClosure(e,r+1,F);if(u===-1)throw g.UNMATCHED_LEFT_BRACE;return[a,u];case"}":throw g.UNMATCHED_RIGHT_BRACE;case"\\\\":case"\\!":case"\\,":case"\\:":case"\\;":case"\\>":return[t.toNode(),r+1];case"\\ ":case"~":return[t.toNode(),r+1];case"_":case"^":return[he,r];case"&":if(this.alignmentDepth<=0)throw new g("Unexpected & outside of an alignment");return[t.toNode(),r+1];default:throw new g("Unknown control sequence")}default:throw new g("Unknown token type")}}parseCommandExpr(e,r){T(e[r].type===2);let t=e[r],n=t.value,o=r+1;switch(Qe(n.slice(1))){case 0:return[t.toNode(),o];case 1:{if(o>=e.length)throw new g("Expecting argument for "+n);if(n==="\\sqrt"&&o<e.length&&e[o].eq(Je)){let[c,h]=this.parseClosure(e,o+1,et);if(h===-1)throw g.UNMATCHED_LEFT_BRACKET;let[d,k]=this.parseNextArg(e,h);return[new w(t,[d],c),k]}else if(n==="\\text"){if(o+2>=e.length)throw new g("Expecting content for \\text command");T(e[o].eq(Z)),T(e[o+1].type===3),T(e[o+2].eq(F));let c=e[o+1];return[new _(c),o+3]}else if(n==="\\displaylines"){T(e[o].eq(Z));let[c,h]=this.parseAligned(e,o+1,F);if(h===-1)throw g.UNMATCHED_LEFT_BRACE;let d=new f(ve(c,tt.toNode()));return[new w(t,[d]),h]}let[u,p]=this.parseNextArg(e,o);return[new w(t,[u]),p]}case 2:{let[u,p]=this.parseNextArg(e,o),[c,h]=this.parseNextArg(e,p);return[new w(t,[u,c]),h]}default:throw new Error("Invalid number of parameters")}}parseNextArg(e,r){let t=r,n=null;for(;t<e.length;){let o;if([o,t]=this.parseNextExprWithoutSupSub(e,t),!(o.head.type===5||o.head.type===6)){n=o;break}}if(n===null)throw new g("Expecting argument but token stream ended");return[n,t]}parseLeftRightExpr(e,r){T(e[r].eq(Oe));let t=r+1;if(t+=Q(e,t).length,t>=e.length)throw new g("Expecting a delimiter after \\left");let n=_e(e,t);if(n===null)throw new g("Invalid delimiter after \\left");t++;let[o,a]=this.parseClosure(e,t,Se);if(a===-1)throw g.UNMATCHED_COMMAND_LEFT;if(t=a,t+=Q(e,t).length,t>=e.length)throw new g("Expecting a delimiter after \\right");let u=_e(e,t);if(u===null)throw new g("Invalid delimiter after \\right");t++;let p=n.value==="."?null:n,c=u.value==="."?null:u;return[new A({body:o,left:p,right:c}),t]}parseBeginEndExpr(e,r){T(e[r].eq(Ae));let t=r+1;T(e[t].eq(Z)),T(e[t+1].type===3),T(e[t+2].eq(F));let n=e[t+1].value;t+=3;let o=null;["array","subarray"].includes(n)&&(t+=Q(e,t).length,[o,t]=this.parseNextArg(e,t));let[a,u]=this.parseAligned(e,t,Ce);if(u===-1)throw g.UNMATCHED_COMMAND_BEGIN;if(t=u,T(e[t].eq(Z)),T(e[t+1].type===3),T(e[t+2].eq(F)),e[t+1].value!==n)throw new g("\\begin and \\end environments mismatch");return t+=3,[new M(new l(3,n),a,o),t]}parseAligned(e,r,t){this.alignmentDepth++;let n=r;n+=Q(e,n).length;let o;if([o,n]=this.parseClosure(e,n,t),n===-1)return[[],-1];let a;if(o.type==="ordgroup"){let u=o.items;for(;u.length>0&&[5,6].includes(u[u.length-1].head.type);)u.pop();a=R(u,new l(7,"\\\\").toNode()).map(p=>R(p,new l(7,"&").toNode()).map(c=>new f(c)))}else a=[[o]];return this.alignmentDepth--,[a,n]}applyStyleCommands(e){for(let r=0;r<e.length;r++){let t=this.getStyleToken(e[r]);if(t){let n=this.applyStyleCommands(e.slice(0,r)),o=this.applyStyleCommands(e.slice(r+1)),a;o.length===0?a=he:o.length===1?a=o[0]:a=new f(o);let u=new w(t,[a]);return n.concat(u)}}return e}getStyleToken(e){return e.type==="terminal"&&(e.head.eq(l.COMMAND_DISPLAYSTYLE)||e.head.eq(l.COMMAND_TEXTSTYLE))?e.head:null}};function rt(s){let e=t=>t.eq(de)||t.eq(Te),r=[];for(let t=0;t<s.length;t++)s[t].type===5&&t+1<s.length&&e(s[t+1])||s[t].type===5&&t-1>=0&&e(s[t-1])||r.push(s[t]);return r}function nt(s,e){let r=[];for(let t of s)if(t.type===2&&e[t.value]){let n=ce(e[t.value]);r=r.concat(n)}else r.push(t);return r}function Re(s,e={}){let r=new ge,t=ce(s);return t=rt(t),t=nt(t,e),r.parse(t)}var G=new Map([["arrow.l.r.double.long","<==>"],["arrow.l.r.long","<-->"],["arrow.r.bar","|->"],["arrow.r.double.bar","|=>"],["arrow.r.double.long","==>"],["arrow.r.long","-->"],["arrow.r.long.squiggly","~~>"],["arrow.r.tail",">->"],["arrow.r.twohead","->>"],["arrow.l.double.long","<=="],["arrow.l.long","<--"],["arrow.l.long.squiggly","<~~"],["arrow.l.tail","<-<"],["arrow.l.twohead","<<-"],["arrow.l.r.double","<=>"],["colon.double.eq","::="],["dots.h","..."],["gt.triple",">>>"],["lt.triple","<<<"],["arrow.r","->"],["arrow.r.double","=>"],["arrow.r.squiggly","~>"],["arrow.l","<-"],["arrow.l.squiggly","<~"],["bar.v.double","||"],["bracket.l.stroked","[|"],["bracket.r.stroked","|]"],["colon.eq",":="],["eq.colon","=:"],["eq.not","!="],["gt.double",">>"],["gt.eq",">="],["lt.double","<<"],["lt.eq","<="],["ast.op","*"],["minus","-"],["tilde.op","~"],["arrow.l.r","<->"]]),J=new Map;for(let[s,e]of G.entries())e.length>1&&J.set(e,s);var i=class s{type;value;constructor(e,r){this.type=e,this.value=r}eq(e){return this.type===e.type&&this.value===e.value}isOneOf(e){return K(e,this)}toNode(){return new X(this)}toString(){switch(this.type){case 4:return`"${this.value}"`;case 5:return`//${this.value}`;default:return this.value}}static NONE=new s(0,"#none");static EMPTY=new s(2,"");static LEFT_BRACE=new s(2,"{");static RIGHT_BRACE=new s(2,"}");static PLUS=new s(2,"+");static MINUS=new s(2,"-");static LEFT_DELIMITERS=[new s(2,"("),new s(2,"["),new s(2,"{"),new s(2,"|"),new s(1,"chevron.l"),new s(1,"paren.l"),new s(1,"brace.l")];static RIGHT_DELIMITERS=[new s(2,")"),new s(2,"]"),new s(2,"}"),new s(2,"|"),new s(1,"chevron.r"),new s(1,"paren.r"),new s(1,"brace.r")]},we=class extends Error{node;constructor(e,r){super(e),this.name="TypstWriterError",this.node=r}},N=new i(7," "),x=class{type;head;options;constructor(e,r){this.type=e,this.head=r||i.NONE}setOptions(e){this.options=e}eq(e){return this.type===e.type&&this.head.eq(e.head)}toString(){throw new Error("Unimplemented toString() in base class TypstNode")}},X=class extends x{constructor(e){super("terminal",e)}isOverHigh(){return!1}isLeftSpaceful(){switch(this.head.type){case 6:case 8:return!1;case 4:return!0;case 1:case 2:return!["(","!","}","]"].includes(this.head.value);default:return!0}}isRightSpaceful(){switch(this.head.type){case 6:case 8:return!1;case 4:return!0;case 1:case 2:return["+","=",",","\\/","dot","dot.op","arrow","arrow.r"].includes(this.head.value);default:return!1}}toString(){return this.head.toString()}serialize(e,r){if(this.head.type===2){if(this.head.value===","&&e.insideFunctionDepth>0)return[new i(1,"comma")]}else if(this.head.type===1){let t=this.head.value;return r.preferShorthands&&G.has(t)&&(t=G.get(t)),r.inftyToOo&&t==="infinity"&&(t="oo"),[new i(1,t)]}else if(this.head.type===6||this.head.type===8){let t=[];for(let n of this.head.value)if(n===" ")r.keepSpaces&&t.push(new i(6,n));else if(n===`
|
|
7
|
+
`)t.push(new i(1,n));else throw new we(`Unexpected whitespace character: ${n}`,this);return t}return[this.head]}},L=class extends x{items;constructor(e){super("group",i.NONE),this.items=e}isOverHigh(){return this.items.some(e=>e.isOverHigh())}isLeftSpaceful(){return this.items.length===0?!1:this.items[0].isLeftSpaceful()}isRightSpaceful(){return this.items.length===0?!1:this.items.at(-1).isRightSpaceful()}serialize(e,r){if(this.items.length===0)return[];let t=[];for(let n=0;n<this.items.length;n++){let o=this.items[n],a=o.serialize(e,r);if(o.isLeftSpaceful()&&n>0&&t.length>0){let u=t.at(-1),p=!1;p||=u.eq(N),p||=["{","["].includes(u.value),p||t.push(N)}t.push(...a),o.isRightSpaceful()&&n<this.items.length-1&&(t.at(-1)?.eq(N)||t.push(N))}if(t.length>0&&(t[0].eq(i.MINUS)||t[0].eq(i.PLUS)))for(;t.length>1&&t[1].eq(N);)t.splice(1,1);return t}},O=class extends x{base;sup;sub;constructor(e){super("supsub",i.NONE),this.base=e.base,this.sup=e.sup,this.sub=e.sub}isOverHigh(){return this.base.isOverHigh()}isLeftSpaceful(){return!0}isRightSpaceful(){return!0}serialize(e,r){let t=[],{base:n,sup:o,sub:a}=this;t.push(...n.serialize(e,r));let u=o&&o.head.eq(new i(2,"'"));return u&&t.push(new i(2,"'")),a&&(t.push(new i(2,"_")),t.push(...a.serialize(e,r))),o&&!u&&(t.push(new i(2,"^")),t.push(...o.serialize(e,r))),t}},m=class extends x{args;constructor(e,r){super("funcCall",e),this.args=r}isOverHigh(){return this.head.value==="frac"?!0:this.args.some(e=>e.isOverHigh())}isLeftSpaceful(){return!0}isRightSpaceful(){return!["op","bold","dot"].includes(this.head.value)}serialize(e,r){let t=[],n=this.head;t.push(n),e.insideFunctionDepth++,t.push(ee);for(let o=0;o<this.args.length;o++)t.push(...this.args[o].serialize(e,r)),o<this.args.length-1&&(t.push(new i(2,",")),t.push(N));if(this.options)for(let[o,a]of Object.entries(this.options))t.push(new i(3,`, ${o}: ${a.toString()}`));return t.push(te),e.insideFunctionDepth--,t}},I=class extends x{args;constructor(e){super("fraction",i.NONE),this.args=e}isOverHigh(){return!0}isLeftSpaceful(){return!0}isRightSpaceful(){return!0}serialize(e,r){let t=[],[n,o]=this.args;return t.push(...n.serialize(e,r)),t.push(new i(2,"/")),t.push(...o.serialize(e,r)),t}},ee=new i(2,"("),te=new i(2,")"),q=class extends x{body;left;right;constructor(e,r){super("leftright",e),this.body=r.body,this.left=r.left,this.right=r.right}isOverHigh(){return this.body.isOverHigh()}isLeftSpaceful(){return!0}isRightSpaceful(){return!0}serialize(e,r){let t=[],n=new i(1,"lr"),{left:o,right:a}=this;return this.head.eq(n)&&(t.push(n),t.push(ee)),o&&(t.push(o),U(o.value[0])&&t.push(N)),t.push(...this.body.serialize(e,r)),a&&(U(a.value[0])&&t.push(N),t.push(a)),this.head.eq(n)&&t.push(te),t}},y=class s extends x{matrix;constructor(e,r){super("matrixLike",e),this.matrix=r}isOverHigh(){return!0}isLeftSpaceful(){return!0}isRightSpaceful(){return!1}serialize(e,r){let t=[],n,o;if(this.head.eq(s.MAT)?(n=new i(2,","),o=new i(2,";")):this.head.eq(s.CASES)?(n=new i(2,"&"),o=new i(2,",")):this.head.eq(i.NONE)&&(n=new i(2,"&"),o=new i(1,"\\")),!this.head.eq(i.NONE)&&(t.push(this.head),e.insideFunctionDepth++,t.push(ee),this.options))for(let[a,u]of Object.entries(this.options))t.push(new i(3,`${a}: ${u.toString()}, `));return this.matrix.forEach((a,u)=>{a.forEach((p,c)=>{t.push(...p.serialize(e,r)),c<a.length-1?(t.push(N),t.push(n),t.push(N)):u<this.matrix.length-1&&(o.value==="\\"&&t.push(N),t.push(o),t.push(N))})}),this.head.eq(i.NONE)||(t.push(te),e.insideFunctionDepth--),t}static MAT=new i(1,"mat");static CASES=new i(1,"cases")},B=class extends x{fragments;constructor(e,r){super("markupFunc",e),this.fragments=r}isOverHigh(){return this.fragments.some(e=>e.isOverHigh())}isLeftSpaceful(){return!0}isRightSpaceful(){return!0}serialize(e,r){let t=[];if(t.push(this.head),e.insideFunctionDepth++,t.push(ee),this.options){let n=Object.entries(this.options);for(let o=0;o<n.length;o++){let[a,u]=n[o];t.push(new i(3,`${a}: ${u.toString()}`)),o<n.length-1&&t.push(new i(2,","))}}t.push(te),t.push(new i(3,"["));for(let n of this.fragments)t.push(new i(3,"$")),t.push(...n.serialize(e,r)),t.push(new i(3,"$"));return t.push(new i(3,"]")),t}};var st=new i(2,"("),ot=new i(2,")"),at=new i(2,","),De=new i(1,`
|
|
8
|
+
`),be=new i(7," ");var re=class{buffer="";queue=[];options;constructor(e){this.options=e}serialize(e){let r={insideFunctionDepth:0};this.queue.push(...e.serialize(r,this.options))}flushQueue(){let e=this.queue.filter(n=>n.value!==""),r=[];for(let n of e)n.eq(be)&&r.length>0&&r[r.length-1].eq(be)||r.push(n);let t=new i(1,"");for(let n=0;n<r.length;n++)r[n].eq(be)&&(n===0||n===r.length-1||r[n-1].type===6||r[n-1].isOneOf([st,De])||r[n+1].isOneOf([ot,at,De]))&&(r[n]=t);r=r.filter(n=>!n.eq(t));for(let n=0;n<r.length;n++){let o=r[n];this.buffer+=o.toString()}this.queue=[]}finalize(){this.flushQueue();let e=function(n){let o=n.replace(/floor\.l\s*(.*?)\s*floor\.r/g,"floor($1)");return o=o.replace(/floor\(\)/g,'floor("")'),o},r=function(n){let o=n.replace(/ceil\.l\s*(.*?)\s*ceil\.r/g,"ceil($1)");return o=o.replace(/ceil\(\)/g,'ceil("")'),o},t=function(n){let o=n.replace(/floor\.l\s*(.*?)\s*ceil\.r/g,"round($1)");return o=o.replace(/round\(\)/g,'round("")'),o};if(this.options.optimize){let n=[e,r,t];for(let o of n)this.buffer=o(this.buffer)}return this.buffer=this.buffer.replace(/& =/g,"&="),this.buffer}};var E=new Map([["displaystyle","display"],["textstyle","inline"],["hspace","#h"],["|","bar.v.double"],[",","thin"],[":","med"],[" ","med"],[";","thick"],[">","med"],["~","space.nobreak"],["blacktriangleleft","triangle.filled.l"],["blacktriangleright","triangle.filled.r"],["clubsuit","suit.club.filled"],["hookleftarrow","arrow.l.hook"],["hookrightarrow","arrow.r.hook"],["leftrightarrow","arrow.l.r"],["lgblksquare","square.filled.big"],["lgwhtsquare","square.stroked.big"],["nearrow","arrow.tr"],["nwarrow","arrow.tl"],["searrow","arrow.br"],["swarrow","arrow.bl"],["spadesuit","suit.spade.filled"],["updownarrow","arrow.t.b"],["ln","ln"],["log","log"],["cos","cos"],["sin","sin"],["tan","tan"],["cot","cot"],["sec","sec"],["csc","csc"],["mod","mod"],["omicron","omicron"],["Xi","Xi"],["Upsilon","Upsilon"],["lim","lim"],["binom","binom"],["tilde","tilde"],["hat","hat"],["sqrt","sqrt"],["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"],["operatorname*","op"],["boldsymbol","bold"],["mathbb","bb"],["mathbf","bold"],["mathcal","cal"],["mathscr","scr"],["mathit","italic"],["mathfrak","frak"],["mathrm","upright"],["mathsf","sans"],["mathtt","mono"],["rm","upright"],["pmb","bold"],["leadsto","arrow.r.squiggly"],["P","pilcrow"],["S","section"],["aleph","alef"],["infin","infinity"],["Delta","Delta"],["Gamma","Gamma"],["Lambda","Lambda"],["Omega","Omega"],["Phi","Phi"],["Pi","Pi"],["Psi","Psi"],["Sigma","Sigma"],["Theta","Theta"],["alpha","alpha"],["beta","beta"],["bigcirc","circle.big"],["bullet","bullet"],["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"],["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"],["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","chevron.l"],["lbrace","brace.l"],["lbrack","bracket.l"],["ldots","dots.h"],["le","lt.eq"],["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"],["odot","dot.circle"],["oint","integral.cont"],["oiint","integral.surf"],["oiiint","integral.vol"],["omega","omega"],["ominus","minus.circle"],["otimes","times.circle"],["parallel","parallel"],["partial","partial"],["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","chevron.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"],["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"],["tau","tau"],["theta","theta"],["times","times"],["to","arrow.r"],["top","top"],["triangle","triangle.t"],["twoheadrightarrow","arrow.r.twohead"],["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"],["intop","limits(integral)"],["LaTeX","#LaTeX"],["TeX","#TeX"]]),it=new Map([["acwopencirclearrow","arrow.ccw"],["adots","dots.up"],["angdnr","angle.acute"],["angle","angle"],["angles","angle.s"],["approx","approx"],["approxeq","approx.eq"],["approxident","tilde.triple"],["assert","tack.r.short"],["ast","ast.op"],["astrosun","sun"],["asymp","asymp"],["awint","integral.ccw"],["backcong","tilde.rev.equiv"],["backdprime","prime.double.rev"],["backprime","prime.rev"],["backsim","tilde.rev"],["backsimeq","tilde.eq.rev"],["backslash","backslash"],["backtrprime","prime.triple.rev"],["bardownharpoonleft","harpoon.bl.bar"],["bardownharpoonright","harpoon.br.bar"],["barleftarrow","arrow.l.stop"],["barleftarrowrightarrowbar","arrows.lr.stop"],["barleftharpoondown","harpoon.lb.stop"],["barleftharpoonup","harpoon.lt.stop"],["barrightharpoondown","harpoon.rb.bar"],["barrightharpoonup","harpoon.rt.bar"],["baruparrow","arrow.t.stop"],["barupharpoonleft","harpoon.tl.stop"],["barupharpoonright","harpoon.tr.stop"],["barV","tack.b.double"],["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"],["because","because"],["bigblacktriangledown","triangle.filled.b"],["bigblacktriangleup","triangle.filled.t"],["bigbot","tack.t.big"],["bigcap","inter.big"],["bigcup","union.big"],["bigcupdot","union.dot.big"],["biginterleave","interleave.big"],["bigodot","dot.o.big"],["bigoplus","plus.o.big"],["bigotimes","times.o.big"],["bigsqcap","inter.sq.big"],["bigsqcup","union.sq.big"],["bigstar","star.filled"],["bigtimes","times.big"],["bigtop","tack.b.big"],["bigtriangledown","triangle.stroked.b"],["bigtriangleup","triangle.stroked.t"],["biguplus","union.plus.big"],["bigvee","or.big"],["bigwedge","and.big"],["bigwhitestar","star.stroked"],["blackhourglass","hourglass.filled"],["blacktriangle","triangle.filled.small.t"],["blacktriangledown","triangle.filled.small.b"],["blkhorzoval","ellipse.filled.h"],["blkvertoval","ellipse.filled.v"],["bot","bot"],["boxast","ast.square"],["boxdot","dot.square"],["boxminus","minus.square"],["boxplus","plus.square"],["boxtimes","times.square"],["cap","inter"],["Cap","inter.double"],["capdot","inter.dot"],["capwedge","inter.and"],["caretinsert","caret"],["cdot","dot.op"],["cdotp","dot.c"],["checkmark","checkmark"],["circledast","ast.op.o"],["circledbullet","bullet.o"],["circledcirc","compose.o"],["circleddash","dash.o"],["circledequal","cc.nd"],["circledparallel","parallel.o"],["circledvert","bar.v.o"],["circledwhitebullet","bullet.stroked.o"],["Colon","colon.double"],["coloneq","colon.eq"],["Coloneq","colon.double.eq"],["complement","complement"],["cong","tilde.equiv"],["coprod","product.co"],["cup","union"],["Cup","union.double"],["cupdot","union.dot"],["cupleftarrow","union.arrow"],["cupvee","union.or"],["curlyeqprec","eq.prec"],["curlyeqsucc","eq.succ"],["curlyvee","or.curly"],["curlywedge","and.curly"],["curvearrowleft","arrow.ccw.half"],["curvearrowright","arrow.cw.half"],["cwopencirclearrow","arrow.cw"],["dagger","dagger"],["dashcolon","dash.colon"],["dashv","tack.l"],["Dashv","tack.l.double"],["dashVdash","tack.l.r"],["ddagger","dagger.double"],["ddddot","dot.quad"],["dddot","dot.triple"],["ddots","dots.down"],["DDownarrow","arrow.b.quad"],["Ddownarrow","arrow.b.triple"],["diameter","diameter"],["diamondcdot","diamond.stroked.dot"],["diamondsuit","suit.diamond.stroked"],["dicei","die.one"],["diceii","die.two"],["diceiii","die.three"],["diceiv","die.four"],["dicev","die.five"],["dicevi","die.six"],["div","div"],["divideontimes","times.div"],["Doteq","eq.dots"],["dotminus","minus.dot"],["dotplus","plus.dot"],["dotsim","tilde.dot"],["dottedcircle","circle.dotted"],["dottedsquare","square.stroked.dotted"],["doubleplus","plus.double"],["downarrow","arrow.b"],["Downarrow","arrow.b.double"],["downarrowbar","arrow.b.stop"],["downarrowbarred","arrow.b.struck"],["downdasharrow","arrow.b.dashed"],["downdownarrows","arrows.bb"],["downharpoonleft","harpoon.bl"],["downharpoonleftbar","harpoon.bl.stop"],["downharpoonright","harpoon.br"],["downharpoonrightbar","harpoon.br.stop"],["downharpoonsleftright","harpoons.blbr"],["downuparrows","arrows.bt"],["downupharpoonsleftright","harpoons.bltr"],["downwhitearrow","arrow.b.stroked"],["downzigzagarrow","arrow.zigzag"],["dprime","prime.double"],["dualmap","multimap.double"],["eighthnote","note.eighth.alt"],["ell","ell"],["emptysetoarr","emptyset.arrow.r"],["emptysetoarrl","emptyset.arrow.l"],["emptysetobar","emptyset.bar"],["emptysetocirc","emptyset.circle"],["eparsl","parallel.slanted.eq"],["eqcolon","eq.colon"],["eqdef","eq.def"],["eqgtr","eq.gt"],["eqless","eq.lt"],["eqsim","minus.tilde"],["equal","eq"],["equalparallel","parallel.eq"],["equiv","eq.triple"],["Equiv","eq.quad"],["equivVert","parallel.equiv"],["eqvparsl","parallel.slanted.equiv"],["errbarblackcircle","errorbar.circle.filled"],["errbarblackdiamond","errorbar.diamond.filled"],["errbarblacksquare","errorbar.square.filled"],["errbarcircle","errorbar.circle.stroked"],["errbardiamond","errorbar.diamond.stroked"],["errbarsquare","errorbar.square.stroked"],["euro","euro"],["exists","exists"],["fallingdotseq","eq.dots.down"],["fint","integral.slash"],["flat","flat"],["forall","forall"],["fourvdots","fence.dotted"],["frown","frown"],["fullouterjoin","join.l.r"],["geq","gt.eq"],["geqq","gt.equiv"],["geqslant","gt.eq.slant"],["gg","gt.double"],["ggg","gt.triple"],["gggnest","gt.triple.nested"],["gnapprox","gt.napprox"],["gneq","gt.neq"],["gneqq","gt.nequiv"],["gnsim","gt.ntilde"],["greater","gt"],["gtlpar","angle.spheric.rev"],["gtrapprox","gt.approx"],["gtrdot","gt.dot"],["gtreqless","gt.eq.lt"],["gtrless","gt.lt"],["gtrsim","gt.tilde"],["heartsuit","suit.heart.stroked"],["hknearrow","arrow.tr.hook"],["hknwarrow","arrow.tl.hook"],["hksearrow","arrow.br.hook"],["hkswarrow","arrow.bl.hook"],["horizbar","bar.h"],["hourglass","hourglass.stroked"],["hrectangle","rect.stroked.h"],["hrectangleblack","rect.filled.h"],["hyphenbullet","bullet.hyph"],["iiiint","integral.quad"],["iiint","integral.triple"],["iinfin","infinity.incomplete"],["iint","integral.double"],["Im","Im"],["imageof","image"],["in","in"],["increment","laplace"],["infty","infinity"],["int","integral"],["intbar","integral.dash"],["intBar","integral.dash.double"],["intcap","integral.inter"],["intclockwise","integral.cw"],["intcup","integral.union"],["interleave","interleave"],["intlarhk","integral.arrow.hook"],["intx","integral.times"],["inversebullet","bullet.hole"],["Join","join"],["langle","chevron.l"],["lAngle","chevron.l.double"],["langledot","chevron.l.dot"],["lat","lat"],["late","lat.eq"],["lbag","bag.l"],["lblkbrbrak","shell.l.filled"],["lbrace","brace.l"],["lBrace","brace.l.stroked"],["lbrack","bracket.l"],["lBrack","bracket.l.stroked"],["lbracklltick","bracket.l.tick.b"],["lbrackultick","bracket.l.tick.t"],["lbrbrak","shell.l"],["Lbrbrak","shell.l.stroked"],["lceil","ceil.l"],["lcurvyangle","chevron.l.curly"],["leftarrow","arrow.l"],["Leftarrow","arrow.l.double"],["leftarrowtail","arrow.l.tail"],["leftarrowtriangle","arrow.l.open"],["leftdasharrow","arrow.l.dashed"],["leftdotarrow","arrow.l.dotted"],["leftdowncurvedarrow","arrow.l.curve"],["leftharpoondown","harpoon.lb"],["leftharpoondownbar","harpoon.lb.bar"],["leftharpoonsupdown","harpoons.ltlb"],["leftharpoonup","harpoon.lt"],["leftharpoonupbar","harpoon.lt.bar"],["leftleftarrows","arrows.ll"],["leftouterjoin","join.l"],["Leftrightarrow","arrow.l.r.double"],["leftrightarrows","arrows.lr"],["leftrightarrowtriangle","arrow.l.r.open"],["leftrightharpoondowndown","harpoon.lb.rb"],["leftrightharpoondownup","harpoon.lb.rt"],["leftrightharpoons","harpoons.ltrb"],["leftrightharpoonsdown","harpoons.lbrb"],["leftrightharpoonsup","harpoons.ltrt"],["leftrightharpoonupdown","harpoon.lt.rb"],["leftrightharpoonupup","harpoon.lt.rt"],["leftrightsquigarrow","arrow.l.r.wave"],["leftsquigarrow","arrow.l.squiggly"],["leftthreearrows","arrows.lll"],["leftthreetimes","times.three.l"],["leftwavearrow","arrow.l.wave"],["leftwhitearrow","arrow.l.stroked"],["leq","lt.eq"],["leqq","lt.equiv"],["leqslant","lt.eq.slant"],["less","lt"],["lessapprox","lt.approx"],["lessdot","lt.dot"],["lesseqgtr","lt.eq.gt"],["lessgtr","lt.gt"],["lesssim","lt.tilde"],["lfloor","floor.l"],["lgblkcircle","circle.filled.big"],["lgroup","paren.l.flat"],["lgwhtcircle","circle.stroked.big"],["ll","lt.double"],["llangle","chevron.l.closed"],["llblacktriangle","triangle.filled.bl"],["llcorner","corner.l.b"],["LLeftarrow","arrow.l.quad"],["Lleftarrow","arrow.l.triple"],["lll","lt.triple"],["lllnest","lt.triple.nested"],["llparenthesis","paren.l.closed"],["lltriangle","triangle.stroked.bl"],["lmoustache","mustache.l"],["lnapprox","lt.napprox"],["lneq","lt.neq"],["lneqq","lt.nequiv"],["lnsim","lt.ntilde"],["longdashv","tack.l.long"],["Longleftarrow","arrow.l.double.long"],["longleftarrow","arrow.l.long"],["Longleftrightarrow","arrow.l.r.double.long"],["longleftrightarrow","arrow.l.r.long"],["longleftsquigarrow","arrow.l.long.squiggly"],["Longmapsfrom","arrow.l.double.long.bar"],["longmapsfrom","arrow.l.long.bar"],["longmapsto","arrow.r.long.bar"],["Longmapsto","arrow.r.double.long.bar"],["Longrightarrow","arrow.r.double.long"],["longrightarrow","arrow.r.long"],["longrightsquigarrow","arrow.r.long.squiggly"],["looparrowleft","arrow.l.loop"],["looparrowright","arrow.r.loop"],["lparen","paren.l"],["lParen","paren.l.stroked"],["lrblacktriangle","triangle.filled.br"],["lrcorner","corner.r.b"],["lrtriangle","triangle.stroked.br"],["ltimes","times.l"],["lvzigzag","fence.l"],["Lvzigzag","fence.l.double"],["maltese","maltese"],["mapsdown","arrow.b.bar"],["mapsfrom","arrow.l.bar"],["Mapsfrom","arrow.l.double.bar"],["mapsto","arrow.r.bar"],["Mapsto","arrow.r.double.bar"],["mapsup","arrow.t.bar"],["mathampersand","amp"],["mathatsign","at"],["mathcolon","colon"],["mathcomma","comma"],["mathdollar","dollar"],["mathexclam","excl"],["mathhyphen","hyph"],["mathparagraph","pilcrow"],["mathpercent","percent"],["mathperiod","dot.basic"],["mathplus","plus"],["mathquestion","quest"],["mathratio","ratio"],["mathsection","section"],["mathsemicolon","semi"],["mathslash","slash"],["mathsterling","pound"],["mathyen","yen"],["mdblkdiamond","diamond.filled.medium"],["mdblklozenge","lozenge.filled.medium"],["mdlgblkcircle","circle.filled"],["mdlgblkdiamond","diamond.filled"],["mdlgblklozenge","lozenge.filled"],["mdlgblksquare","square.filled"],["mdlgwhtcircle","circle.stroked"],["mdlgwhtdiamond","diamond.stroked"],["mdlgwhtlozenge","lozenge.stroked"],["mdlgwhtsquare","square.stroked"],["mdsmblkcircle","circle.filled.tiny"],["mdsmwhtcircle","circle.stroked.small"],["mdwhtdiamond","diamond.stroked.medium"],["mdwhtlozenge","lozenge.stroked.medium"],["measeq","eq.m"],["measuredangle","angle.arc"],["measuredangleleft","angle.arc.rev"],["measuredrightangle","angle.right.arc"],["mho","Omega.inv"],["mid","divides"],["minus","minus"],["models","models"],["mp","minus.plus"],["multimap","multimap"],["nabla","gradient"],["napprox","approx.not"],["nasymp","asymp.not"],["natural","natural"],["ncong","tilde.equiv.not"],["ne","eq.not"],["Nearrow","arrow.tr.double"],["neg","not"],["nequiv","equiv.not"],["neswarrow","arrow.tr.bl"],["nexists","exists.not"],["ngeq","gt.eq.not"],["ngtr","gt.not"],["ngtrless","gt.lt.not"],["ngtrsim","gt.tilde.not"],["nHdownarrow","arrow.b.dstruck"],["nhpar","parallel.struck"],["nHuparrow","arrow.t.dstruck"],["nhVvert","interleave.struck"],["ni","in.rev"],["nLeftarrow","arrow.l.double.not"],["nleftarrow","arrow.l.not"],["nLeftrightarrow","arrow.l.r.double.not"],["nleftrightarrow","arrow.l.r.not"],["nleq","lt.eq.not"],["nless","lt.not"],["nlessgtr","lt.gt.not"],["nlesssim","lt.tilde.not"],["nmid","divides.not"],["nni","in.rev.not"],["notin","in.not"],["nparallel","parallel.not"],["nprec","prec.not"],["npreccurlyeq","prec.curly.eq.not"],["nRightarrow","arrow.r.double.not"],["nrightarrow","arrow.r.not"],["nsim","tilde.not"],["nsimeq","tilde.eq.not"],["nsqsubseteq","subset.eq.sq.not"],["nsqsupseteq","supset.eq.sq.not"],["nsubset","subset.not"],["nsubseteq","subset.eq.not"],["nsucc","succ.not"],["nsucccurlyeq","succ.curly.eq.not"],["nsupset","supset.not"],["nsupseteq","supset.eq.not"],["ntrianglelefteq","lt.tri.eq.not"],["ntrianglerighteq","gt.tri.eq.not"],["nvartriangleleft","lt.tri.not"],["nvartriangleright","gt.tri.not"],["nVdash","forces.not"],["nvdash","tack.r.not"],["nvDash","tack.r.double.not"],["nvinfty","infinity.bar"],["nvLeftarrow","arrow.l.double.struck"],["nvleftarrow","arrow.l.struck"],["nVleftarrow","arrow.l.dstruck"],["nvleftarrowtail","arrow.l.tail.struck"],["nVleftarrowtail","arrow.l.tail.dstruck"],["nvLeftrightarrow","arrow.l.r.double.struck"],["nvleftrightarrow","arrow.l.r.struck"],["nVleftrightarrow","arrow.l.r.dstruck"],["nvRightarrow","arrow.r.double.struck"],["nvrightarrow","arrow.r.struck"],["nVrightarrow","arrow.r.dstruck"],["nvrightarrowtail","arrow.r.tail.struck"],["nVrightarrowtail","arrow.r.tail.dstruck"],["nvtwoheadleftarrow","arrow.l.twohead.struck"],["nVtwoheadleftarrow","arrow.l.twohead.dstruck"],["nvtwoheadleftarrowtail","arrow.l.twohead.tail.struck"],["nVtwoheadleftarrowtail","arrow.l.twohead.tail.dstruck"],["nvtwoheadrightarrow","arrow.r.twohead.struck"],["nVtwoheadrightarrow","arrow.r.twohead.dstruck"],["nvtwoheadrightarrowtail","arrow.r.twohead.tail.struck"],["nVtwoheadrightarrowtail","arrow.r.twohead.tail.dstruck"],["Nwarrow","arrow.tl.double"],["nwsearrow","arrow.tl.br"],["obrbrak","shell.t"],["obslash","backslash.o"],["odiv","div.o"],["odot","dot.o"],["odotslashdot","div.slanted.o"],["ogreaterthan","gt.o"],["oiiint","integral.vol"],["oiint","integral.surf"],["oint","integral.cont"],["ointctrclockwise","integral.cont.ccw"],["olessthan","lt.o"],["ominus","minus.o"],["operp","perp.o"],["oplus","plus.o"],["opluslhrim","plus.o.l"],["oplusrhrim","plus.o.r"],["origof","original"],["oslash","slash.o"],["otimes","times.o"],["otimeshat","times.o.hat"],["otimeslhrim","times.o.l"],["otimesrhrim","times.o.r"],["parallel","parallel"],["parallelogram","parallelogram.stroked"],["parallelogramblack","parallelogram.filled"],["parsim","parallel.tilde"],["partial","partial"],["pentagon","penta.stroked"],["pentagonblack","penta.filled"],["perp","perp"],["pm","plus.minus"],["prec","prec"],["Prec","prec.double"],["precapprox","prec.approx"],["preccurlyeq","prec.curly.eq"],["preceq","prec.eq"],["preceqq","prec.equiv"],["precnapprox","prec.napprox"],["precneq","prec.neq"],["precneqq","prec.nequiv"],["precnsim","prec.ntilde"],["precsim","prec.tilde"],["prime","prime"],["prod","product"],["propto","prop"],["QED","qed"],["qprime","prime.quad"],["quarternote","note.quarter.alt"],["questeq","eq.quest"],["Question","quest.double"],["rangle","chevron.r"],["rAngle","chevron.r.double"],["rangledot","chevron.r.dot"],["rangledownzigzagarrow","angle.azimuth"],["rbag","bag.r"],["rblkbrbrak","shell.r.filled"],["rbrace","brace.r"],["rBrace","brace.r.stroked"],["rbrack","bracket.r"],["rBrack","bracket.r.stroked"],["rbracklrtick","bracket.r.tick.b"],["rbrackurtick","bracket.r.tick.t"],["rbrbrak","shell.r"],["Rbrbrak","shell.r.stroked"],["rceil","ceil.r"],["rcurvyangle","chevron.r.curly"],["Re","Re"],["revangle","angle.rev"],["revemptyset","emptyset.rev"],["revnmid","divides.not.rev"],["rfloor","floor.r"],["rgroup","paren.r.flat"],["rightangle","angle.right"],["rightanglemdot","angle.right.dot"],["rightanglesqr","angle.right.square"],["rightarrow","arrow.r"],["Rightarrow","arrow.r.double"],["rightarrowbar","arrow.r.stop"],["rightarrowonoplus","plus.o.arrow"],["rightarrowtail","arrow.r.tail"],["rightarrowtriangle","arrow.r.open"],["rightdasharrow","arrow.r.dashed"],["rightdotarrow","arrow.r.dotted"],["rightdowncurvedarrow","arrow.r.curve"],["rightharpoondown","harpoon.rb"],["rightharpoondownbar","harpoon.rb.stop"],["rightharpoonsupdown","harpoons.rtrb"],["rightharpoonup","harpoon.rt"],["rightharpoonupbar","harpoon.rt.stop"],["rightleftarrows","arrows.rl"],["rightleftharpoons","harpoons.rtlb"],["rightleftharpoonsdown","harpoons.rblb"],["rightleftharpoonsup","harpoons.rtlt"],["rightouterjoin","join.r"],["rightrightarrows","arrows.rr"],["rightsquigarrow","arrow.r.squiggly"],["rightthreearrows","arrows.rrr"],["rightthreetimes","times.three.r"],["rightwavearrow","arrow.r.wave"],["rightwhitearrow","arrow.r.stroked"],["risingdotseq","eq.dots.up"],["rmoustache","mustache.r"],["rparen","paren.r"],["rParen","paren.r.stroked"],["rrangle","chevron.r.closed"],["RRightarrow","arrow.r.quad"],["Rrightarrow","arrow.r.triple"],["rrparenthesis","paren.r.closed"],["rsolbar","backslash.not"],["rtimes","times.r"],["rvzigzag","fence.r"],["Rvzigzag","fence.r.double"],["Searrow","arrow.br.double"],["setminus","without"],["sharp","sharp"],["shortdowntack","tack.b.short"],["shortlefttack","tack.l.short"],["shortuptack","tack.t.short"],["sim","tilde.op"],["sime","tilde.eq"],["similarleftarrow","arrow.l.tilde"],["similarrightarrow","arrow.r.tilde"],["simneqq","tilde.nequiv"],["smallblacktriangleleft","triangle.filled.small.l"],["smallblacktriangleright","triangle.filled.small.r"],["smallin","in.small"],["smallni","in.rev.small"],["smalltriangleleft","triangle.stroked.small.l"],["smalltriangleright","triangle.stroked.small.r"],["smashtimes","smash"],["smblkcircle","bullet"],["smblkdiamond","diamond.filled.small"],["smblklozenge","lozenge.filled.small"],["smeparsl","parallel.slanted.eq.tilde"],["smile","smile"],["smt","smt"],["smte","smt.eq"],["smwhtcircle","bullet.stroked"],["smwhtdiamond","diamond.stroked.small"],["smwhtlozenge","lozenge.stroked.small"],["sphericalangle","angle.spheric"],["sphericalangleup","angle.spheric.t"],["sqcap","inter.sq"],["Sqcap","inter.sq.double"],["sqcup","union.sq"],["Sqcup","union.sq.double"],["sqint","integral.square"],["sqsubset","subset.sq"],["sqsubseteq","subset.eq.sq"],["sqsubsetneq","subset.sq.neq"],["sqsupset","supset.sq"],["sqsupseteq","supset.eq.sq"],["sqsupsetneq","supset.sq.neq"],["squoval","square.stroked.rounded"],["sslash","slash.double"],["star","star.op"],["stareq","eq.star"],["subset","subset"],["Subset","subset.double"],["subsetdot","subset.dot"],["subseteq","subset.eq"],["subsetneq","subset.neq"],["succ","succ"],["Succ","succ.double"],["succapprox","succ.approx"],["succcurlyeq","succ.curly.eq"],["succeq","succ.eq"],["succeqq","succ.equiv"],["succnapprox","succ.napprox"],["succneq","succ.neq"],["succneqq","succ.nequiv"],["succnsim","succ.ntilde"],["succsim","succ.tilde"],["sum","sum"],["sumint","sum.integral"],["supset","supset"],["Supset","supset.double"],["supsetdot","supset.dot"],["supseteq","supset.eq"],["supsetneq","supset.neq"],["Swarrow","arrow.bl.double"],["therefore","therefore"],["threedangle","angle.spatial"],["threedotcolon","colon.tri.op"],["tieinfty","infinity.tie"],["times","times"],["tminus","miny"],["top","tack.b"],["tplus","tiny"],["trianglecdot","triangle.stroked.dot"],["triangledown","triangle.stroked.small.b"],["triangleleft","triangle.stroked.l"],["trianglelefteq","lt.tri.eq"],["triangleminus","minus.triangle"],["triangleplus","plus.triangle"],["triangleq","eq.delta"],["triangleright","triangle.stroked.r"],["trianglerighteq","gt.tri.eq"],["triangletimes","times.triangle"],["tripleplus","plus.triple"],["trprime","prime.triple"],["trslash","slash.triple"],["turnediota","iota.inv"],["twoheaddownarrow","arrow.b.twohead"],["twoheadleftarrow","arrow.l.twohead"],["twoheadleftarrowtail","arrow.l.twohead.tail"],["twoheadmapsfrom","arrow.l.twohead.bar"],["twoheadmapsto","arrow.r.twohead.bar"],["twoheadrightarrow","arrow.r.twohead"],["twoheadrightarrowtail","arrow.r.twohead.tail"],["twoheaduparrow","arrow.t.twohead"],["twonotes","note.eighth.beamed"],["ubrbrak","shell.b"],["ulblacktriangle","triangle.filled.tl"],["ulcorner","corner.l.t"],["ultriangle","triangle.stroked.tl"],["uminus","union.minus"],["underbrace","brace.b"],["underbracket","bracket.b"],["underparen","paren.b"],["unicodecdots","dots.h.c"],["unicodeellipsis","dots.h"],["upand","amp.inv"],["uparrow","arrow.t"],["Uparrow","arrow.t.double"],["uparrowbarred","arrow.t.struck"],["upbackepsilon","epsilon.alt.rev"],["updasharrow","arrow.t.dashed"],["upDigamma","Digamma"],["updigamma","digamma"],["Updownarrow","arrow.t.b.double"],["updownarrows","arrows.tb"],["updownharpoonleftleft","harpoon.tl.bl"],["updownharpoonleftright","harpoon.tl.br"],["updownharpoonrightleft","harpoon.tr.bl"],["updownharpoonrightright","harpoon.tr.br"],["updownharpoonsleftright","harpoons.tlbr"],["upharpoonleft","harpoon.tl"],["upharpoonleftbar","harpoon.tl.bar"],["upharpoonright","harpoon.tr"],["upharpoonrightbar","harpoon.tr.bar"],["upharpoonsleftright","harpoons.tltr"],["uplus","union.plus"],["upuparrows","arrows.tt"],["upwhitearrow","arrow.t.stroked"],["urblacktriangle","triangle.filled.tr"],["urcorner","corner.r.t"],["urtriangle","triangle.stroked.tr"],["UUparrow","arrow.t.quad"],["Uuparrow","arrow.t.triple"],["varclubsuit","suit.club.stroked"],["varhexagon","hexa.stroked"],["varhexagonblack","hexa.filled"],["varnothing","emptyset"],["varointclockwise","integral.cont.cw"],["varspadesuit","suit.spade.stroked"],["vartriangle","triangle.stroked.small.t"],["vartriangleleft","lt.tri"],["vartriangleright","gt.tri"],["Vbar","tack.t.double"],["Vdash","forces"],["vdash","tack.r"],["vDash","tack.r.double"],["vdots","dots.v"],["vee","or"],["Vee","or.double"],["veedot","or.dot"],["veeeq","eq.equi"],["vert","bar.v"],["Vert","bar.v.double"],["vlongdash","tack.r.long"],["vrectangle","rect.stroked.v"],["vrectangleblack","rect.filled.v"],["Vvert","bar.v.triple"],["vysmblkcircle","circle.filled.small"],["vysmwhtcircle","circle.stroked.tiny"],["wedge","and"],["Wedge","and.double"],["wedgedot","and.dot"],["wedgeq","eq.est"],["whiteinwhitetriangle","triangle.stroked.nested"],["whthorzoval","ellipse.stroked.h"],["whtvertoval","ellipse.stroked.v"],["wideangledown","angle.obtuse"],["wr","wreath"],["xsol","slash.big"]]),lt=new Map([["gets","leftarrow"],["iff","Longleftrightarrow"],["implies","Longrightarrow"]]);for(let[s,e]of it)E.has(s)||E.set(s,e);var P=new Map;for(let[s,e]of Array.from(E.entries()).reverse())P.set(e,s);P.set("oo","infty");var ut=new Map([["top","top"],["frac","frac"],["tilde","tilde"],["hat","hat"],["upright","mathrm"],["bold","boldsymbol"],["infinity","infty"],["diff","partial"]]);for(let[s,e]of ut)P.set(s,e);for(let[s,e]of lt)E.has(s)||E.set(s,E.get(e));var z=class extends Error{node;constructor(e,r=null){super(e),this.name="ConverterError",this.node=r}},pt=i.NONE.toNode(),ct=["dim","id","im","mod","Pr","sech","csch"];function ht(s){if(/^[a-zA-Z0-9]$/.test(s))return s;if(s==="/")return"\\/";if(["\\\\","\\{","\\}","\\%"].includes(s))return s.substring(1);if(["\\$","\\#","\\&","\\_"].includes(s))return s;if(s.startsWith("\\")){let e=s.slice(1);return E.has(e)?E.get(e):null}return s}function Y(s,e){let r;switch(s.type){case 0:return i.NONE;case 2:r=1;break;case 1:r=2;break;case 3:r=3;break;case 4:r=5;break;case 5:r=6;break;case 6:r=8;break;case 7:{if(s.value==="\\\\")return new i(7,"\\");if(s.value==="\\!")return new i(1,"#h(-math.thin.amount)");if(s.value==="~"){let n=E.get("~");return new i(1,n)}else if(E.has(s.value.substring(1))){let n=E.get(s.value.substring(1));return new i(1,n)}else throw new Error(`Unknown control sequence: ${s.value}`)}default:throw Error(`Unknown token type: ${s.type}`)}let t=ht(s.value);if(t===null){if(e.nonStrict)return new i(r,s.value.substring(1));throw new z(`Unknown token: ${s.value}`,s)}return new i(r,t)}function dt(s,e){let[r,t]=s.args;if(e.optimize&&["\\overset{\\text{def}}{=}","\\overset{d e f}{=}"].includes(s.toString()))return new i(1,"eq.def").toNode();let n=new m(new i(1,"limits"),[b(t,e)]);return new O({base:n,sup:b(r,e),sub:null})}function Tt(s,e){let[r,t]=s.args,n=new m(new i(1,"limits"),[b(t,e)]);return new O({base:n,sub:b(r,e),sup:null})}function gt(s){let e={},r={l:"#left",c:"#center",r:"#right"},t=Array.from(s),n=[],o=0;for(let u of t)u==="|"?n.push(o):(u==="l"||u==="c"||u==="r")&&o++;if(n.length>0){let u;n.length===1?u=`#${n[0]}`:u=`#(vline: (${n.join(", ")}))`,e.augment=new i(3,u).toNode()}let a=t.map(u=>r[u]).filter(u=>u!==void 0).map(u=>new i(3,u).toNode());if(a.length>0){let u=a.every(p=>p.eq(a[0]));e.align=u?a[0]:new i(3,"#center").toNode()}return e}var wt=new i(2,"("),bt=new i(2,")");function fe(s){return["group","supsub","matrixLike","fraction","empty"].includes(s.type)?new q(null,{left:wt,right:bt,body:s}):s}function b(s,e){switch(s.type){case"terminal":return Y(s.head,e).toNode();case"text":{let t=s;return new i(4,t.head.value).toNode()}case"ordgroup":let r=s;return new L(r.items.map(t=>b(t,e)));case"supsub":{let t=s,{base:n,sup:o,sub:a}=t;if(n&&n.type==="funcCall"&&n.head.value==="\\overbrace"&&o)return new m(new i(1,"overbrace"),[b(n.args[0],e),b(o,e)]);if(n&&n.type==="funcCall"&&n.head.value==="\\underbrace"&&a)return new m(new i(1,"underbrace"),[b(n.args[0],e),b(a,e)]);let u={base:b(n,e),sup:o?b(o,e):null,sub:a?b(a,e):null};return u.sup&&(u.sup=fe(u.sup)),u.sub&&(u.sub=fe(u.sub)),new O(u)}case"leftright":{let t=s,{left:n,right:o}=t,a=b(t.body,e);if(e.optimize&&n!==null&&o!==null){let h=Y(n,e),d=Y(o,e);if(n.value==="\\|"&&o.value==="\\|")return new m(new i(1,"norm"),[a]);if(["[]","()","\\{\\}","\\lfloor\\rfloor","\\lceil\\rceil","\\lfloor\\rceil"].includes(n.value+o.value))return new L([h.toNode(),a,d.toNode()])}let u=function(h){return["(",")","{","["].includes(h.value)?new i(2,"\\"+h.value):h},p=n?Y(n,e):null,c=o?Y(o,e):null;return p===null&&c!==null&&(c=u(c)),c===null&&p!==null&&(p=u(p)),new q(new i(1,"lr"),{body:a,left:p,right:c})}case"funcCall":{let t=s,n=b(t.args[0],e);if(t.head.value==="\\sqrt"&&t.data){let o=b(t.data,e);return new m(new i(1,"root"),[o,n])}if(t.head.value==="\\mathbf"){let o=new m(new i(1,"bold"),[n]);return new m(new i(1,"upright"),[o])}if(t.head.value==="\\overrightarrow")return new m(new i(1,"arrow"),[n]);if(t.head.value==="\\overleftarrow")return new m(new i(1,"accent"),[n,new i(1,"arrow.l").toNode()]);if(t.head.value==="\\operatorname"||t.head.value==="\\operatorname*"){if(e.optimize&&ct.includes(n.head.value))return new i(1,n.head.value).toNode();let o=new m(new i(1,"op"),[new i(4,n.head.value).toNode()]);return t.head.value==="\\operatorname*"&&o.setOptions({limits:new i(3,"#true").toNode()}),o}if(t.head.value==="\\textcolor"){let o=new B(new i(1,"#text"),[b(t.args[1],e)]);return o.setOptions({fill:n}),o}if(t.head.value==="\\substack"||t.head.value==="\\displaylines"||t.head.value==="\\mathinner")return n;if(t.head.value==="\\mathrel")return new m(new i(1,"class"),[new i(4,"relation").toNode(),n]);if(t.head.value==="\\mathbin")return new m(new i(1,"class"),[new i(4,"binary").toNode(),n]);if(t.head.value==="\\mathop")return new m(new i(1,"class"),[new i(4,"large").toNode(),n]);if(t.head.value==="\\set")return new q(null,{body:n,left:i.LEFT_BRACE,right:i.RIGHT_BRACE});if(t.head.value==="\\not"){let o=b(t.args[0],e);if(T(o.type==="terminal"),o.head.type===1)return new i(1,o.head.value+".not").toNode();switch(o.head.value){case"=":return new i(1,"eq.not").toNode();default:throw new Error(`Not supported: \\not ${o.head.value}`)}}if(t.head.value==="\\overset")return dt(t,e);if(t.head.value==="\\underset")return Tt(t,e);if(t.head.value==="\\frac"&&e.fracToSlash)return new I(t.args.map(o=>b(o,e)).map(fe));if(e.optimize){if(t.head.value==="\\mathbb"&&/^\\mathbb{[A-Z]}$/.test(t.toString()))return new i(1,n.head.value.repeat(2)).toNode();if(t.head.value==="\\mathrm"&&t.toString()==="\\mathrm{d}")return new i(1,"dif").toNode()}return new m(Y(t.head,e),t.args.map(o=>b(o,e)))}case"beginend":{let t=s,n=t.matrix.map(o=>o.map(a=>b(a,e)));if(t.head.value.startsWith("align"))return new y(null,n);if(t.head.value==="cases")return new y(y.CASES,n);if(t.head.value==="subarray"){if(t.data)switch(t.data.head.value){case"r":n.forEach(a=>a.push(i.EMPTY.toNode()));break;case"l":n.forEach(a=>a.unshift(i.EMPTY.toNode()));break;default:break}return new y(null,n)}if(t.head.value==="array"){let o={delim:pt};T(t.data!==null&&t.head.type===3);let a=gt(t.data.head.value);Object.assign(o,a);let u=new y(y.MAT,n);return u.setOptions(o),u}if(t.head.value.endsWith("matrix")){let o=new y(y.MAT,n),a;switch(t.head.value){case"matrix":a=i.NONE;break;case"pmatrix":return o;case"bmatrix":a=new i(4,"[");break;case"Bmatrix":a=new i(4,"{");break;case"vmatrix":a=new i(4,"|");break;case"Vmatrix":{a=new i(1,"bar.v.double");break}default:throw new z(`Unimplemented beginend: ${t.head}`,t)}return o.setOptions({delim:a.toNode()}),o}throw new z(`Unimplemented beginend: ${t.head}`,t)}default:throw new z(`Unimplemented node type: ${s.type}`,s)}}function C(s){switch(s.type){case 0:return l.EMPTY;case 1:{let e=function(r){switch(r){case"eq":return"=";case"plus":return"+";case"minus":return"-";case"percent":return"%";default:return P.has(r)?"\\"+P.get(r):"\\"+r}};if(s.value.endsWith(".not")){let r=e(s.value.slice(0,-4));return new l(2,r.startsWith("\\")?`\\not${r}`:`\\not ${r}`)}return new l(2,e(s.value))}case 2:{let e;return["{","}","%"].includes(s.value)?e="\\"+s.value:e=s.value,new l(1,e)}case 3:return new l(3,s.value);case 4:return new l(3,s.value);case 5:return new l(4,s.value);case 6:return new l(5,s.value);case 7:{let e;switch(s.value){case"\\":e="\\\\";break;case"&":e="&";break;default:throw new Error(`[typst_token_to_tex]Unimplemented control sequence: ${s.value}`)}return new l(7,e)}case 8:return new l(6,s.value);default:throw new Error(`Unimplemented token type: ${s.type}`)}}var mt=new l(1,",").toNode();function ye(s,e){let r=t=>ye(t,e);switch(s.type){case"terminal":{let t=s;if(t.head.type===1){if(t.head.value==="eq.def")return new w(new l(2,"\\overset"),[new _(new l(3,"def")),new l(1,"=").toNode()]);if(t.head.value==="comma")return new l(1,",").toNode();if(t.head.value==="dif")return new w(new l(2,"\\mathrm"),[new l(1,"d").toNode()]);if(t.head.value==="hyph"||t.head.value==="hyph.minus")return new _(new l(3,"-"));if(/^([A-Z])\1$/.test(t.head.value))return new w(new l(2,"\\mathbb"),[new l(1,t.head.value[0]).toNode()])}return t.head.type===4?new _(new l(3,t.head.value)):C(t.head).toNode()}case"group":{let n=s.items.map(r),o=new l(7,"&").toNode(),a=new l(7,"\\\\").toNode();if(K(n,o)){let u=R(n,a),p=[];for(let c of u){let h=R(c,o);p.push(h.map(d=>new f(d)))}return new M(new l(3,"aligned"),p)}return new f(n)}case"leftright":{let t=s,n=r(t.body),o=t.left?C(t.left):new l(1,"."),a=t.right?C(t.right):new l(1,".");return t.isOverHigh()&&(o.value="\\left"+o.value,a.value="\\right"+a.value),new f([o.toNode(),n,a.toNode()])}case"funcCall":{let t=s;switch(t.head.value){case"norm":{let n=t.args[0],o=r(n);return t.isOverHigh()?new A({body:o,left:new l(2,"\\|"),right:new l(2,"\\|")}):o}case"floor":case"ceil":{let n="\\l"+t.head.value,o="\\r"+t.head.value,a=t.args[0],u=r(a),p=new l(2,n),c=new l(2,o);return t.isOverHigh()?new A({body:u,left:p,right:c}):new f([p.toNode(),u,c.toNode()])}case"root":{let[n,o]=t.args,a=r(n);return new w(new l(2,"\\sqrt"),[r(o)],a)}case"overbrace":case"underbrace":{let[n,o]=t.args,a=new w(C(t.head),[r(n)]),u=r(o),p=t.head.value==="overbrace"?{base:a,sup:u,sub:null}:{base:a,sub:u,sup:null};return new S(p)}case"vec":{let n=t.args.map(o=>[r(o)]);return new M(new l(3,"pmatrix"),n)}case"op":{let n=t.args[0];return T(n.head.type===4),new w(C(t.head),[new l(3,n.head.value).toNode()])}case"class":{let n=t.args[0];T(n.head.type===4);let o;switch(n.head.value){case"relation":o="\\mathrel";break;case"binary":o="\\mathbin";break;case"large":o="\\mathop";break;default:throw new Error(`Unimplemented class: ${n.head.value}`)}return new w(new l(2,o),[r(t.args[1])])}case"display":{let n=t.args[0],o=new f([l.COMMAND_DISPLAYSTYLE.toNode(),r(n)]);return e.blockMathMode||o.items.push(l.COMMAND_TEXTSTYLE.toNode()),o}case"inline":{let n=t.args[0],o=new f([l.COMMAND_TEXTSTYLE.toNode(),r(n)]);return e.blockMathMode&&o.items.push(l.COMMAND_DISPLAYSTYLE.toNode()),o}default:{let n=C(t.head),o=W.includes(n.value.substring(1))||H.includes(n.value.substring(1));return n.value.length>0&&o?new w(n,t.args.map(r)):new f([C(t.head).toNode(),new l(1,"(").toNode(),...Me(t.args.map(r),mt),new l(1,")").toNode()])}}}case"markupFunc":{let t=s;switch(t.head.value){case"#text":if(t.options&&t.options.fill){let n=t.options.fill;return new w(new l(2,"\\textcolor"),[r(n),r(t.fragments[0])])}case"#heading":default:throw new Error(`Unimplemented markup function: ${t.head.value}`)}}case"supsub":{let t=s,{base:n,sup:o,sub:a}=t,u=o?r(o):null,p=a?r(a):null;if(n.head.eq(new i(1,"limits"))){let k=r(n.args[0]);if(u!==null&&p===null)return new w(new l(2,"\\overset"),[u,k]);if(u===null&&p!==null)return new w(new l(2,"\\underset"),[p,k]);{let ae=new w(new l(2,"\\underset"),[p,k]);return new w(new l(2,"\\overset"),[u,ae])}}let c=r(n);return new S({base:c,sup:u,sub:p})}case"matrixLike":{let t=s,n=t.matrix.map(o=>o.map(r));if(t.head.eq(y.MAT)){let o="pmatrix";if(t.options&&"delim"in t.options){let a=t.options.delim;switch(a.head.value){case"#none":o="matrix";break;case"[":case"]":o="bmatrix";break;case"(":case")":o="pmatrix";break;case"{":case"}":o="Bmatrix";break;case"|":o="vmatrix";break;case"bar":case"bar.v":o="vmatrix";break;case"bar.v.double":o="Vmatrix";break;default:throw new Error(`Unexpected delimiter ${a.head}`)}}return new M(new l(3,o),n)}else{if(t.head.eq(y.CASES))return new M(new l(3,"cases"),n);throw new Error(`Unexpected matrix type ${t.head}`)}}case"fraction":{let t=s,[n,o]=t.args,a=r(n),u=r(o);return new w(new l(2,"\\frac"),[a,u])}default:throw new Error("[convert_typst_node_to_tex] Unimplemented type: "+s.type)}}var ft=Array.from(J.keys());function yt(){return`(${ft.map(e=>(e=e.replaceAll("|","\\|"),e=e.replaceAll(".","\\."),e=e.replaceAll("[","\\["),e=e.replaceAll("]","\\]"),e)).join("|")})`}var Et=yt(),Nt=new Map([[String.raw`//[^\n]*`,s=>new i(5,s.text().substring(2))],[String.raw`/`,s=>new i(2,s.text())],[String.raw`[_^&]`,s=>new i(7,s.text())],[String.raw`\r?\n`,s=>new i(8,`
|
|
9
|
+
`)],[String.raw`\s+`,s=>new i(6,s.text())],[String.raw`\\[$&#_]`,s=>new i(2,s.text())],[String.raw`\\\n`,s=>[new i(7,"\\"),new i(8,`
|
|
10
|
+
`)]],[String.raw`\\\s`,s=>[new i(7,"\\"),new i(6," ")]],[String.raw`\\\S`,s=>new i(7,"")],[String.raw`"([^"]|(\\"))*"`,s=>{let e=s.text().substring(1,s.text().length-1);return e.replaceAll('\\"','"'),new i(4,e)}],[Et,s=>{let e=s.text(),r=J.get(e);return new i(1,r)}],[String.raw`[0-9]+(\.[0-9]+)?`,s=>new i(2,s.text())],[String.raw`[+\-*/=\'<>!.,;?()\[\]|]`,s=>new i(2,s.text())],[String.raw`#h\((.+?)\)`,s=>{let e=s.reMatchArray();return[new i(1,"#h"),new i(2,"("),new i(3,e[1]),new i(2,")")]}],[String.raw`#none`,s=>new i(0,s.text())],[String.raw`#?[a-zA-Z\.]+`,s=>new i(s.text().length===1?2:1,s.text())],[String.raw`.`,s=>new i(2,s.text())]]),xt={start:Nt};function Ie(s){return new D(xt).collect(s)}function Be(s,e){let r=e;for(;r<s.length&&s[r].eq(new i(2,"'"));)r+=1;return r-e}function Ue(s,e,r,t){T(s[e].isOneOf(r));let n=1,o=e+1;for(;n>0;){if(o>=s.length)throw new Error("Unmatched brackets or parentheses");s[o].isOneOf(t)?n-=1:s[o].isOneOf(r)&&(n+=1),o+=1}return o-1}function Ee(s,e){return Ue(s,e,[j,We,_t],[ne,He,Ot])}function kt(s){let e=new i(2,":").toNode(),r={},t=[];for(let n=0;n<s.length;n++){if(s[n].type!=="group")continue;let o=s[n],a=ue(o.items,e);if(a===-1||a===0)continue;if(t.push(n),o.items[a-1].eq(new i(1,"delim").toNode())){if(o.items.length!==3)throw new V("Invalid number of arguments for delim");r.delim=o.items[a+1]}else throw new V("Not implemented for other named parameters")}for(let n=t.length-1;n>=0;n--)s.splice(t[n],1);return[s,r]}function Pe(s){let e=[];for(let r=0;r<s;r++)e.push(new i(2,"'").toNode());return e}var se=new i(2,"/").toNode();function vt(s,e){let r=e;for(;r<s.length&&(s[r].head.type===6||s[r].head.type===8);)r++;return r===s.length?null:s[r]}function Mt(s){let e=!1,r=[];for(let t=0;t<s.length;t++){let n=s[t];(n.head.type===6||n.head.type===8)&&(e||vt(s,t+1)?.eq(se))||(n.eq(se)?e=!0:e=!1,r.push(n))}return r}function Lt(s){s=Mt(s);let e=[],r=[],t=0;for(;t<s.length;){let n=s[t];if(n.eq(se))e.push(n);else if(e.length>0&&e[e.length-1].eq(se)){let o=n;if(r.length===0)throw new V("Unexpected '/' operator, no numerator before it");let a=r.pop();o.type==="leftright"&&(o=o.body),a.type==="leftright"&&(a=a.body),r.push(new I([a,o])),e.pop()}else r.push(n);t++}return r.length===1?r[0]:new L(r)}function qt(s){let e=new i(2,":").toNode(),r={};for(let t of s)T(t.items.length==3),T(t.items[1].eq(e)),r[t.items[0].toString()]=new X(new i(3,t.items[2].toString()));return r}var V=class extends Error{constructor(e){super(e),this.name="TypstParserError"}},Ye=new i(7,"_"),ze=new i(7,"^"),j=new i(2,"("),ne=new i(2,")"),We=new i(2,"["),He=new i(2,"]"),_t=new i(2,"{"),Ot=new i(2,"}"),Ne=new i(2,","),St=new i(2,";"),At=new i(7,"&"),xe=class{space_sensitive;newline_sensitive;constructor(e=!0,r=!0){this.space_sensitive=e,this.newline_sensitive=r}parse(e){let[r,t]=this.parseGroup(e,0,e.length);return r}parseGroup(e,r,t){return this.parseUntil(e.slice(r,t),0,null)}parseNextExpr(e,r){let[t,n]=this.parseNextExprWithoutSupSub(e,r),o=null,a=null,u=Be(e,n);if(u>0&&(t=new L([t].concat(Pe(u))),n+=u),n<e.length&&e[n].eq(Ye)?([o,n]=this.parseSupOrSub(e,n+1),n<e.length&&e[n].eq(ze)&&([a,n]=this.parseSupOrSub(e,n+1))):n<e.length&&e[n].eq(ze)&&([a,n]=this.parseSupOrSub(e,n+1),n<e.length&&e[n].eq(Ye)&&([o,n]=this.parseSupOrSub(e,n+1))),o!==null||a!==null){let p={base:t,sup:a,sub:o};return[new O(p),n]}else return[t,n]}parseUntil(e,r,t,n={}){n.spaceSensitive===void 0&&(n.spaceSensitive=this.space_sensitive),n.newlineSensitive===void 0&&(n.newlineSensitive=this.newline_sensitive);let o=[],a=r;for(;a<e.length&&!(t!==null&&e[a].eq(t));){let[p,c]=this.parseNextExpr(e,a);a=c,!((p.head.type===6||p.head.type===8)&&(!n.spaceSensitive&&p.head.value.replace(/ /g,"").length===0||!n.newlineSensitive&&p.head.value===`
|
|
11
|
+
`))&&o.push(p)}return a>=e.length&&t!==null?[i.NONE.toNode(),-1]:[Lt(o),a+1]}parseSupOrSub(e,r){let t,n;if(e[r].eq(j)){if([t,n]=this.parseUntil(e,r+1,ne),n===-1)throw new Error("Unmatched '('")}else[t,n]=this.parseNextExprWithoutSupSub(e,r);let o=Be(e,n);return o>0&&(t=new L([t].concat(Pe(o))),n+=o),[t,n]}parseNextExprWithoutSupSub(e,r){let t=e[r],n=t.toNode();if(t.eq(j)){let[o,a]=this.parseUntil(e,r+1,ne);if(a===-1)throw new Error("Unmatched '('");return[new q(null,{body:o,left:j,right:ne}),a]}if(t.type===2&&!U(t.value[0]))return[n,r+1];if([2,1].includes(t.type)&&r+1<e.length&&e[r+1].eq(j)){if(t.value==="mat"){let[p,c,h]=this.parseMatrix(e,r+1,St,Ne),d=new y(t,p);return d.setOptions(c),[d,h]}if(t.value==="cases"){let[p,c,h]=this.parseMatrix(e,r+1,Ne,At),d=new y(t,p);return d.setOptions(c),[d,h]}if(t.value==="lr")return this.parseLrArguments(e,r+1);if(["#heading","#text"].includes(t.value)){let[p,c]=this.parseArguments(e,r+1),h=qt(p);T(e[c].eq(We));let d=new i(2,"$"),k=Ue(e,c+1,[d],[d]),[ae,Ct]=this.parseGroup(e,c+2,k);T(e[k+1].eq(He));let ke=new B(t,[ae]);return ke.setOptions(h),[ke,k+2]}let[o,a]=this.parseArguments(e,r+1);return[new m(t,o),a]}return[n,r+1]}parseArguments(e,r){let t=Ee(e,r);return[this.parseArgumentsWithSeparator(e,r+1,t,Ne),t+1]}parseLrArguments(e,r){let t=new i(1,"lr"),n=Ee(e,r),o=null,a=null,u=r+1,p=n;p>u&&e[u].isOneOf(i.LEFT_DELIMITERS)&&(o=e[u],u+=1),p-1>u&&e[p-1].isOneOf(i.RIGHT_DELIMITERS)&&(a=e[p-1],p-=1);let[c,h]=this.parseGroup(e,u,p);return[new q(t,{body:c,left:o,right:a}),n+1]}parseMatrix(e,r,t,n){let o=Ee(e,r),a=[],u={},p=r+1;for(;p<o;)for(;p<o;){let c=ue(e,t,p);(c===-1||c>o)&&(c=o);let h=this.parseArgumentsWithSeparator(e,p,c,n),d={};[h,d]=kt(h),a.push(h),Object.assign(u,d),p=c+1}return[a,u,o+1]}parseArgumentsWithSeparator(e,r,t,n){let o=[],a=r;for(;a<t;){let u,p,c={spaceSensitive:!1,newlineSensitive:!0};[u,p]=this.parseUntil(e.slice(0,t),a,n,c),p==-1&&([u,p]=this.parseUntil(e.slice(0,t),a,null,c)),o.push(u),a=p}return o}};function Fe(s){let e=new xe,r=Ie(s);return e.parse(r)}var oe=class{buffer="";queue=[];append(e){this.queue=this.queue.concat(e.serialize())}flushQueue(){for(;this.queue.length>0;){let e=this.queue[this.queue.length-1];if(e.eq(l.COMMAND_DISPLAYSTYLE)||e.eq(l.COMMAND_TEXTSTYLE))this.queue.pop();else break}for(let e=0;e<this.queue.length;e++)this.buffer=le(this.buffer,this.queue[e]);this.queue=[]}finalize(){return this.flushQueue(),this.buffer}};function $e(s,e={}){let r={nonStrict:!0,preferShorthands:!0,keepSpaces:!1,fracToSlash:!0,inftyToOo:!1,optimize:!0,customTexMacros:{}};if(typeof e!="object")throw new Error("options must be an object");for(let a in r)a in e&&(r[a]=e[a]);let t=Re(s,r.customTexMacros),n=b(t,r),o=new re(r);return o.serialize(n),o.finalize()}function Ge(s,e={}){let r={blockMathMode:!0};if(typeof e!="object")throw new Error("options must be an object");for(let a in r)a in e&&(r[a]=e[a]);let t=Fe(s),n=ye(t,r),o=new oe;return o.append(n),o.finalize()}window.tex2typst=$e;window.typst2tex=Ge;})();
|
package/package.json
CHANGED
package/src/typst-types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { array_includes } from "./generic";
|
|
2
2
|
import { shorthandMap } from "./typst-shorthands";
|
|
3
|
+
import { isalpha } from "./utils";
|
|
3
4
|
|
|
4
5
|
export enum TypstTokenType {
|
|
5
6
|
NONE,
|
|
@@ -50,6 +51,8 @@ export class TypstToken {
|
|
|
50
51
|
public static readonly EMPTY = new TypstToken(TypstTokenType.ELEMENT, '');
|
|
51
52
|
public static readonly LEFT_BRACE = new TypstToken(TypstTokenType.ELEMENT, '{');
|
|
52
53
|
public static readonly RIGHT_BRACE = new TypstToken(TypstTokenType.ELEMENT, '}');
|
|
54
|
+
public static readonly PLUS = new TypstToken(TypstTokenType.ELEMENT, '+');
|
|
55
|
+
public static readonly MINUS = new TypstToken(TypstTokenType.ELEMENT, '-');
|
|
53
56
|
|
|
54
57
|
|
|
55
58
|
public static readonly LEFT_DELIMITERS = [
|
|
@@ -135,6 +138,9 @@ export abstract class TypstNode {
|
|
|
135
138
|
// e.g. 1/2 is over high, "2" is not.
|
|
136
139
|
abstract isOverHigh(): boolean;
|
|
137
140
|
|
|
141
|
+
abstract isLeftSpaceful(): boolean;
|
|
142
|
+
abstract isRightSpaceful(): boolean;
|
|
143
|
+
|
|
138
144
|
// Serialize a tree of TypstNode into a list of TypstToken
|
|
139
145
|
abstract serialize(env: TypstWriterEnvironment, options: TypstWriterOptions): TypstToken[];
|
|
140
146
|
|
|
@@ -161,6 +167,42 @@ export class TypstTerminal extends TypstNode {
|
|
|
161
167
|
return false;
|
|
162
168
|
}
|
|
163
169
|
|
|
170
|
+
public isLeftSpaceful(): boolean {
|
|
171
|
+
switch (this.head.type) {
|
|
172
|
+
case TypstTokenType.SPACE:
|
|
173
|
+
case TypstTokenType.NEWLINE:
|
|
174
|
+
return false;
|
|
175
|
+
case TypstTokenType.TEXT:
|
|
176
|
+
return true;
|
|
177
|
+
case TypstTokenType.SYMBOL:
|
|
178
|
+
case TypstTokenType.ELEMENT: {
|
|
179
|
+
if(['(', '!', '}', ']'].includes(this.head.value)) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
default:
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
public isRightSpaceful(): boolean {
|
|
190
|
+
switch (this.head.type) {
|
|
191
|
+
case TypstTokenType.SPACE:
|
|
192
|
+
case TypstTokenType.NEWLINE:
|
|
193
|
+
return false;
|
|
194
|
+
case TypstTokenType.TEXT:
|
|
195
|
+
return true;
|
|
196
|
+
case TypstTokenType.SYMBOL:
|
|
197
|
+
case TypstTokenType.ELEMENT: {
|
|
198
|
+
return ['+', '=', ',', '\\/', 'dot', 'dot.op', 'arrow', 'arrow.r'].includes(this.head.value);
|
|
199
|
+
}
|
|
200
|
+
default:
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
164
206
|
public toString(): string {
|
|
165
207
|
return this.head.toString();
|
|
166
208
|
}
|
|
@@ -200,6 +242,8 @@ export class TypstTerminal extends TypstNode {
|
|
|
200
242
|
}
|
|
201
243
|
}
|
|
202
244
|
|
|
245
|
+
|
|
246
|
+
|
|
203
247
|
export class TypstGroup extends TypstNode {
|
|
204
248
|
public items: TypstNode[];
|
|
205
249
|
constructor(items: TypstNode[]) {
|
|
@@ -211,14 +255,52 @@ export class TypstGroup extends TypstNode {
|
|
|
211
255
|
return this.items.some((n) => n.isOverHigh());
|
|
212
256
|
}
|
|
213
257
|
|
|
258
|
+
public isLeftSpaceful(): boolean {
|
|
259
|
+
if (this.items.length === 0) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
return this.items[0].isLeftSpaceful();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
public isRightSpaceful(): boolean {
|
|
266
|
+
if (this.items.length === 0) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
return this.items.at(-1)!.isRightSpaceful();
|
|
270
|
+
}
|
|
271
|
+
|
|
214
272
|
public serialize(env: TypstWriterEnvironment, options: TypstWriterOptions): TypstToken[] {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (queue.length > 0 && queue[0].eq(SOFT_SPACE)) {
|
|
218
|
-
queue.shift();
|
|
273
|
+
if (this.items.length === 0) {
|
|
274
|
+
return [];
|
|
219
275
|
}
|
|
220
|
-
|
|
221
|
-
|
|
276
|
+
const queue: TypstToken[] = [];
|
|
277
|
+
for(let i = 0; i < this.items.length; i++) {
|
|
278
|
+
const n = this.items[i];
|
|
279
|
+
const tokens = n.serialize(env, options);
|
|
280
|
+
if (n.isLeftSpaceful() && i > 0) {
|
|
281
|
+
if (queue.length > 0) {
|
|
282
|
+
const top = queue.at(-1)!;
|
|
283
|
+
let no_need_space = false;
|
|
284
|
+
no_need_space ||= top.eq(SOFT_SPACE);
|
|
285
|
+
no_need_space ||= ['{', '['].includes(top.value);
|
|
286
|
+
if (!no_need_space) {
|
|
287
|
+
queue.push(SOFT_SPACE);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
queue.push(...tokens);
|
|
292
|
+
if (n.isRightSpaceful() && i < this.items.length - 1) {
|
|
293
|
+
if(!(queue.at(-1)?.eq(SOFT_SPACE))) {
|
|
294
|
+
queue.push(SOFT_SPACE);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// "- a" -> "-a"
|
|
299
|
+
// "+ a" -> "+a"
|
|
300
|
+
if (queue.length > 0 && (queue[0].eq(TypstToken.MINUS) || queue[0].eq(TypstToken.PLUS))) {
|
|
301
|
+
while(queue.length > 1 && queue[1].eq(SOFT_SPACE)) {
|
|
302
|
+
queue.splice(1, 1);
|
|
303
|
+
}
|
|
222
304
|
}
|
|
223
305
|
return queue;
|
|
224
306
|
}
|
|
@@ -241,6 +323,15 @@ export class TypstSupsub extends TypstNode {
|
|
|
241
323
|
return this.base.isOverHigh();
|
|
242
324
|
}
|
|
243
325
|
|
|
326
|
+
public isLeftSpaceful(): boolean {
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
public isRightSpaceful(): boolean {
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
|
|
244
335
|
public serialize(env: TypstWriterEnvironment, options: TypstWriterOptions): TypstToken[] {
|
|
245
336
|
const queue: TypstToken[] = [];
|
|
246
337
|
let { base, sup, sub } = this;
|
|
@@ -263,7 +354,6 @@ export class TypstSupsub extends TypstNode {
|
|
|
263
354
|
queue.push(new TypstToken(TypstTokenType.ELEMENT, '^'));
|
|
264
355
|
queue.push(...sup.serialize(env, options));
|
|
265
356
|
}
|
|
266
|
-
queue.push(SOFT_SPACE);
|
|
267
357
|
return queue;
|
|
268
358
|
}
|
|
269
359
|
}
|
|
@@ -282,6 +372,14 @@ export class TypstFuncCall extends TypstNode {
|
|
|
282
372
|
return this.args.some((n) => n.isOverHigh());
|
|
283
373
|
}
|
|
284
374
|
|
|
375
|
+
public isLeftSpaceful(): boolean {
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
public isRightSpaceful(): boolean {
|
|
380
|
+
return !['op', 'bold', 'dot'].includes(this.head.value);
|
|
381
|
+
}
|
|
382
|
+
|
|
285
383
|
public serialize(env: TypstWriterEnvironment, options: TypstWriterOptions): TypstToken[] {
|
|
286
384
|
const queue: TypstToken[] = [];
|
|
287
385
|
|
|
@@ -293,6 +391,7 @@ export class TypstFuncCall extends TypstNode {
|
|
|
293
391
|
queue.push(...this.args[i].serialize(env, options));
|
|
294
392
|
if (i < this.args.length - 1) {
|
|
295
393
|
queue.push(new TypstToken(TypstTokenType.ELEMENT, ','));
|
|
394
|
+
queue.push(SOFT_SPACE);
|
|
296
395
|
}
|
|
297
396
|
}
|
|
298
397
|
if (this.options) {
|
|
@@ -318,15 +417,21 @@ export class TypstFraction extends TypstNode {
|
|
|
318
417
|
return true;
|
|
319
418
|
}
|
|
320
419
|
|
|
420
|
+
public isLeftSpaceful(): boolean {
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
public isRightSpaceful(): boolean {
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
|
|
321
428
|
public serialize(env: TypstWriterEnvironment, options: TypstWriterOptions): TypstToken[] {
|
|
322
429
|
const queue: TypstToken[] = [];
|
|
323
430
|
|
|
324
431
|
const [numerator, denominator] = this.args;
|
|
325
|
-
queue.push(SOFT_SPACE);
|
|
326
432
|
queue.push(...numerator.serialize(env, options));
|
|
327
433
|
queue.push(new TypstToken(TypstTokenType.ELEMENT, '/'));
|
|
328
434
|
queue.push(...denominator.serialize(env, options));
|
|
329
|
-
queue.push(SOFT_SPACE);
|
|
330
435
|
return queue;
|
|
331
436
|
}
|
|
332
437
|
}
|
|
@@ -351,6 +456,15 @@ export class TypstLeftright extends TypstNode {
|
|
|
351
456
|
return this.body.isOverHigh();
|
|
352
457
|
}
|
|
353
458
|
|
|
459
|
+
public isLeftSpaceful(): boolean {
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
public isRightSpaceful(): boolean {
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
|
|
354
468
|
public serialize(env: TypstWriterEnvironment, options: TypstWriterOptions): TypstToken[] {
|
|
355
469
|
const queue: TypstToken[] = [];
|
|
356
470
|
const LR = new TypstToken(TypstTokenType.SYMBOL, 'lr');
|
|
@@ -361,9 +475,17 @@ export class TypstLeftright extends TypstNode {
|
|
|
361
475
|
}
|
|
362
476
|
if (left) {
|
|
363
477
|
queue.push(left);
|
|
478
|
+
// `lr(brace.l 1/3 brace.r)` instead of `lr(brace.l1/3 brace.r)`
|
|
479
|
+
if (isalpha(left.value[0])) {
|
|
480
|
+
queue.push(SOFT_SPACE);
|
|
481
|
+
}
|
|
364
482
|
}
|
|
365
483
|
queue.push(...this.body.serialize(env, options));
|
|
366
484
|
if (right) {
|
|
485
|
+
// `lr(brace.l 1/3 brace.r)` instead of `lr(brace.l 1/3brace.r)`
|
|
486
|
+
if (isalpha(right.value[0])) {
|
|
487
|
+
queue.push(SOFT_SPACE);
|
|
488
|
+
}
|
|
367
489
|
queue.push(right);
|
|
368
490
|
}
|
|
369
491
|
if (this.head.eq(LR)) {
|
|
@@ -387,6 +509,14 @@ export class TypstMatrixLike extends TypstNode {
|
|
|
387
509
|
return true;
|
|
388
510
|
}
|
|
389
511
|
|
|
512
|
+
public isLeftSpaceful(): boolean {
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
public isRightSpaceful(): boolean {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
|
|
390
520
|
public serialize(env: TypstWriterEnvironment, options: TypstWriterOptions): TypstToken[] {
|
|
391
521
|
const queue: TypstToken[] = [];
|
|
392
522
|
|
|
@@ -418,10 +548,16 @@ export class TypstMatrixLike extends TypstNode {
|
|
|
418
548
|
row.forEach((cell, j) => {
|
|
419
549
|
queue.push(...cell.serialize(env, options));
|
|
420
550
|
if (j < row.length - 1) {
|
|
551
|
+
queue.push(SOFT_SPACE);
|
|
421
552
|
queue.push(cell_sep);
|
|
553
|
+
queue.push(SOFT_SPACE);
|
|
422
554
|
} else {
|
|
423
555
|
if (i < this.matrix.length - 1) {
|
|
556
|
+
if (row_sep.value === '\\') {
|
|
557
|
+
queue.push(SOFT_SPACE);
|
|
558
|
+
}
|
|
424
559
|
queue.push(row_sep);
|
|
560
|
+
queue.push(SOFT_SPACE);
|
|
425
561
|
}
|
|
426
562
|
}
|
|
427
563
|
});
|
|
@@ -458,6 +594,14 @@ export class TypstMarkupFunc extends TypstNode {
|
|
|
458
594
|
return this.fragments.some((n) => n.isOverHigh());
|
|
459
595
|
}
|
|
460
596
|
|
|
597
|
+
public isLeftSpaceful(): boolean {
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
public isRightSpaceful(): boolean {
|
|
602
|
+
return true;
|
|
603
|
+
}
|
|
604
|
+
|
|
461
605
|
public serialize(env: TypstWriterEnvironment, options: TypstWriterOptions): TypstToken[] {
|
|
462
606
|
const queue: TypstToken[] = [];
|
|
463
607
|
|
package/src/typst-writer.ts
CHANGED
|
@@ -34,50 +34,6 @@ export class TypstWriter {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
private writeBuffer(previousToken: TypstToken | null, token: TypstToken) {
|
|
38
|
-
const str = token.toString();
|
|
39
|
-
|
|
40
|
-
if (str === '') {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let no_need_space = false;
|
|
45
|
-
// putting the first token in clause
|
|
46
|
-
no_need_space ||= /[\(\[\|]$/.test(this.buffer) && /^\w/.test(str);
|
|
47
|
-
// closing a clause
|
|
48
|
-
no_need_space ||= /^[})\]\|]$/.test(str);
|
|
49
|
-
// putting the opening '(' for a function
|
|
50
|
-
no_need_space ||= /[^=]$/.test(this.buffer) && str === '(';
|
|
51
|
-
// putting punctuation
|
|
52
|
-
no_need_space ||= /^[_^,;!]$/.test(str);
|
|
53
|
-
// putting a prime
|
|
54
|
-
no_need_space ||= str === "'";
|
|
55
|
-
// leading sign. e.g. produce "+1" instead of " +1"
|
|
56
|
-
no_need_space ||= /[\(\[{]\s*(-|\+)$/.test(this.buffer) || this.buffer === "-" || this.buffer === "+";
|
|
57
|
-
// new line
|
|
58
|
-
no_need_space ||= str.startsWith('\n');
|
|
59
|
-
// buffer is empty
|
|
60
|
-
no_need_space ||= this.buffer === "";
|
|
61
|
-
// don't put space multiple times
|
|
62
|
-
no_need_space ||= (/\s$/.test(this.buffer) || /^\s/.test(str));
|
|
63
|
-
// "&=" instead of "& ="
|
|
64
|
-
no_need_space ||= this.buffer.endsWith('&') && str === '=';
|
|
65
|
-
// before or after a slash e.g. "a/b" instead of "a / b"
|
|
66
|
-
no_need_space ||= this.buffer.endsWith('/') || str === '/';
|
|
67
|
-
// "[$x + y$]" instead of "[ $ x + y $ ]"
|
|
68
|
-
no_need_space ||= token.type === TypstTokenType.LITERAL;
|
|
69
|
-
// other cases
|
|
70
|
-
no_need_space ||= /[\s_^{\(]$/.test(this.buffer);
|
|
71
|
-
if (previousToken !== null) {
|
|
72
|
-
no_need_space ||= previousToken.type === TypstTokenType.LITERAL;
|
|
73
|
-
}
|
|
74
|
-
if (!no_need_space) {
|
|
75
|
-
this.buffer += ' ';
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.buffer += str;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
37
|
// Serialize a tree of TypstNode into a list of TypstToken
|
|
82
38
|
public serialize(abstractNode: TypstNode) {
|
|
83
39
|
const env = {insideFunctionDepth: 0};
|
|
@@ -86,9 +42,11 @@ export class TypstWriter {
|
|
|
86
42
|
|
|
87
43
|
|
|
88
44
|
protected flushQueue() {
|
|
45
|
+
const queue1 = this.queue.filter((token) => token.value !== '');
|
|
46
|
+
|
|
89
47
|
// merge consecutive soft spaces
|
|
90
48
|
let qu: TypstToken[] = [];
|
|
91
|
-
for(const token of
|
|
49
|
+
for(const token of queue1) {
|
|
92
50
|
if (token.eq(SOFT_SPACE) && qu.length > 0 && qu[qu.length - 1].eq(SOFT_SPACE)) {
|
|
93
51
|
continue;
|
|
94
52
|
}
|
|
@@ -115,8 +73,7 @@ export class TypstWriter {
|
|
|
115
73
|
|
|
116
74
|
for(let i = 0; i < qu.length; i++) {
|
|
117
75
|
let token = qu[i];
|
|
118
|
-
|
|
119
|
-
this.writeBuffer(previous_token, token);
|
|
76
|
+
this.buffer += token.toString();
|
|
120
77
|
}
|
|
121
78
|
|
|
122
79
|
this.queue = [];
|
|
@@ -151,6 +108,8 @@ export class TypstWriter {
|
|
|
151
108
|
this.buffer = pass(this.buffer);
|
|
152
109
|
}
|
|
153
110
|
}
|
|
111
|
+
// "& =" -> "&="
|
|
112
|
+
this.buffer = this.buffer.replace(/& =/g, '&=');
|
|
154
113
|
return this.buffer;
|
|
155
114
|
}
|
|
156
115
|
}
|