@drghaliasri/butex 8.1.2 → 8.1.5
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/book.d.mts +19 -1
- package/dist/book.d.ts +19 -1
- package/dist/book.js +2501 -2
- package/dist/book.js.map +1 -1
- package/dist/book.mjs +2500 -2
- package/dist/book.mjs.map +1 -1
- package/dist/document-cli.js +222 -1
- package/dist/document-cli.js.map +1 -1
- package/dist/document.d.mts +1 -0
- package/dist/document.d.ts +1 -0
- package/dist/document.js +10 -2
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +10 -2
- package/dist/document.mjs.map +1 -1
- package/dist/react-book.d.mts +1 -0
- package/dist/react-book.d.ts +1 -0
- package/dist/react-book.js +10 -2
- package/dist/react-book.js.map +1 -1
- package/dist/react-book.mjs +10 -2
- package/dist/react-book.mjs.map +1 -1
- package/dist/react-document-preview.d.mts +1 -0
- package/dist/react-document-preview.d.ts +1 -0
- package/dist/react-document-preview.js +10 -2
- package/dist/react-document-preview.js.map +1 -1
- package/dist/react-document-preview.mjs +10 -2
- package/dist/react-document-preview.mjs.map +1 -1
- package/dist/react-document.d.mts +1 -0
- package/dist/react-document.d.ts +1 -0
- package/dist/react-document.js +10 -2
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +10 -2
- package/dist/react-document.mjs.map +1 -1
- package/package.json +1 -1
package/dist/book.mjs
CHANGED
|
@@ -7,6 +7,34 @@ function documentId(prefix) {
|
|
|
7
7
|
return id;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
// src/editor/digits.ts
|
|
11
|
+
var WESTERN = "0123456789";
|
|
12
|
+
var ARABIC_INDIC = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
|
|
13
|
+
var PERSIAN_INDIC = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
|
|
14
|
+
var digitSets = {
|
|
15
|
+
western: WESTERN,
|
|
16
|
+
arabicIndic: ARABIC_INDIC,
|
|
17
|
+
persianIndic: PERSIAN_INDIC
|
|
18
|
+
};
|
|
19
|
+
function digitValue(char) {
|
|
20
|
+
const western = WESTERN.indexOf(char);
|
|
21
|
+
if (western >= 0) {
|
|
22
|
+
return western;
|
|
23
|
+
}
|
|
24
|
+
const arabicIndic = ARABIC_INDIC.indexOf(char);
|
|
25
|
+
if (arabicIndic >= 0) {
|
|
26
|
+
return arabicIndic;
|
|
27
|
+
}
|
|
28
|
+
return PERSIAN_INDIC.indexOf(char);
|
|
29
|
+
}
|
|
30
|
+
function formatDigits(value, digitForm = "western") {
|
|
31
|
+
const target = digitSets[digitForm];
|
|
32
|
+
return Array.from(value, (char) => {
|
|
33
|
+
const value2 = digitValue(char);
|
|
34
|
+
return value2 >= 0 ? target[value2] : char;
|
|
35
|
+
}).join("");
|
|
36
|
+
}
|
|
37
|
+
|
|
10
38
|
// src/document/articleMeta.ts
|
|
11
39
|
var BUTEX_BASMALA_LINE1 = "\u0628\u0650\u0633\u0652\u0645\u0650 \u0671\u0644\u0644\u064E\u0651\u0670\u0647\u0650 \u0671\u0644\u0631\u064E\u0651\u062D\u0652\u0645\u064E\u0670\u0646\u0650 \u0671\u0644\u0631\u064E\u0651\u062D\u0650\u064A\u0645\u0650";
|
|
12
40
|
var BUTEX_BASMALA_LINE2 = "\u0648\u064E\u0671\u0644\u0635\u064E\u0651\u0644\u064E\u0627\u0629\u064F \u0648\u064E\u0671\u0644\u0633\u064E\u0651\u0644\u064E\u0627\u0645\u064F \u0639\u064E\u0644\u064E\u0649\u0670 \u0631\u064E\u0633\u064F\u0648\u0644\u0650 \u0671\u0644\u0644\u064E\u0651\u0670\u0647\u0650";
|
|
@@ -125,6 +153,16 @@ function referenceFromJson(json) {
|
|
|
125
153
|
fieldSeparator: normalizeReferenceFieldSeparator(json.field_separator)
|
|
126
154
|
};
|
|
127
155
|
}
|
|
156
|
+
function bibliographyEntryBody(reference, separator = reference.fieldSeparator, options = {}) {
|
|
157
|
+
const year = options.digitForm !== void 0 ? formatDigits(reference.year, options.digitForm) : reference.year;
|
|
158
|
+
const parts = [reference.authors, reference.title, reference.venue, year].filter((part) => part.trim().length > 0);
|
|
159
|
+
return parts.join(`${separator} `);
|
|
160
|
+
}
|
|
161
|
+
function bibliographyEntryLatex(reference) {
|
|
162
|
+
const body = bibliographyEntryBody(reference);
|
|
163
|
+
const url = reference.url.trim().length > 0 ? ` \\url{${reference.url}}` : "";
|
|
164
|
+
return `\\bibitem{${reference.key}} ${body}${url}`.trim();
|
|
165
|
+
}
|
|
128
166
|
|
|
129
167
|
// src/ast/commands/index.ts
|
|
130
168
|
function renderCommandCore(context) {
|
|
@@ -479,6 +517,26 @@ function fromMathObjectJson(json, mode = "english") {
|
|
|
479
517
|
closing: json.closing
|
|
480
518
|
};
|
|
481
519
|
}
|
|
520
|
+
function renderMathNodeLatex(math) {
|
|
521
|
+
const lines = math.lines.map((line) => line.arabicLatex());
|
|
522
|
+
if (math.mathMode === "$" || math.mathMode === "\\(") {
|
|
523
|
+
return math.mathMode + lines.join(" ") + math.closing;
|
|
524
|
+
}
|
|
525
|
+
if (math.mathMode === "$$" || math.mathMode === "\\[") {
|
|
526
|
+
if (lines.length === 1) {
|
|
527
|
+
return math.mathMode + "\n" + lines[0] + "\n" + math.closing;
|
|
528
|
+
}
|
|
529
|
+
return math.mathMode + "\n" + lines.map((line) => ` ${line}`).join(" \\\\\n") + "\n" + math.closing;
|
|
530
|
+
}
|
|
531
|
+
if (lines.length === 1) {
|
|
532
|
+
return `${math.mathMode}
|
|
533
|
+
${lines[0]}
|
|
534
|
+
${math.closing}`;
|
|
535
|
+
}
|
|
536
|
+
return `${math.mathMode}
|
|
537
|
+
${lines.map((line) => ` ${line}`).join(" \\\\\n")}
|
|
538
|
+
${math.closing}`;
|
|
539
|
+
}
|
|
482
540
|
|
|
483
541
|
// src/document/labels.ts
|
|
484
542
|
function parseFloatMetaFromJson(json) {
|
|
@@ -596,6 +654,23 @@ function labelNumberMap(document2) {
|
|
|
596
654
|
}
|
|
597
655
|
return map;
|
|
598
656
|
}
|
|
657
|
+
function stripDisplayMathDelimiters(source) {
|
|
658
|
+
const trimmed = source.trim();
|
|
659
|
+
if (trimmed.startsWith("\\[") && trimmed.endsWith("\\]")) {
|
|
660
|
+
return trimmed.slice(2, -2).trim();
|
|
661
|
+
}
|
|
662
|
+
if (trimmed.startsWith("$$") && trimmed.endsWith("$$")) {
|
|
663
|
+
return trimmed.slice(2, -2).trim();
|
|
664
|
+
}
|
|
665
|
+
for (const environment of ["equation", "equation*"]) {
|
|
666
|
+
const opening = `\\begin{${environment}}`;
|
|
667
|
+
const closing = `\\end{${environment}}`;
|
|
668
|
+
if (trimmed.startsWith(opening) && trimmed.endsWith(closing)) {
|
|
669
|
+
return trimmed.slice(opening.length, -closing.length).trim();
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return trimmed;
|
|
673
|
+
}
|
|
599
674
|
|
|
600
675
|
// src/document/inlineIdentity.ts
|
|
601
676
|
function createDocumentIdentityState() {
|
|
@@ -1245,6 +1320,535 @@ function fromDocumentJson(json, options = {}) {
|
|
|
1245
1320
|
};
|
|
1246
1321
|
}
|
|
1247
1322
|
|
|
1323
|
+
// src/editor/accentCommands.ts
|
|
1324
|
+
var ACCENT_COMMANDS = {
|
|
1325
|
+
vec: {
|
|
1326
|
+
id: "vec",
|
|
1327
|
+
englishTex: "\\vec",
|
|
1328
|
+
arabicTex: "\\arabvec",
|
|
1329
|
+
placement: "over",
|
|
1330
|
+
label: "\u20D7",
|
|
1331
|
+
title: "\u0633\u0647\u0645 \u0641\u0648\u0642"
|
|
1332
|
+
},
|
|
1333
|
+
hat: {
|
|
1334
|
+
id: "hat",
|
|
1335
|
+
englishTex: "\\hat",
|
|
1336
|
+
arabicTex: "\\hat",
|
|
1337
|
+
placement: "over",
|
|
1338
|
+
label: "\u02C6",
|
|
1339
|
+
title: "\u0642\u0628\u0639\u0629"
|
|
1340
|
+
},
|
|
1341
|
+
tilde: {
|
|
1342
|
+
id: "tilde",
|
|
1343
|
+
englishTex: "\\tilde",
|
|
1344
|
+
arabicTex: "\\tilde",
|
|
1345
|
+
placement: "over",
|
|
1346
|
+
label: "\u02DC",
|
|
1347
|
+
title: "\u0645\u062F\u0629"
|
|
1348
|
+
},
|
|
1349
|
+
dot: {
|
|
1350
|
+
id: "dot",
|
|
1351
|
+
englishTex: "\\dot",
|
|
1352
|
+
arabicTex: "\\dot",
|
|
1353
|
+
placement: "over",
|
|
1354
|
+
label: "\u02D9",
|
|
1355
|
+
title: "\u0646\u0642\u0637\u0629 \u0641\u0648\u0642"
|
|
1356
|
+
},
|
|
1357
|
+
ddot: {
|
|
1358
|
+
id: "ddot",
|
|
1359
|
+
englishTex: "\\ddot",
|
|
1360
|
+
arabicTex: "\\ddot",
|
|
1361
|
+
placement: "over",
|
|
1362
|
+
label: "\xA8",
|
|
1363
|
+
title: "\u0646\u0642\u0637\u062A\u0627\u0646 \u0641\u0648\u0642"
|
|
1364
|
+
},
|
|
1365
|
+
dddot: {
|
|
1366
|
+
id: "dddot",
|
|
1367
|
+
englishTex: "\\dddot",
|
|
1368
|
+
arabicTex: "\\dddot",
|
|
1369
|
+
placement: "over",
|
|
1370
|
+
label: "\u20DB",
|
|
1371
|
+
title: "\u062B\u0644\u0627\u062B \u0646\u0642\u0627\u0637 \u0641\u0648\u0642"
|
|
1372
|
+
},
|
|
1373
|
+
bar: {
|
|
1374
|
+
id: "bar",
|
|
1375
|
+
englishTex: "\\bar",
|
|
1376
|
+
arabicTex: "\\bar",
|
|
1377
|
+
placement: "over",
|
|
1378
|
+
label: "\xAF",
|
|
1379
|
+
title: "\u062E\u0637 \u0641\u0648\u0642"
|
|
1380
|
+
},
|
|
1381
|
+
check: {
|
|
1382
|
+
id: "check",
|
|
1383
|
+
englishTex: "\\check",
|
|
1384
|
+
arabicTex: "\\check",
|
|
1385
|
+
placement: "over",
|
|
1386
|
+
label: "\u02C7",
|
|
1387
|
+
title: "\u0639\u0644\u0627\u0645\u0629 \u062A\u062D\u0642\u0642"
|
|
1388
|
+
},
|
|
1389
|
+
breve: {
|
|
1390
|
+
id: "breve",
|
|
1391
|
+
englishTex: "\\breve",
|
|
1392
|
+
arabicTex: "\\breve",
|
|
1393
|
+
placement: "over",
|
|
1394
|
+
label: "\u02D8",
|
|
1395
|
+
title: "\u0642\u0648\u0633 \u0642\u0635\u064A\u0631"
|
|
1396
|
+
},
|
|
1397
|
+
acute: {
|
|
1398
|
+
id: "acute",
|
|
1399
|
+
englishTex: "\\acute",
|
|
1400
|
+
arabicTex: "\\grave",
|
|
1401
|
+
placement: "over",
|
|
1402
|
+
label: "\xB4",
|
|
1403
|
+
title: "\u0646\u0628\u0631\u0629 \u062D\u0627\u062F\u0629"
|
|
1404
|
+
},
|
|
1405
|
+
grave: {
|
|
1406
|
+
id: "grave",
|
|
1407
|
+
englishTex: "\\grave",
|
|
1408
|
+
arabicTex: "\\acute",
|
|
1409
|
+
placement: "over",
|
|
1410
|
+
label: "`",
|
|
1411
|
+
title: "\u0646\u0628\u0631\u0629 \u062B\u0642\u064A\u0644\u0629"
|
|
1412
|
+
},
|
|
1413
|
+
overline: {
|
|
1414
|
+
id: "overline",
|
|
1415
|
+
englishTex: "\\overline",
|
|
1416
|
+
arabicTex: "\\overline",
|
|
1417
|
+
placement: "over",
|
|
1418
|
+
label: "\u203E",
|
|
1419
|
+
title: "\u062E\u0637 \u0639\u0644\u0648\u064A \u0645\u0645\u062A\u062F"
|
|
1420
|
+
},
|
|
1421
|
+
underline: {
|
|
1422
|
+
id: "underline",
|
|
1423
|
+
englishTex: "\\underline",
|
|
1424
|
+
arabicTex: "\\underline",
|
|
1425
|
+
placement: "under",
|
|
1426
|
+
label: "_",
|
|
1427
|
+
title: "\u062E\u0637 \u0633\u0641\u0644\u064A"
|
|
1428
|
+
},
|
|
1429
|
+
overleftarrow: {
|
|
1430
|
+
id: "overleftarrow",
|
|
1431
|
+
englishTex: "\\overleftarrow",
|
|
1432
|
+
arabicTex: "\\overrightarrow",
|
|
1433
|
+
placement: "over",
|
|
1434
|
+
label: "\u2190",
|
|
1435
|
+
title: "\u0633\u0647\u0645 \u0639\u0644\u0648\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631"
|
|
1436
|
+
},
|
|
1437
|
+
overrightarrow: {
|
|
1438
|
+
id: "overrightarrow",
|
|
1439
|
+
englishTex: "\\overrightarrow",
|
|
1440
|
+
arabicTex: "\\overleftarrow",
|
|
1441
|
+
placement: "over",
|
|
1442
|
+
label: "\u2192",
|
|
1443
|
+
title: "\u0633\u0647\u0645 \u0639\u0644\u0648\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646"
|
|
1444
|
+
},
|
|
1445
|
+
overleftrightarrow: {
|
|
1446
|
+
id: "overleftrightarrow",
|
|
1447
|
+
englishTex: "\\overleftrightarrow",
|
|
1448
|
+
arabicTex: "\\overleftrightarrow",
|
|
1449
|
+
placement: "over",
|
|
1450
|
+
label: "\u2194",
|
|
1451
|
+
title: "\u0633\u0647\u0645 \u0639\u0644\u0648\u064A \u0645\u0632\u062F\u0648\u062C \u0627\u0644\u0627\u062A\u062C\u0627\u0647"
|
|
1452
|
+
}
|
|
1453
|
+
};
|
|
1454
|
+
function accentCommandSpec(id) {
|
|
1455
|
+
return Object.prototype.hasOwnProperty.call(ACCENT_COMMANDS, id) ? ACCENT_COMMANDS[id] : null;
|
|
1456
|
+
}
|
|
1457
|
+
function accentCommandIdFromTex(tex) {
|
|
1458
|
+
const normalized = tex.startsWith("\\") ? tex : `\\${tex}`;
|
|
1459
|
+
for (const spec of Object.values(ACCENT_COMMANDS)) {
|
|
1460
|
+
if (spec.englishTex === normalized) {
|
|
1461
|
+
return spec.id;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
for (const spec of Object.values(ACCENT_COMMANDS)) {
|
|
1465
|
+
if (spec.arabicTex === normalized) {
|
|
1466
|
+
return spec.id;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
return null;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// src/editor/atomicCommands.ts
|
|
1473
|
+
var ATOMIC_COMMANDS = {
|
|
1474
|
+
///////////////////////// Functions ////////////////////////////////
|
|
1475
|
+
//////////////// Trigonometric Functions
|
|
1476
|
+
cos: {
|
|
1477
|
+
id: "cos",
|
|
1478
|
+
category: "function",
|
|
1479
|
+
englishTex: "\\cos",
|
|
1480
|
+
arabicTex: "\\arcos",
|
|
1481
|
+
arabicLabel: "\u062C\u062A\u0627",
|
|
1482
|
+
title: "\u062C\u064A\u0628 \u0627\u0644\u062A\u0645\u0627\u0645"
|
|
1483
|
+
},
|
|
1484
|
+
sin: {
|
|
1485
|
+
id: "sin",
|
|
1486
|
+
category: "function",
|
|
1487
|
+
englishTex: "\\sin",
|
|
1488
|
+
arabicTex: "\\arsin",
|
|
1489
|
+
arabicLabel: "\u062C\u0627",
|
|
1490
|
+
title: "\u062C\u064A\u0628"
|
|
1491
|
+
},
|
|
1492
|
+
tan: {
|
|
1493
|
+
id: "tan",
|
|
1494
|
+
category: "function",
|
|
1495
|
+
englishTex: "\\tan",
|
|
1496
|
+
arabicTex: "\\artan",
|
|
1497
|
+
arabicLabel: "\u0638\u0627",
|
|
1498
|
+
title: "\u0638\u0644"
|
|
1499
|
+
},
|
|
1500
|
+
cot: {
|
|
1501
|
+
id: "cot",
|
|
1502
|
+
category: "function",
|
|
1503
|
+
englishTex: "\\cot",
|
|
1504
|
+
arabicTex: "\\arcot",
|
|
1505
|
+
arabicLabel: "\u0638\u062A\u0627",
|
|
1506
|
+
title: "\u0638\u0644 \u062A\u0645\u0627\u0645"
|
|
1507
|
+
},
|
|
1508
|
+
sec: {
|
|
1509
|
+
id: "sec",
|
|
1510
|
+
category: "function",
|
|
1511
|
+
englishTex: "\\sec",
|
|
1512
|
+
arabicTex: "\\arsec",
|
|
1513
|
+
arabicLabel: "\u0642\u0627",
|
|
1514
|
+
title: "\u0642\u0627\u0637\u0639"
|
|
1515
|
+
},
|
|
1516
|
+
csc: {
|
|
1517
|
+
id: "csc",
|
|
1518
|
+
category: "function",
|
|
1519
|
+
englishTex: "\\csc",
|
|
1520
|
+
arabicTex: "\\arcsc",
|
|
1521
|
+
arabicLabel: "\u0642\u062A\u0627",
|
|
1522
|
+
title: "\u0642\u0627\u0637\u0639 \u062A\u0645\u0627\u0645"
|
|
1523
|
+
},
|
|
1524
|
+
/////////////////// Arc Trigonometric Functions
|
|
1525
|
+
arccos: {
|
|
1526
|
+
id: "arccos",
|
|
1527
|
+
category: "function",
|
|
1528
|
+
englishTex: "\\arccos",
|
|
1529
|
+
arabicTex: "\\aracos",
|
|
1530
|
+
arabicLabel: "\u0642\u062C\u062A\u0627",
|
|
1531
|
+
title: "\u0642\u0627\u0637\u0639 \u062C\u064A\u0628 \u0627\u0644\u062A\u0645\u0627\u0645"
|
|
1532
|
+
},
|
|
1533
|
+
arcsin: {
|
|
1534
|
+
id: "arcsin",
|
|
1535
|
+
category: "function",
|
|
1536
|
+
englishTex: "\\arcsin",
|
|
1537
|
+
arabicTex: "\\arasin",
|
|
1538
|
+
arabicLabel: "\u0642\u062C\u0627",
|
|
1539
|
+
title: "\u0642\u0627\u0637\u0639 \u062C\u064A\u0628"
|
|
1540
|
+
},
|
|
1541
|
+
arctan: {
|
|
1542
|
+
id: "arctan",
|
|
1543
|
+
category: "function",
|
|
1544
|
+
englishTex: "\\arctan",
|
|
1545
|
+
arabicTex: "\\aratan",
|
|
1546
|
+
arabicLabel: "\u0642\u0638\u0627",
|
|
1547
|
+
title: "\u0642\u0627\u0637\u0639 \u0638\u0644"
|
|
1548
|
+
},
|
|
1549
|
+
arccot: {
|
|
1550
|
+
id: "arccot",
|
|
1551
|
+
category: "function",
|
|
1552
|
+
englishTex: "\\arccot",
|
|
1553
|
+
arabicTex: "\\aracot",
|
|
1554
|
+
arabicLabel: "\u0642\u0638\u062A\u0627",
|
|
1555
|
+
title: "\u0642\u0627\u0637\u0639 \u0638\u0644 \u0627\u0644\u062A\u0645\u0627\u0645"
|
|
1556
|
+
},
|
|
1557
|
+
arcsec: {
|
|
1558
|
+
id: "arcsec",
|
|
1559
|
+
category: "function",
|
|
1560
|
+
englishTex: "\\arcsec",
|
|
1561
|
+
arabicTex: "\\arasec",
|
|
1562
|
+
arabicLabel: "\u0642\u0642\u0627",
|
|
1563
|
+
title: "\u0642\u0627\u0637\u0639 \u0627\u0644\u0642\u0627\u0637\u0639"
|
|
1564
|
+
},
|
|
1565
|
+
arccsc: {
|
|
1566
|
+
id: "arccsc",
|
|
1567
|
+
category: "function",
|
|
1568
|
+
englishTex: "\\arccsc",
|
|
1569
|
+
arabicTex: "\\aracsc",
|
|
1570
|
+
arabicLabel: "\u0642\u0642\u062A\u0627",
|
|
1571
|
+
title: "\u0642\u0627\u0637\u0639 \u0627\u0644\u0642\u0627\u0637\u0639 \u0627\u0644\u062A\u0645\u0627\u0645"
|
|
1572
|
+
},
|
|
1573
|
+
///////////////// Hyperbolic Functions
|
|
1574
|
+
cosh: {
|
|
1575
|
+
id: "cosh",
|
|
1576
|
+
category: "function",
|
|
1577
|
+
englishTex: "\\cosh",
|
|
1578
|
+
arabicTex: "\\arcosh",
|
|
1579
|
+
arabicLabel: "\u062C\u062A\u0632\u0627",
|
|
1580
|
+
title: "\u062C\u064A\u0628 \u0627\u0644\u062A\u0645\u0627\u0645 \u0627\u0644\u0632\u0627\u0626\u062F"
|
|
1581
|
+
},
|
|
1582
|
+
sinh: {
|
|
1583
|
+
id: "sinh",
|
|
1584
|
+
category: "function",
|
|
1585
|
+
englishTex: "\\sinh",
|
|
1586
|
+
arabicTex: "\\arsinh",
|
|
1587
|
+
arabicLabel: "\u062C\u0632\u0627",
|
|
1588
|
+
title: "\u062C\u064A\u0628 \u0627\u0644\u0632\u0627\u0626\u062F"
|
|
1589
|
+
},
|
|
1590
|
+
tanh: {
|
|
1591
|
+
id: "tanh",
|
|
1592
|
+
category: "function",
|
|
1593
|
+
englishTex: "\\tanh",
|
|
1594
|
+
arabicTex: "\\artanh",
|
|
1595
|
+
arabicLabel: "\u0638\u0632\u0627",
|
|
1596
|
+
title: "\u0638\u0644 \u0627\u0644\u0632\u0627\u0626\u062F"
|
|
1597
|
+
},
|
|
1598
|
+
coth: {
|
|
1599
|
+
id: "coth",
|
|
1600
|
+
category: "function",
|
|
1601
|
+
englishTex: "\\coth",
|
|
1602
|
+
arabicTex: "\\arcoth",
|
|
1603
|
+
arabicLabel: "\u0638\u062A\u0632\u0627",
|
|
1604
|
+
title: "\u0638\u0644 \u062A\u0645\u0627\u0645 \u0627\u0644\u0632\u0627\u0626\u062F"
|
|
1605
|
+
},
|
|
1606
|
+
////// These function somehow doesnt exist in LaTeX and therefore MathJax, skip for now. no problem.
|
|
1607
|
+
// sech: {
|
|
1608
|
+
// id: 'sech',
|
|
1609
|
+
// category: 'function',
|
|
1610
|
+
// englishTex: '\\sech',
|
|
1611
|
+
// arabicTex: '\\arsech',
|
|
1612
|
+
// arabicLabel: 'قزا',
|
|
1613
|
+
// title: 'قاطع الزائد',
|
|
1614
|
+
// },
|
|
1615
|
+
// csch: {
|
|
1616
|
+
// id: 'csch',
|
|
1617
|
+
// category: 'function',
|
|
1618
|
+
// englishTex: '\\csch',
|
|
1619
|
+
// arabicTex: '\\arcsch',
|
|
1620
|
+
// arabicLabel: 'قتزا',
|
|
1621
|
+
// title: 'قاطع تمام الزائد',
|
|
1622
|
+
// },
|
|
1623
|
+
///////////////// arc Hyperbolic Functions
|
|
1624
|
+
///// Not on MathJax, skip for now, it is okay.
|
|
1625
|
+
////////////////////// Limits & Series ////////////////////////////////
|
|
1626
|
+
sum: {
|
|
1627
|
+
id: "sum",
|
|
1628
|
+
category: "limits_series",
|
|
1629
|
+
englishTex: "\\sum",
|
|
1630
|
+
arabicTex: "\\arsum",
|
|
1631
|
+
arabicLabel: "\u0645\u062C\u0640\u0640\u0640",
|
|
1632
|
+
title: "\u0645\u062C\u0645\u0648\u0639"
|
|
1633
|
+
},
|
|
1634
|
+
prod: {
|
|
1635
|
+
id: "prod",
|
|
1636
|
+
category: "limits_series",
|
|
1637
|
+
englishTex: "\\prod",
|
|
1638
|
+
arabicTex: "\\arprod",
|
|
1639
|
+
arabicLabel: "\u062C\u0640\u0640\u0640\u062F",
|
|
1640
|
+
title: "\u062C\u062F\u0627\u0621"
|
|
1641
|
+
},
|
|
1642
|
+
lim: {
|
|
1643
|
+
id: "lim",
|
|
1644
|
+
category: "limits_series",
|
|
1645
|
+
englishTex: "\\lim",
|
|
1646
|
+
arabicTex: "\\arlim",
|
|
1647
|
+
arabicLabel: "\u0646\u0640\u0640\u0640\u0640\u0640\u0647\u0627",
|
|
1648
|
+
title: "\u062D\u062F"
|
|
1649
|
+
},
|
|
1650
|
+
arg: {
|
|
1651
|
+
id: "arg",
|
|
1652
|
+
category: "limits_series",
|
|
1653
|
+
englishTex: "\\arg",
|
|
1654
|
+
arabicTex: "\\ararg",
|
|
1655
|
+
arabicLabel: "\u062D\u062C",
|
|
1656
|
+
title: "\u062D\u062C\u0629"
|
|
1657
|
+
},
|
|
1658
|
+
max: {
|
|
1659
|
+
id: "max",
|
|
1660
|
+
category: "limits_series",
|
|
1661
|
+
englishTex: "\\max",
|
|
1662
|
+
arabicTex: "\\armax",
|
|
1663
|
+
arabicLabel: "\u0623\u0643\u0628\u0631",
|
|
1664
|
+
title: "\u0623\u0643\u0628\u0631"
|
|
1665
|
+
},
|
|
1666
|
+
min: {
|
|
1667
|
+
id: "min",
|
|
1668
|
+
category: "limits_series",
|
|
1669
|
+
englishTex: "\\min",
|
|
1670
|
+
arabicTex: "\\armin",
|
|
1671
|
+
arabicLabel: "\u0623\u0635\u063A\u0631",
|
|
1672
|
+
title: "\u0623\u0635\u063A\u0631"
|
|
1673
|
+
},
|
|
1674
|
+
sup: {
|
|
1675
|
+
id: "sup",
|
|
1676
|
+
category: "limits_series",
|
|
1677
|
+
englishTex: "\\sup",
|
|
1678
|
+
arabicTex: "\\arsup",
|
|
1679
|
+
arabicLabel: "\u0623\u0639\u0644\u0649",
|
|
1680
|
+
title: "\u0623\u0639\u0644\u0649"
|
|
1681
|
+
},
|
|
1682
|
+
inf: {
|
|
1683
|
+
id: "inf",
|
|
1684
|
+
category: "limits_series",
|
|
1685
|
+
englishTex: "\\inf",
|
|
1686
|
+
arabicTex: "\\arinf",
|
|
1687
|
+
arabicLabel: "\u0623\u062F\u0646\u0649",
|
|
1688
|
+
title: "\u0623\u062F\u0646\u0649"
|
|
1689
|
+
},
|
|
1690
|
+
////////////////////// Logarithmic and Exponential and Determinant Functions ////////////////////////////////
|
|
1691
|
+
pi: {
|
|
1692
|
+
id: "pi",
|
|
1693
|
+
category: "function2",
|
|
1694
|
+
englishTex: "\\pi",
|
|
1695
|
+
arabicTex: "\\arpi",
|
|
1696
|
+
arabicLabel: "\u0637",
|
|
1697
|
+
title: "\u0646\u0633\u0628\u0629 \u0627\u0644\u062F\u0627\u0626\u0631\u0629"
|
|
1698
|
+
},
|
|
1699
|
+
exp: {
|
|
1700
|
+
id: "exp",
|
|
1701
|
+
category: "function2",
|
|
1702
|
+
englishTex: "\\exp",
|
|
1703
|
+
arabicTex: "\\arexp",
|
|
1704
|
+
arabicLabel: "\u0647\u0640",
|
|
1705
|
+
title: "\u0623\u0633\u064A\u0629"
|
|
1706
|
+
},
|
|
1707
|
+
ln: {
|
|
1708
|
+
id: "ln",
|
|
1709
|
+
category: "function2",
|
|
1710
|
+
englishTex: "\\ln",
|
|
1711
|
+
arabicTex: "\\arln",
|
|
1712
|
+
arabicRenderTex: "\\prescript{}{\\arexp}{\\arlog}",
|
|
1713
|
+
arabicLabel: "\u0644\u0648",
|
|
1714
|
+
title: "\u0644\u0648\u063A\u0627\u0631\u064A\u062A\u0645 \u0637\u0628\u064A\u0639\u064A"
|
|
1715
|
+
},
|
|
1716
|
+
log: {
|
|
1717
|
+
id: "log",
|
|
1718
|
+
category: "function2",
|
|
1719
|
+
englishTex: "\\log",
|
|
1720
|
+
arabicTex: "\\arlog",
|
|
1721
|
+
arabicLabel: "\u0644\u0648",
|
|
1722
|
+
title: "\u0644\u0648\u063A\u0627\u0631\u064A\u062A\u0645"
|
|
1723
|
+
},
|
|
1724
|
+
det: {
|
|
1725
|
+
id: "det",
|
|
1726
|
+
category: "function2",
|
|
1727
|
+
englishTex: "\\det",
|
|
1728
|
+
arabicTex: "\\ardet",
|
|
1729
|
+
arabicLabel: "\u0645\u062D\u062F\u062F",
|
|
1730
|
+
title: "\u0645\u062D\u062F\u062F"
|
|
1731
|
+
},
|
|
1732
|
+
////////////////////// Derivatives ////////////////////////////////
|
|
1733
|
+
ad: {
|
|
1734
|
+
id: "ad",
|
|
1735
|
+
category: "derivative",
|
|
1736
|
+
englishTex: "\\mathrm{d}",
|
|
1737
|
+
englishLabel: "d",
|
|
1738
|
+
arabicTex: "\\ad",
|
|
1739
|
+
arabicLabel: "\u0621",
|
|
1740
|
+
title: "\u0639\u0644\u0627\u0645\u0629 \u0627\u0644\u0627\u0634\u062A\u0642\u0627\u0642"
|
|
1741
|
+
},
|
|
1742
|
+
////////////////////// Groups /////////////////////////////////
|
|
1743
|
+
N: {
|
|
1744
|
+
id: "N",
|
|
1745
|
+
category: "groups",
|
|
1746
|
+
englishTex: "\\mathbb{N}",
|
|
1747
|
+
arabicTex: "\\arabN",
|
|
1748
|
+
arabicLabel: "\u0637",
|
|
1749
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u0637\u0628\u064A\u0639\u064A\u0629"
|
|
1750
|
+
},
|
|
1751
|
+
Z: {
|
|
1752
|
+
id: "Z",
|
|
1753
|
+
category: "groups",
|
|
1754
|
+
englishTex: "\\mathbb{Z}",
|
|
1755
|
+
arabicTex: "\\arabZ",
|
|
1756
|
+
arabicLabel: "\u0635",
|
|
1757
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u0635\u062D\u064A\u062D\u0629"
|
|
1758
|
+
},
|
|
1759
|
+
Q: {
|
|
1760
|
+
id: "Q",
|
|
1761
|
+
category: "groups",
|
|
1762
|
+
englishTex: "\\mathbb{Q}",
|
|
1763
|
+
arabicTex: "\\arabQ",
|
|
1764
|
+
arabicLabel: "\u0646",
|
|
1765
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u0646\u0633\u0628\u064A\u0629"
|
|
1766
|
+
},
|
|
1767
|
+
R: {
|
|
1768
|
+
id: "R",
|
|
1769
|
+
category: "groups",
|
|
1770
|
+
englishTex: "\\mathbb{R}",
|
|
1771
|
+
arabicTex: "\\arabR",
|
|
1772
|
+
arabicLabel: "\u062D",
|
|
1773
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u062D\u0642\u064A\u0642\u064A\u0629"
|
|
1774
|
+
},
|
|
1775
|
+
C: {
|
|
1776
|
+
id: "C",
|
|
1777
|
+
category: "groups",
|
|
1778
|
+
englishTex: "\\mathbb{C}",
|
|
1779
|
+
arabicTex: "\\arabC",
|
|
1780
|
+
arabicLabel: "\u0639",
|
|
1781
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u0639\u064F\u0642\u062F\u064A\u0629"
|
|
1782
|
+
},
|
|
1783
|
+
H: {
|
|
1784
|
+
id: "H",
|
|
1785
|
+
category: "groups",
|
|
1786
|
+
englishTex: "\\mathbb{H}",
|
|
1787
|
+
arabicTex: "\\arabH",
|
|
1788
|
+
arabicLabel: "\u0631",
|
|
1789
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u0631\u0628\u0627\u0639\u064A\u0629"
|
|
1790
|
+
},
|
|
1791
|
+
////////////////////// Operations ////////////////////////////
|
|
1792
|
+
////////////////////// Spacing ////////////////////////////////
|
|
1793
|
+
negThinSpace: {
|
|
1794
|
+
id: "negThinSpace",
|
|
1795
|
+
category: "spacing",
|
|
1796
|
+
englishTex: "\\!",
|
|
1797
|
+
arabicTex: "\\!",
|
|
1798
|
+
arabicLabel: "",
|
|
1799
|
+
title: "\u0641\u0631\u0627\u063A \u0633\u0627\u0644\u0628 \u0631\u0641\u064A\u0639",
|
|
1800
|
+
spacing: { direction: "negative", level: 1 }
|
|
1801
|
+
},
|
|
1802
|
+
thinSpace: {
|
|
1803
|
+
id: "thinSpace",
|
|
1804
|
+
category: "spacing",
|
|
1805
|
+
englishTex: "\\,",
|
|
1806
|
+
arabicTex: "\\,",
|
|
1807
|
+
arabicLabel: "",
|
|
1808
|
+
title: "\u0641\u0631\u0627\u063A \u0631\u0641\u064A\u0639",
|
|
1809
|
+
spacing: { direction: "positive", level: 1 }
|
|
1810
|
+
},
|
|
1811
|
+
mediumSpace: {
|
|
1812
|
+
id: "mediumSpace",
|
|
1813
|
+
category: "spacing",
|
|
1814
|
+
englishTex: "\\:",
|
|
1815
|
+
arabicTex: "\\:",
|
|
1816
|
+
arabicLabel: "",
|
|
1817
|
+
title: "\u0641\u0631\u0627\u063A \u0645\u062A\u0648\u0633\u0637",
|
|
1818
|
+
spacing: { direction: "positive", level: 1 }
|
|
1819
|
+
},
|
|
1820
|
+
thickSpace: {
|
|
1821
|
+
id: "thickSpace",
|
|
1822
|
+
category: "spacing",
|
|
1823
|
+
englishTex: "\\;",
|
|
1824
|
+
arabicTex: "\\;",
|
|
1825
|
+
arabicLabel: "",
|
|
1826
|
+
title: "\u0641\u0631\u0627\u063A \u0639\u0631\u064A\u0636",
|
|
1827
|
+
spacing: { direction: "positive", level: 2 }
|
|
1828
|
+
},
|
|
1829
|
+
quadSpace: {
|
|
1830
|
+
id: "quadSpace",
|
|
1831
|
+
category: "spacing",
|
|
1832
|
+
englishTex: "\\quad",
|
|
1833
|
+
arabicTex: "\\quad",
|
|
1834
|
+
arabicLabel: "",
|
|
1835
|
+
title: "\u0641\u0631\u0627\u063A \u0643\u0628\u064A\u0631",
|
|
1836
|
+
spacing: { direction: "positive", level: 3 }
|
|
1837
|
+
},
|
|
1838
|
+
qquadSpace: {
|
|
1839
|
+
id: "qquadSpace",
|
|
1840
|
+
category: "spacing",
|
|
1841
|
+
englishTex: "\\qquad",
|
|
1842
|
+
arabicTex: "\\qquad",
|
|
1843
|
+
arabicLabel: "",
|
|
1844
|
+
title: "\u0641\u0631\u0627\u063A \u0643\u0628\u064A\u0631 \u062C\u062F\u0627",
|
|
1845
|
+
spacing: { direction: "positive", level: 4 }
|
|
1846
|
+
}
|
|
1847
|
+
};
|
|
1848
|
+
function atomicCommandSpec(id) {
|
|
1849
|
+
return Object.prototype.hasOwnProperty.call(ATOMIC_COMMANDS, id) ? ATOMIC_COMMANDS[id] : null;
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1248
1852
|
// src/editor/atomicCommandsOperators.ts
|
|
1249
1853
|
var ATOMIC_OPERATOR_COMMANDS = {
|
|
1250
1854
|
inf: {
|
|
@@ -1800,6 +2404,300 @@ var ATOMIC_OPERATOR_COMMANDS = {
|
|
|
1800
2404
|
};
|
|
1801
2405
|
var MIRRORED_OPERATOR_TEX = Object.values(ATOMIC_OPERATOR_COMMANDS).filter((command) => command.mirror).map((command) => command.Tex).sort((a, b) => b.length - a.length);
|
|
1802
2406
|
var COMPILE_MIRRORED_OPERATOR_TEX = Object.values(ATOMIC_OPERATOR_COMMANDS).filter((command) => "compileMirror" in command && command.compileMirror).map((command) => command.Tex).sort((a, b) => b.length - a.length);
|
|
2407
|
+
function matchingMirroredOperatorFrom(tex, index, operatorTexList) {
|
|
2408
|
+
for (const operatorTex of operatorTexList) {
|
|
2409
|
+
if (!tex.startsWith(operatorTex, index)) {
|
|
2410
|
+
continue;
|
|
2411
|
+
}
|
|
2412
|
+
const next = tex[index + operatorTex.length];
|
|
2413
|
+
if (next != null && /[A-Za-z]/.test(next)) {
|
|
2414
|
+
continue;
|
|
2415
|
+
}
|
|
2416
|
+
return operatorTex;
|
|
2417
|
+
}
|
|
2418
|
+
return null;
|
|
2419
|
+
}
|
|
2420
|
+
function findMatchingBrace(tex, openIndex) {
|
|
2421
|
+
let depth = 0;
|
|
2422
|
+
for (let index = openIndex; index < tex.length; index += 1) {
|
|
2423
|
+
const char = tex[index];
|
|
2424
|
+
if (char === "\\") {
|
|
2425
|
+
index += 1;
|
|
2426
|
+
continue;
|
|
2427
|
+
}
|
|
2428
|
+
if (char === "{") {
|
|
2429
|
+
depth += 1;
|
|
2430
|
+
} else if (char === "}") {
|
|
2431
|
+
depth -= 1;
|
|
2432
|
+
if (depth === 0) {
|
|
2433
|
+
return index;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
return -1;
|
|
2438
|
+
}
|
|
2439
|
+
function mirrorBuTeXOperatorsInTex(tex, options = {}) {
|
|
2440
|
+
const mirroredOperatorTex = options.target === "compile" ? COMPILE_MIRRORED_OPERATOR_TEX : MIRRORED_OPERATOR_TEX;
|
|
2441
|
+
let result = "";
|
|
2442
|
+
let index = 0;
|
|
2443
|
+
while (index < tex.length) {
|
|
2444
|
+
if (tex.startsWith("\\butexmirror{", index)) {
|
|
2445
|
+
const end = findMatchingBrace(tex, index + "\\butexmirror".length);
|
|
2446
|
+
if (end !== -1) {
|
|
2447
|
+
const bodyStart = index + "\\butexmirror{".length;
|
|
2448
|
+
const body = tex.slice(bodyStart, end);
|
|
2449
|
+
if (options.target === "compile" && MIRRORED_OPERATOR_TEX.includes(body) && !mirroredOperatorTex.includes(body)) {
|
|
2450
|
+
result += body;
|
|
2451
|
+
} else {
|
|
2452
|
+
result += tex.slice(index, end + 1);
|
|
2453
|
+
}
|
|
2454
|
+
index = end + 1;
|
|
2455
|
+
continue;
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
const operatorTex = matchingMirroredOperatorFrom(tex, index, mirroredOperatorTex);
|
|
2459
|
+
if (operatorTex) {
|
|
2460
|
+
result += `\\butexmirror{${operatorTex}}`;
|
|
2461
|
+
index += operatorTex.length;
|
|
2462
|
+
continue;
|
|
2463
|
+
}
|
|
2464
|
+
result += tex[index];
|
|
2465
|
+
index += 1;
|
|
2466
|
+
}
|
|
2467
|
+
return result;
|
|
2468
|
+
}
|
|
2469
|
+
function atomicOperatorCommandSpec(id) {
|
|
2470
|
+
return Object.prototype.hasOwnProperty.call(ATOMIC_OPERATOR_COMMANDS, id) ? ATOMIC_OPERATOR_COMMANDS[id] : null;
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
// src/editor/standardCommands.ts
|
|
2474
|
+
var STANDARD_COMMANDS = {
|
|
2475
|
+
"\\alpha": { tex: "\\alpha", label: "\u03B1", title: "alpha" },
|
|
2476
|
+
"\\beta": { tex: "\\beta", label: "\u03B2", title: "beta" },
|
|
2477
|
+
"\\gamma": { tex: "\\gamma", label: "\u03B3", title: "gamma" },
|
|
2478
|
+
"\\delta": { tex: "\\delta", label: "\u03B4", title: "delta" },
|
|
2479
|
+
"\\epsilon": { tex: "\\epsilon", label: "\u03B5", title: "epsilon" },
|
|
2480
|
+
"\\eta": { tex: "\\eta", label: "\u03B7", title: "eta" },
|
|
2481
|
+
"\\theta": { tex: "\\theta", label: "\u03B8", title: "theta" },
|
|
2482
|
+
"\\lambda": { tex: "\\lambda", label: "\u03BB", title: "lambda" },
|
|
2483
|
+
"\\mu": { tex: "\\mu", label: "\u03BC", title: "mu" },
|
|
2484
|
+
"\\rho": { tex: "\\rho", label: "\u03C1", title: "rho" },
|
|
2485
|
+
"\\sigma": { tex: "\\sigma", label: "\u03C3", title: "sigma" },
|
|
2486
|
+
"\\tau": { tex: "\\tau", label: "\u03C4", title: "tau" },
|
|
2487
|
+
"\\phi": { tex: "\\phi", label: "\u03C6", title: "phi" },
|
|
2488
|
+
"\\chi": { tex: "\\chi", label: "\u03C7", title: "chi" },
|
|
2489
|
+
"\\psi": { tex: "\\psi", label: "\u03C8", title: "psi" },
|
|
2490
|
+
"\\omega": { tex: "\\omega", label: "\u03C9", title: "omega" },
|
|
2491
|
+
"\\zeta": { tex: "\\zeta", label: "\u03B6", title: "zeta" },
|
|
2492
|
+
"\\nabla": { tex: "\\nabla", label: "\u2207", title: "nabla" },
|
|
2493
|
+
"\\Delta": { tex: "\\Delta", label: "\u0394", title: "Delta" },
|
|
2494
|
+
"\\partial": { tex: "\\partial", label: "\u2202", title: "partial derivative" },
|
|
2495
|
+
"\\Longleftrightarrow": { tex: "\\Longleftrightarrow", label: "\u27FA", title: "long equivalence arrow" },
|
|
2496
|
+
"\\backslash": { tex: "\\backslash", label: "\u2216", title: "reverse solidus" }
|
|
2497
|
+
};
|
|
2498
|
+
function standardCommandSpec(tex) {
|
|
2499
|
+
return Object.prototype.hasOwnProperty.call(STANDARD_COMMANDS, tex) ? STANDARD_COMMANDS[tex] : null;
|
|
2500
|
+
}
|
|
2501
|
+
function isStandardCommandTex(tex) {
|
|
2502
|
+
return standardCommandSpec(tex) !== null;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
// src/editor/factory.ts
|
|
2506
|
+
var nextId2 = 1;
|
|
2507
|
+
function makeId(prefix) {
|
|
2508
|
+
const id = `${prefix}_${String(nextId2)}`;
|
|
2509
|
+
nextId2 += 1;
|
|
2510
|
+
return id;
|
|
2511
|
+
}
|
|
2512
|
+
function createEditorChain(nodes = []) {
|
|
2513
|
+
return {
|
|
2514
|
+
id: makeId("chain"),
|
|
2515
|
+
nodes
|
|
2516
|
+
};
|
|
2517
|
+
}
|
|
2518
|
+
function createEditorNode(kind, expr) {
|
|
2519
|
+
return {
|
|
2520
|
+
id: makeId("node"),
|
|
2521
|
+
kind,
|
|
2522
|
+
expr,
|
|
2523
|
+
characterFont: void 0,
|
|
2524
|
+
superscript: null,
|
|
2525
|
+
subscript: null,
|
|
2526
|
+
leftDelimExpr: "",
|
|
2527
|
+
rightDelimExpr: "",
|
|
2528
|
+
innerExpr: null,
|
|
2529
|
+
numerator: null,
|
|
2530
|
+
denominator: null,
|
|
2531
|
+
radicand: null,
|
|
2532
|
+
rootIndex: null,
|
|
2533
|
+
overExpr: null,
|
|
2534
|
+
underExpr: null,
|
|
2535
|
+
baseExpr: null,
|
|
2536
|
+
envName: null,
|
|
2537
|
+
matrixStyle: null,
|
|
2538
|
+
matrixRows: null,
|
|
2539
|
+
columnAlignments: null
|
|
2540
|
+
};
|
|
2541
|
+
}
|
|
2542
|
+
function createDelimiterNode(leftDelimExpr2, rightDelimExpr2) {
|
|
2543
|
+
return {
|
|
2544
|
+
...createEditorNode("delimiter", ""),
|
|
2545
|
+
leftDelimExpr: leftDelimExpr2,
|
|
2546
|
+
rightDelimExpr: rightDelimExpr2,
|
|
2547
|
+
innerExpr: createEditorChain()
|
|
2548
|
+
};
|
|
2549
|
+
}
|
|
2550
|
+
function createBoxedNode() {
|
|
2551
|
+
return {
|
|
2552
|
+
...createEditorNode("boxed", ""),
|
|
2553
|
+
innerExpr: createEditorChain()
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
2556
|
+
function createFracNode() {
|
|
2557
|
+
return {
|
|
2558
|
+
...createEditorNode("frac", ""),
|
|
2559
|
+
numerator: createEditorChain(),
|
|
2560
|
+
denominator: createEditorChain()
|
|
2561
|
+
};
|
|
2562
|
+
}
|
|
2563
|
+
function createSqrtNode() {
|
|
2564
|
+
return {
|
|
2565
|
+
...createEditorNode("sqrt", ""),
|
|
2566
|
+
radicand: createEditorChain(),
|
|
2567
|
+
rootIndex: createEditorChain()
|
|
2568
|
+
};
|
|
2569
|
+
}
|
|
2570
|
+
function createOversetNode() {
|
|
2571
|
+
return {
|
|
2572
|
+
...createEditorNode("overset", ""),
|
|
2573
|
+
overExpr: createEditorChain(),
|
|
2574
|
+
baseExpr: createEditorChain()
|
|
2575
|
+
};
|
|
2576
|
+
}
|
|
2577
|
+
function createUndersetNode() {
|
|
2578
|
+
return {
|
|
2579
|
+
...createEditorNode("underset", ""),
|
|
2580
|
+
underExpr: createEditorChain(),
|
|
2581
|
+
baseExpr: createEditorChain()
|
|
2582
|
+
};
|
|
2583
|
+
}
|
|
2584
|
+
function createAccentNode(accentId) {
|
|
2585
|
+
return {
|
|
2586
|
+
...createEditorNode("accent", accentId),
|
|
2587
|
+
baseExpr: createEditorChain()
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
function createGridEnvNode(envName, rows, columns, columnAlignments) {
|
|
2591
|
+
const safeRows = Math.max(1, Math.min(12, Math.trunc(rows)));
|
|
2592
|
+
const safeColumns = envName === "cases" ? 2 : Math.max(1, Math.min(12, Math.trunc(columns)));
|
|
2593
|
+
const matrixStyles = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
|
|
2594
|
+
const isMatrix = matrixStyles.has(envName) && envName !== "array" && envName !== "aligned";
|
|
2595
|
+
return {
|
|
2596
|
+
...createEditorNode("env", ""),
|
|
2597
|
+
envName,
|
|
2598
|
+
matrixStyle: isMatrix ? envName : null,
|
|
2599
|
+
matrixRows: Array.from(
|
|
2600
|
+
{ length: safeRows },
|
|
2601
|
+
() => Array.from({ length: safeColumns }, () => createEditorChain())
|
|
2602
|
+
),
|
|
2603
|
+
columnAlignments: envName === "array" ? Array.from({ length: safeColumns }, (_, index) => columnAlignments?.[index] ?? "c") : null
|
|
2604
|
+
};
|
|
2605
|
+
}
|
|
2606
|
+
function cloneEditorSession(session) {
|
|
2607
|
+
return {
|
|
2608
|
+
englishTree: structuredClone(session.englishTree),
|
|
2609
|
+
arabicTree: structuredClone(session.arabicTree),
|
|
2610
|
+
activeSide: session.activeSide,
|
|
2611
|
+
splitLeafTyping: session.splitLeafTyping,
|
|
2612
|
+
forceSplitNextLeaf: session.forceSplitNextLeaf,
|
|
2613
|
+
arabicReverseNumberTyping: session.arabicReverseNumberTyping,
|
|
2614
|
+
currentCharacterFont: session.currentCharacterFont ?? "default",
|
|
2615
|
+
currentCharacterWrapper: session.currentCharacterWrapper ?? null,
|
|
2616
|
+
currentDigitForm: session.currentDigitForm ?? "western",
|
|
2617
|
+
caret: { ...session.caret },
|
|
2618
|
+
selection: session.selection ? { ...session.selection } : null,
|
|
2619
|
+
selectedNodeId: session.selectedNodeId,
|
|
2620
|
+
selectedStructureNodeId: session.selectedStructureNodeId,
|
|
2621
|
+
sync: structuredClone(session.sync),
|
|
2622
|
+
debugLog: session.debugLog.slice()
|
|
2623
|
+
};
|
|
2624
|
+
}
|
|
2625
|
+
function collectNodeIds(chain, ids) {
|
|
2626
|
+
for (const node of chain.nodes) {
|
|
2627
|
+
ids.push(node.id);
|
|
2628
|
+
if (node.superscript) {
|
|
2629
|
+
collectNodeIds(node.superscript, ids);
|
|
2630
|
+
}
|
|
2631
|
+
if (node.subscript) {
|
|
2632
|
+
collectNodeIds(node.subscript, ids);
|
|
2633
|
+
}
|
|
2634
|
+
if (node.innerExpr) {
|
|
2635
|
+
collectNodeIds(node.innerExpr, ids);
|
|
2636
|
+
}
|
|
2637
|
+
if (node.numerator) {
|
|
2638
|
+
collectNodeIds(node.numerator, ids);
|
|
2639
|
+
}
|
|
2640
|
+
if (node.denominator) {
|
|
2641
|
+
collectNodeIds(node.denominator, ids);
|
|
2642
|
+
}
|
|
2643
|
+
if (node.rootIndex) {
|
|
2644
|
+
collectNodeIds(node.rootIndex, ids);
|
|
2645
|
+
}
|
|
2646
|
+
if (node.radicand) {
|
|
2647
|
+
collectNodeIds(node.radicand, ids);
|
|
2648
|
+
}
|
|
2649
|
+
if (node.overExpr) {
|
|
2650
|
+
collectNodeIds(node.overExpr, ids);
|
|
2651
|
+
}
|
|
2652
|
+
if (node.underExpr) {
|
|
2653
|
+
collectNodeIds(node.underExpr, ids);
|
|
2654
|
+
}
|
|
2655
|
+
if (node.baseExpr) {
|
|
2656
|
+
collectNodeIds(node.baseExpr, ids);
|
|
2657
|
+
}
|
|
2658
|
+
if (node.matrixRows) {
|
|
2659
|
+
for (const row of node.matrixRows) {
|
|
2660
|
+
for (const cell of row) {
|
|
2661
|
+
collectNodeIds(cell, ids);
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
function buildInitialSyncMap(englishTree, arabicTree) {
|
|
2668
|
+
const englishIds = [];
|
|
2669
|
+
const arabicIds = [];
|
|
2670
|
+
collectNodeIds(englishTree, englishIds);
|
|
2671
|
+
collectNodeIds(arabicTree, arabicIds);
|
|
2672
|
+
const all = /* @__PURE__ */ new Set([...englishIds, ...arabicIds]);
|
|
2673
|
+
const sync = {};
|
|
2674
|
+
for (const nodeId of all) {
|
|
2675
|
+
sync[nodeId] = { expr: "synced" };
|
|
2676
|
+
}
|
|
2677
|
+
return sync;
|
|
2678
|
+
}
|
|
2679
|
+
function createEditorSession(englishTree, arabicTree, activeSide = "arabic") {
|
|
2680
|
+
return {
|
|
2681
|
+
englishTree,
|
|
2682
|
+
arabicTree,
|
|
2683
|
+
activeSide,
|
|
2684
|
+
splitLeafTyping: false,
|
|
2685
|
+
forceSplitNextLeaf: false,
|
|
2686
|
+
arabicReverseNumberTyping: true,
|
|
2687
|
+
currentCharacterFont: "default",
|
|
2688
|
+
currentCharacterWrapper: null,
|
|
2689
|
+
currentDigitForm: "western",
|
|
2690
|
+
caret: {
|
|
2691
|
+
chainId: englishTree.id,
|
|
2692
|
+
index: 0
|
|
2693
|
+
},
|
|
2694
|
+
selection: null,
|
|
2695
|
+
selectedNodeId: null,
|
|
2696
|
+
selectedStructureNodeId: null,
|
|
2697
|
+
sync: buildInitialSyncMap(englishTree, arabicTree),
|
|
2698
|
+
debugLog: []
|
|
2699
|
+
};
|
|
2700
|
+
}
|
|
1803
2701
|
|
|
1804
2702
|
// src/editor/characterFonts.ts
|
|
1805
2703
|
var CHARACTER_FONT_SPECS = [
|
|
@@ -1865,6 +2763,344 @@ var CHARACTER_FONT_OPTIONS = CHARACTER_FONT_SPECS.map(({ id, label }) => ({ id,
|
|
|
1865
2763
|
var NON_DEFAULT_CHARACTER_FONT_SPECS = CHARACTER_FONT_SPECS.filter(
|
|
1866
2764
|
(font) => font.id !== "default" && typeof font.macro === "string"
|
|
1867
2765
|
);
|
|
2766
|
+
function characterFontSpec(fontId) {
|
|
2767
|
+
return CHARACTER_FONT_SPECS.find((font) => font.id === fontId) ?? CHARACTER_FONT_SPECS[0];
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2770
|
+
// src/editor/divideOperator.ts
|
|
2771
|
+
var DIVIDE_OPERATOR_EN = "/";
|
|
2772
|
+
var DIVIDE_OPERATOR_AR = "\\";
|
|
2773
|
+
var DIVIDE_OPERATOR_AR_LATEX = "\\backslash";
|
|
2774
|
+
function isDivideOperatorExpr(expr) {
|
|
2775
|
+
return expr === DIVIDE_OPERATOR_EN || expr === DIVIDE_OPERATOR_AR || expr === DIVIDE_OPERATOR_AR_LATEX;
|
|
2776
|
+
}
|
|
2777
|
+
function renderDivideOperatorLatex(side) {
|
|
2778
|
+
return side === "arabic" ? "\\backslash" : DIVIDE_OPERATOR_EN;
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
// src/editor/rawOperatorPresentation.ts
|
|
2782
|
+
var RTL_DIRECTIONAL_RAW_OPERATOR_SURFACE = {
|
|
2783
|
+
"<": ">",
|
|
2784
|
+
">": "<"
|
|
2785
|
+
};
|
|
2786
|
+
function renderRawOperatorLatex(expr, side) {
|
|
2787
|
+
if (isDivideOperatorExpr(expr)) {
|
|
2788
|
+
return renderDivideOperatorLatex(side);
|
|
2789
|
+
}
|
|
2790
|
+
if (side === "arabic" && Object.prototype.hasOwnProperty.call(RTL_DIRECTIONAL_RAW_OPERATOR_SURFACE, expr)) {
|
|
2791
|
+
return `\\butexmirror{${expr}}`;
|
|
2792
|
+
}
|
|
2793
|
+
return expr;
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
// src/editor/indexSequence.ts
|
|
2797
|
+
function isIndexComma(node) {
|
|
2798
|
+
return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
|
|
2799
|
+
}
|
|
2800
|
+
function isValidIndexSequence(chain) {
|
|
2801
|
+
let count = 0;
|
|
2802
|
+
let afterComma = false;
|
|
2803
|
+
for (const node of chain.nodes) {
|
|
2804
|
+
if (node.superscript || node.subscript) return false;
|
|
2805
|
+
if (isIndexComma(node)) {
|
|
2806
|
+
if (count === 0 || afterComma) return false;
|
|
2807
|
+
afterComma = true;
|
|
2808
|
+
continue;
|
|
2809
|
+
}
|
|
2810
|
+
const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
|
|
2811
|
+
const identity = node.sourceLatex ?? node.expr;
|
|
2812
|
+
const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
|
|
2813
|
+
if (!isDigit && !isLetter) return false;
|
|
2814
|
+
count += 1;
|
|
2815
|
+
afterComma = false;
|
|
2816
|
+
if (count > 64) return false;
|
|
2817
|
+
}
|
|
2818
|
+
return count >= 2 && !afterComma;
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2821
|
+
// src/editor/render.ts
|
|
2822
|
+
function selectedDigitForm(options) {
|
|
2823
|
+
return options?.digitForm ?? "western";
|
|
2824
|
+
}
|
|
2825
|
+
function latinScripts(node, options) {
|
|
2826
|
+
let scripts = "";
|
|
2827
|
+
if (node.superscript) {
|
|
2828
|
+
scripts += `^{${renderChainEnglish(node.superscript, options)}}`;
|
|
2829
|
+
}
|
|
2830
|
+
if (node.subscript) {
|
|
2831
|
+
scripts += `_{${renderChainEnglish(node.subscript, options)}}`;
|
|
2832
|
+
}
|
|
2833
|
+
return scripts;
|
|
2834
|
+
}
|
|
2835
|
+
function optionalRootIndexEnglish(node, options) {
|
|
2836
|
+
if (!node.rootIndex) {
|
|
2837
|
+
return "";
|
|
2838
|
+
}
|
|
2839
|
+
const rendered = renderChainEnglish(node.rootIndex, options);
|
|
2840
|
+
return rendered === "" ? "" : `[${rendered}]`;
|
|
2841
|
+
}
|
|
2842
|
+
function optionalRootIndexArabic(node, options) {
|
|
2843
|
+
if (!node.rootIndex) {
|
|
2844
|
+
return "";
|
|
2845
|
+
}
|
|
2846
|
+
const rendered = renderChainArabic(node.rootIndex, options);
|
|
2847
|
+
return rendered === "" ? "" : `[${rendered}]`;
|
|
2848
|
+
}
|
|
2849
|
+
function arabicScripts(node, content, options) {
|
|
2850
|
+
const sup = node.superscript ? renderChainArabic(node.superscript, options) : "";
|
|
2851
|
+
const sub = node.subscript ? renderChainArabic(node.subscript, options) : "";
|
|
2852
|
+
if (sup !== "" || sub !== "") {
|
|
2853
|
+
return `\\prescript{${sup}}{${sub}}{${content}}`;
|
|
2854
|
+
}
|
|
2855
|
+
return content;
|
|
2856
|
+
}
|
|
2857
|
+
function renderMatrixRowsEnglish(node, options) {
|
|
2858
|
+
if (!node.matrixRows) {
|
|
2859
|
+
return "";
|
|
2860
|
+
}
|
|
2861
|
+
const envName = node.envName ?? node.matrixStyle;
|
|
2862
|
+
if (!envName) {
|
|
2863
|
+
return "";
|
|
2864
|
+
}
|
|
2865
|
+
const rows = node.matrixRows.map((row) => row.map((cell) => renderChainEnglish(cell, options)).join(" & "));
|
|
2866
|
+
if (envName === "array") {
|
|
2867
|
+
const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows[0]?.length ?? 0).join("");
|
|
2868
|
+
return `\\begin{array}{${spec || "c"}}${rows.join(" \\\\\n")}\\end{array}`;
|
|
2869
|
+
}
|
|
2870
|
+
return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
|
|
2871
|
+
}
|
|
2872
|
+
function reverseAlignmentForArabic(alignment) {
|
|
2873
|
+
if (alignment === "l") {
|
|
2874
|
+
return "r";
|
|
2875
|
+
}
|
|
2876
|
+
if (alignment === "r") {
|
|
2877
|
+
return "l";
|
|
2878
|
+
}
|
|
2879
|
+
return "c";
|
|
2880
|
+
}
|
|
2881
|
+
function renderMatrixRowsArabic(node, options) {
|
|
2882
|
+
if (!node.matrixRows) {
|
|
2883
|
+
return "";
|
|
2884
|
+
}
|
|
2885
|
+
const envName = node.envName ?? node.matrixStyle;
|
|
2886
|
+
if (!envName) {
|
|
2887
|
+
return "";
|
|
2888
|
+
}
|
|
2889
|
+
const rows = node.matrixRows.map(
|
|
2890
|
+
(row) => row.slice().reverse().map((cell) => renderChainArabic(cell, options)).join(" & ")
|
|
2891
|
+
);
|
|
2892
|
+
if (envName === "array") {
|
|
2893
|
+
const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows[0]?.length ?? 0).reverse().map(reverseAlignmentForArabic).join("");
|
|
2894
|
+
return `\\begin{array}{${spec || "c"}}${rows.join(" \\\\\n")}\\end{array}`;
|
|
2895
|
+
}
|
|
2896
|
+
if (envName === "cases" && options?.casesPresentation) {
|
|
2897
|
+
return `\\left.\\begin{array}{rl}${rows.join(" \\\\\n")}\\end{array}\\right\\}`;
|
|
2898
|
+
}
|
|
2899
|
+
return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
|
|
2900
|
+
}
|
|
2901
|
+
function renderAccentEnglish(command, accent, base, options) {
|
|
2902
|
+
const baseTex = base ? renderChainEnglish(base, options) : "";
|
|
2903
|
+
const accentTex = accent ? renderChainEnglish(accent, options) : "";
|
|
2904
|
+
if (accentTex === "") {
|
|
2905
|
+
return baseTex;
|
|
2906
|
+
}
|
|
2907
|
+
return `\\${command}{${accentTex}}{${baseTex}}`;
|
|
2908
|
+
}
|
|
2909
|
+
function renderAccentArabic(command, accent, base, options) {
|
|
2910
|
+
const baseTex = base ? renderChainArabic(base, options) : "";
|
|
2911
|
+
const accentTex = accent ? renderChainArabic(accent, options) : "";
|
|
2912
|
+
if (accentTex === "") {
|
|
2913
|
+
return baseTex;
|
|
2914
|
+
}
|
|
2915
|
+
return `\\${command}{${accentTex}}{${baseTex}}`;
|
|
2916
|
+
}
|
|
2917
|
+
function escapeText(s) {
|
|
2918
|
+
return s.replace(/\\/g, "\\textbackslash{}").replace(/[{}]/g, "\\$&");
|
|
2919
|
+
}
|
|
2920
|
+
function escapeAtomicLiteral(text) {
|
|
2921
|
+
const unescaped = text.replace(/\\([%_&#{}$])/g, "$1");
|
|
2922
|
+
return escapeText(unescaped).replace(/[%_&#$]/g, "\\$&");
|
|
2923
|
+
}
|
|
2924
|
+
function renderCharContent(node, options) {
|
|
2925
|
+
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
2926
|
+
const font = node.characterFont ?? "default";
|
|
2927
|
+
const macro = characterFontSpec(font).macro;
|
|
2928
|
+
if (macro) {
|
|
2929
|
+
return `${macro}{${escapeText(expr)}}`;
|
|
2930
|
+
}
|
|
2931
|
+
return expr;
|
|
2932
|
+
}
|
|
2933
|
+
function renderNodeEnglish(node, options) {
|
|
2934
|
+
if (node.kind === "delimiter" && node.innerExpr) {
|
|
2935
|
+
return `${node.leftDelimExpr} ${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
|
|
2936
|
+
}
|
|
2937
|
+
if (node.kind === "boxed" && node.innerExpr) {
|
|
2938
|
+
const body = `\\boxed{${renderChainEnglish(node.innerExpr, options)}}`;
|
|
2939
|
+
return `${body}${latinScripts(node, options)}`;
|
|
2940
|
+
}
|
|
2941
|
+
if (node.kind === "frac" && node.numerator && node.denominator) {
|
|
2942
|
+
const body = `\\frac{${renderChainEnglish(node.numerator, options)}}{${renderChainEnglish(node.denominator, options)}}`;
|
|
2943
|
+
return `${body}${latinScripts(node, options)}`;
|
|
2944
|
+
}
|
|
2945
|
+
if (node.kind === "sqrt" && node.radicand) {
|
|
2946
|
+
const body = `\\sqrt${optionalRootIndexEnglish(node, options)}{${renderChainEnglish(node.radicand, options)}}`;
|
|
2947
|
+
return `${body}${latinScripts(node, options)}`;
|
|
2948
|
+
}
|
|
2949
|
+
if (node.kind === "overset" && node.baseExpr) {
|
|
2950
|
+
const body = renderAccentEnglish("overset", node.overExpr, node.baseExpr, options);
|
|
2951
|
+
return `${body}${latinScripts(node, options)}`;
|
|
2952
|
+
}
|
|
2953
|
+
if (node.kind === "underset" && node.baseExpr) {
|
|
2954
|
+
const body = renderAccentEnglish("underset", node.underExpr, node.baseExpr, options);
|
|
2955
|
+
return `${body}${latinScripts(node, options)}`;
|
|
2956
|
+
}
|
|
2957
|
+
if (node.kind === "accent" && node.baseExpr) {
|
|
2958
|
+
const cmd = accentCommandSpec(node.expr)?.englishTex ?? `\\${node.expr}`;
|
|
2959
|
+
const body = `${cmd}{${renderChainEnglish(node.baseExpr, options)}}`;
|
|
2960
|
+
return `${body}${latinScripts(node, options)}`;
|
|
2961
|
+
}
|
|
2962
|
+
if (node.kind === "env") {
|
|
2963
|
+
return `${renderMatrixRowsEnglish(node, options)}${latinScripts(node, options)}`;
|
|
2964
|
+
}
|
|
2965
|
+
if (node.kind === "atomicCommand") {
|
|
2966
|
+
const body = atomicCommandSpec(node.expr)?.englishTex ?? node.expr;
|
|
2967
|
+
return `${body}${latinScripts(node, options)}`;
|
|
2968
|
+
}
|
|
2969
|
+
if (node.kind === "atomicOperatorCommand") {
|
|
2970
|
+
const body = node.sourceLatex === "\\le" || node.sourceLatex === "\\ge" ? node.sourceLatex : atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
|
|
2971
|
+
return `${body}${latinScripts(node, options)}`;
|
|
2972
|
+
}
|
|
2973
|
+
if (node.kind === "standardCommand") {
|
|
2974
|
+
return `${node.expr}${latinScripts(node, options)}`;
|
|
2975
|
+
}
|
|
2976
|
+
if (node.kind === "char") {
|
|
2977
|
+
if (node.sourceLatex) {
|
|
2978
|
+
if (node.wrapperCommand === "\\boldarabic" || node.wrapperCommand === "\\mathbf") {
|
|
2979
|
+
const boldSource = node.sourceLatex.startsWith("\\mathbf{") ? node.sourceLatex : `\\mathbf{${node.sourceLatex}}`;
|
|
2980
|
+
return `${boldSource}${latinScripts(node, options)}`;
|
|
2981
|
+
}
|
|
2982
|
+
return `${node.sourceLatex}${latinScripts(node, options)}`;
|
|
2983
|
+
}
|
|
2984
|
+
if (node.wrapperCommand) {
|
|
2985
|
+
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
2986
|
+
const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
|
|
2987
|
+
const escaped = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : escapeText(expr);
|
|
2988
|
+
return `${wrapper}{${escaped}}${latinScripts(node, options)}`;
|
|
2989
|
+
}
|
|
2990
|
+
return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
|
|
2991
|
+
}
|
|
2992
|
+
if (node.kind === "operator") {
|
|
2993
|
+
return `${renderRawOperatorLatex(node.expr, "english")}${latinScripts(node, options)}`;
|
|
2994
|
+
}
|
|
2995
|
+
return `${formatDigits(node.expr, selectedDigitForm(options))}${latinScripts(node, options)}`;
|
|
2996
|
+
}
|
|
2997
|
+
function renderNodeArabic(node, options) {
|
|
2998
|
+
if (node.kind === "delimiter" && node.innerExpr) {
|
|
2999
|
+
const content = `${node.leftDelimExpr}${renderChainArabic(node.innerExpr, options)}${node.rightDelimExpr}`;
|
|
3000
|
+
return arabicScripts(node, content, options);
|
|
3001
|
+
}
|
|
3002
|
+
if (node.kind === "boxed" && node.innerExpr) {
|
|
3003
|
+
const content = `\\boxed{${renderChainArabic(node.innerExpr, options)}}`;
|
|
3004
|
+
return arabicScripts(node, content, options);
|
|
3005
|
+
}
|
|
3006
|
+
if (node.kind === "frac" && node.numerator && node.denominator) {
|
|
3007
|
+
const content = `\\frac{${renderChainArabic(node.numerator, options)}}{${renderChainArabic(node.denominator, options)}}`;
|
|
3008
|
+
return arabicScripts(node, content, options);
|
|
3009
|
+
}
|
|
3010
|
+
if (node.kind === "sqrt" && node.radicand) {
|
|
3011
|
+
const content = `\\arsqrt${optionalRootIndexArabic(node, options)}{${renderChainArabic(node.radicand, options)}}`;
|
|
3012
|
+
return arabicScripts(node, content, options);
|
|
3013
|
+
}
|
|
3014
|
+
if (node.kind === "overset" && node.baseExpr) {
|
|
3015
|
+
const content = renderAccentArabic("overset", node.overExpr, node.baseExpr, options);
|
|
3016
|
+
return arabicScripts(node, content, options);
|
|
3017
|
+
}
|
|
3018
|
+
if (node.kind === "underset" && node.baseExpr) {
|
|
3019
|
+
const content = renderAccentArabic("underset", node.underExpr, node.baseExpr, options);
|
|
3020
|
+
return arabicScripts(node, content, options);
|
|
3021
|
+
}
|
|
3022
|
+
if (node.kind === "accent" && node.baseExpr) {
|
|
3023
|
+
const cmd = accentCommandSpec(node.expr)?.arabicTex ?? `\\${node.expr}`;
|
|
3024
|
+
const content = `${cmd}{${renderChainArabic(node.baseExpr, options)}}`;
|
|
3025
|
+
return arabicScripts(node, content, options);
|
|
3026
|
+
}
|
|
3027
|
+
if (node.kind === "env") {
|
|
3028
|
+
return arabicScripts(node, renderMatrixRowsArabic(node, options), options);
|
|
3029
|
+
}
|
|
3030
|
+
if (node.kind === "atomicCommand") {
|
|
3031
|
+
const spec = atomicCommandSpec(node.expr);
|
|
3032
|
+
const content = spec?.arabicRenderTex ?? spec?.arabicTex ?? node.expr;
|
|
3033
|
+
return arabicScripts(node, content, options);
|
|
3034
|
+
}
|
|
3035
|
+
if (node.kind === "atomicOperatorCommand") {
|
|
3036
|
+
const spec = atomicOperatorCommandSpec(node.expr);
|
|
3037
|
+
const tex = spec?.Tex ?? node.expr;
|
|
3038
|
+
const content = spec?.mirror ? `\\butexmirror{${tex}}` : tex;
|
|
3039
|
+
return arabicScripts(node, content, options);
|
|
3040
|
+
}
|
|
3041
|
+
if (node.kind === "standardCommand") {
|
|
3042
|
+
return arabicScripts(node, node.expr, options);
|
|
3043
|
+
}
|
|
3044
|
+
if (node.kind === "char") {
|
|
3045
|
+
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3046
|
+
const content = renderCharContent(node, options);
|
|
3047
|
+
if (node.wrapperCommand) {
|
|
3048
|
+
const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
|
|
3049
|
+
const literal = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : content;
|
|
3050
|
+
return arabicScripts(node, `${wrapper}{${literal}}`, options);
|
|
3051
|
+
}
|
|
3052
|
+
return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
|
|
3053
|
+
}
|
|
3054
|
+
if (node.kind === "operator") {
|
|
3055
|
+
return arabicScripts(node, renderRawOperatorLatex(node.expr, "arabic"), options);
|
|
3056
|
+
}
|
|
3057
|
+
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
3058
|
+
}
|
|
3059
|
+
function renderChainEnglish(chain, options) {
|
|
3060
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
3061
|
+
const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
|
|
3062
|
+
return "\\mathnormal{" + atoms.join("") + "}";
|
|
3063
|
+
}
|
|
3064
|
+
return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
|
|
3065
|
+
}
|
|
3066
|
+
function renderChainArabic(chain, options) {
|
|
3067
|
+
const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
|
|
3068
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
3069
|
+
return "\\mathnormal{" + rendered.join("\\,") + "}";
|
|
3070
|
+
}
|
|
3071
|
+
return rendered.join(" ");
|
|
3072
|
+
}
|
|
3073
|
+
function renderEnglishLatexFromSession(session) {
|
|
3074
|
+
return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
3075
|
+
}
|
|
3076
|
+
function renderArabicLatexFromSession(session) {
|
|
3077
|
+
return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
3078
|
+
}
|
|
3079
|
+
function renderArabicPreviewLatexFromSession(session) {
|
|
3080
|
+
return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western", casesPresentation: true });
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
// src/editor/state.ts
|
|
3084
|
+
function appendDebug(session, command, note) {
|
|
3085
|
+
const entry = {
|
|
3086
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3087
|
+
command,
|
|
3088
|
+
activeSide: session.activeSide,
|
|
3089
|
+
englishLatex: renderEnglishLatexFromSession(session),
|
|
3090
|
+
arabicLatex: renderArabicLatexFromSession(session),
|
|
3091
|
+
renderOk: true,
|
|
3092
|
+
renderError: null,
|
|
3093
|
+
note
|
|
3094
|
+
};
|
|
3095
|
+
const nextLog = session.debugLog.concat(entry);
|
|
3096
|
+
session.debugLog = nextLog.slice(-120);
|
|
3097
|
+
}
|
|
3098
|
+
function setCurrentDigitForm(session, digitForm) {
|
|
3099
|
+
const next = cloneEditorSession(session);
|
|
3100
|
+
next.currentDigitForm = digitForm;
|
|
3101
|
+
appendDebug(next, "setCurrentDigitForm", digitForm);
|
|
3102
|
+
return next;
|
|
3103
|
+
}
|
|
1868
3104
|
|
|
1869
3105
|
// src/editor/display/delimiter.ts
|
|
1870
3106
|
var DELIMITER_CSS = `
|
|
@@ -2636,8 +3872,63 @@ var WRAPPER_SPECS = [
|
|
|
2636
3872
|
]),
|
|
2637
3873
|
{ prefix: "\\text" }
|
|
2638
3874
|
];
|
|
2639
|
-
|
|
2640
|
-
|
|
3875
|
+
function readBracedArg(source, openBraceIndex) {
|
|
3876
|
+
if (source[openBraceIndex] !== "{") {
|
|
3877
|
+
return null;
|
|
3878
|
+
}
|
|
3879
|
+
let depth = 0;
|
|
3880
|
+
for (let index = openBraceIndex; index < source.length; index += 1) {
|
|
3881
|
+
const char = source[index];
|
|
3882
|
+
if (char === "{") {
|
|
3883
|
+
depth += 1;
|
|
3884
|
+
} else if (char === "}") {
|
|
3885
|
+
depth -= 1;
|
|
3886
|
+
if (depth === 0) {
|
|
3887
|
+
return { inner: source.slice(openBraceIndex + 1, index), end: index + 1 };
|
|
3888
|
+
}
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3891
|
+
return null;
|
|
3892
|
+
}
|
|
3893
|
+
function peelWrapper(source) {
|
|
3894
|
+
for (const wrapper of WRAPPER_SPECS) {
|
|
3895
|
+
if (!source.startsWith(wrapper.prefix)) {
|
|
3896
|
+
continue;
|
|
3897
|
+
}
|
|
3898
|
+
const braced = readBracedArg(source, wrapper.prefix.length);
|
|
3899
|
+
if (!braced || braced.end !== source.length) {
|
|
3900
|
+
continue;
|
|
3901
|
+
}
|
|
3902
|
+
return { inner: braced.inner, font: wrapper.font };
|
|
3903
|
+
}
|
|
3904
|
+
return null;
|
|
3905
|
+
}
|
|
3906
|
+
function normalizeCharImportExpr(expr) {
|
|
3907
|
+
const original = expr;
|
|
3908
|
+
let current = expr;
|
|
3909
|
+
let characterFont = "default";
|
|
3910
|
+
let changed = false;
|
|
3911
|
+
while (true) {
|
|
3912
|
+
const peeled = peelWrapper(current);
|
|
3913
|
+
if (!peeled) {
|
|
3914
|
+
break;
|
|
3915
|
+
}
|
|
3916
|
+
current = peeled.inner;
|
|
3917
|
+
if (peeled.font) {
|
|
3918
|
+
characterFont = peeled.font;
|
|
3919
|
+
}
|
|
3920
|
+
changed = true;
|
|
3921
|
+
}
|
|
3922
|
+
if (!changed) {
|
|
3923
|
+
return { expr: original, characterFont: "default" };
|
|
3924
|
+
}
|
|
3925
|
+
if (current.includes("\\")) {
|
|
3926
|
+
return { expr: original, characterFont: "default" };
|
|
3927
|
+
}
|
|
3928
|
+
return { expr: current, characterFont };
|
|
3929
|
+
}
|
|
3930
|
+
|
|
3931
|
+
// src/shared/math-document/mathEditorAdapter.ts
|
|
2641
3932
|
var COMMAND_FONT_MAP = Object.fromEntries([
|
|
2642
3933
|
["\\text", "infer"],
|
|
2643
3934
|
...NON_DEFAULT_CHARACTER_FONT_SPECS.flatMap((font) => [
|
|
@@ -2648,6 +3939,535 @@ var COMMAND_FONT_MAP = Object.fromEntries([
|
|
|
2648
3939
|
var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
|
|
2649
3940
|
NON_DEFAULT_CHARACTER_FONT_SPECS.map((font) => [font.id, font.macro])
|
|
2650
3941
|
);
|
|
3942
|
+
function commandIdForTex(tex) {
|
|
3943
|
+
for (const spec of Object.values(ATOMIC_COMMANDS)) {
|
|
3944
|
+
const renderTex = spec.arabicRenderTex;
|
|
3945
|
+
if (spec.englishTex === tex || spec.arabicTex === tex || renderTex === tex) {
|
|
3946
|
+
return spec.id;
|
|
3947
|
+
}
|
|
3948
|
+
}
|
|
3949
|
+
return null;
|
|
3950
|
+
}
|
|
3951
|
+
function operatorCommandIdForTex(tex) {
|
|
3952
|
+
const normalized = tex === "\\le" ? "\\leq" : tex === "\\ge" ? "\\geq" : tex;
|
|
3953
|
+
for (const spec of Object.values(ATOMIC_OPERATOR_COMMANDS)) {
|
|
3954
|
+
if (spec.Tex === normalized) {
|
|
3955
|
+
return spec.id;
|
|
3956
|
+
}
|
|
3957
|
+
}
|
|
3958
|
+
return null;
|
|
3959
|
+
}
|
|
3960
|
+
function cloneChainWithFreshIds(chain) {
|
|
3961
|
+
return structuredClone(chain);
|
|
3962
|
+
}
|
|
3963
|
+
function attachScripts(astNode, editorNode) {
|
|
3964
|
+
if (astNode.sourceLatex) {
|
|
3965
|
+
editorNode.sourceLatex = astNode.sourceLatex;
|
|
3966
|
+
}
|
|
3967
|
+
if (astNode.superscript) {
|
|
3968
|
+
const sup = chainToEditorChain(astNode.superscript, true);
|
|
3969
|
+
if (!sup.editable) {
|
|
3970
|
+
return sup;
|
|
3971
|
+
}
|
|
3972
|
+
editorNode.superscript = sup.chain;
|
|
3973
|
+
}
|
|
3974
|
+
if (astNode.subscript) {
|
|
3975
|
+
const sub = chainToEditorChain(astNode.subscript, true);
|
|
3976
|
+
if (!sub.editable) {
|
|
3977
|
+
return sub;
|
|
3978
|
+
}
|
|
3979
|
+
editorNode.subscript = sub.chain;
|
|
3980
|
+
}
|
|
3981
|
+
return null;
|
|
3982
|
+
}
|
|
3983
|
+
var MATRIX_ENV_NAMES = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
|
|
3984
|
+
function isGridEnvName(value) {
|
|
3985
|
+
return MATRIX_ENV_NAMES.has(value) || value === "array" || value === "aligned" || value === "cases";
|
|
3986
|
+
}
|
|
3987
|
+
function isMatrixEnvName(value) {
|
|
3988
|
+
return MATRIX_ENV_NAMES.has(value);
|
|
3989
|
+
}
|
|
3990
|
+
function parseEnvOpening(opening) {
|
|
3991
|
+
const match = /^\\begin\{([^}]+)\}(?:\{([lcr]+)\})?$/.exec(opening);
|
|
3992
|
+
if (!match) {
|
|
3993
|
+
return null;
|
|
3994
|
+
}
|
|
3995
|
+
const envName = match[1] ?? "";
|
|
3996
|
+
if (!isGridEnvName(envName)) {
|
|
3997
|
+
return null;
|
|
3998
|
+
}
|
|
3999
|
+
if (envName === "array") {
|
|
4000
|
+
const spec = match[2] ?? "c";
|
|
4001
|
+
return {
|
|
4002
|
+
envName,
|
|
4003
|
+
alignments: spec.split("").map((alignment) => alignment)
|
|
4004
|
+
};
|
|
4005
|
+
}
|
|
4006
|
+
return { envName };
|
|
4007
|
+
}
|
|
4008
|
+
function splitEnvLine(line) {
|
|
4009
|
+
const cells = [];
|
|
4010
|
+
let current = [];
|
|
4011
|
+
for (const node of line.chain) {
|
|
4012
|
+
if (node instanceof OperatorNode && node.expr === "&") {
|
|
4013
|
+
cells.push(new ChainNode(current));
|
|
4014
|
+
current = [];
|
|
4015
|
+
} else {
|
|
4016
|
+
current.push(node);
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4019
|
+
cells.push(new ChainNode(current));
|
|
4020
|
+
return cells;
|
|
4021
|
+
}
|
|
4022
|
+
function envToEditorNode(node) {
|
|
4023
|
+
const parsed = parseEnvOpening(node.opening);
|
|
4024
|
+
if (!parsed) {
|
|
4025
|
+
return { editable: false, reason: `\u0628\u064A\u0626\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627: ${node.opening}` };
|
|
4026
|
+
}
|
|
4027
|
+
const expectedClosing = `\\end{${parsed.envName}}`;
|
|
4028
|
+
if (node.closing !== expectedClosing) {
|
|
4029
|
+
return { editable: false, reason: `\u0625\u063A\u0644\u0627\u0642 \u0628\u064A\u0626\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.closing}` };
|
|
4030
|
+
}
|
|
4031
|
+
const rowCells = node.lines.map(splitEnvLine);
|
|
4032
|
+
if (parsed.envName === "cases" && (rowCells.length === 0 || rowCells.length > 12 || rowCells.some((row) => row.length !== 2))) {
|
|
4033
|
+
return { editable: false, reason: "\u0628\u064A\u0626\u0629 cases \u062A\u062A\u0637\u0644\u0628 \u062A\u0639\u0628\u064A\u0631\u0627 \u0648\u0634\u0631\u0637\u0627 \u0641\u064A \u0643\u0644 \u0635\u0641 (\u0639\u0645\u0648\u062F\u0627\u0646)" };
|
|
4034
|
+
}
|
|
4035
|
+
const rows = Math.max(1, rowCells.length);
|
|
4036
|
+
const columns = Math.max(1, ...rowCells.map((row) => row.length));
|
|
4037
|
+
const env = createGridEnvNode(parsed.envName, rows, columns, parsed.alignments);
|
|
4038
|
+
for (let rowIndex = 0; rowIndex < rows; rowIndex += 1) {
|
|
4039
|
+
const row = rowCells[rowIndex] ?? [];
|
|
4040
|
+
for (let columnIndex = 0; columnIndex < columns; columnIndex += 1) {
|
|
4041
|
+
const cell = chainToEditorChain(row[columnIndex] ?? new ChainNode());
|
|
4042
|
+
if (!cell.editable) {
|
|
4043
|
+
return cell;
|
|
4044
|
+
}
|
|
4045
|
+
env.matrixRows[rowIndex][columnIndex] = cell.chain;
|
|
4046
|
+
}
|
|
4047
|
+
}
|
|
4048
|
+
if (parsed.envName === "array") {
|
|
4049
|
+
env.columnAlignments = Array.from(
|
|
4050
|
+
{ length: columns },
|
|
4051
|
+
(_, index) => parsed.alignments?.[index] ?? "c"
|
|
4052
|
+
);
|
|
4053
|
+
}
|
|
4054
|
+
if (isMatrixEnvName(parsed.envName)) {
|
|
4055
|
+
env.matrixStyle = parsed.envName;
|
|
4056
|
+
}
|
|
4057
|
+
const scripts = attachScripts(node, env);
|
|
4058
|
+
return scripts ?? { editable: true, node: env };
|
|
4059
|
+
}
|
|
4060
|
+
function charFromTextLikeCommand(node) {
|
|
4061
|
+
const commandFont = COMMAND_FONT_MAP[node.name];
|
|
4062
|
+
if (commandFont === void 0) {
|
|
4063
|
+
return null;
|
|
4064
|
+
}
|
|
4065
|
+
if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
|
|
4066
|
+
return null;
|
|
4067
|
+
}
|
|
4068
|
+
const arg = node.mandatoryArgs[0];
|
|
4069
|
+
if (arg.chain.length !== 1) {
|
|
4070
|
+
return null;
|
|
4071
|
+
}
|
|
4072
|
+
const child = arg.chain[0];
|
|
4073
|
+
if (child instanceof CommandNode) {
|
|
4074
|
+
const nested = charFromTextLikeCommand(child);
|
|
4075
|
+
if (!nested?.editable) {
|
|
4076
|
+
return null;
|
|
4077
|
+
}
|
|
4078
|
+
if (commandFont !== "infer") {
|
|
4079
|
+
nested.node.characterFont = commandFont;
|
|
4080
|
+
}
|
|
4081
|
+
const scripts2 = attachScripts(node, nested.node);
|
|
4082
|
+
return scripts2 ?? nested;
|
|
4083
|
+
}
|
|
4084
|
+
if (!(child instanceof CharNode)) {
|
|
4085
|
+
return null;
|
|
4086
|
+
}
|
|
4087
|
+
const normalized = normalizeCharImportExpr(child.expr);
|
|
4088
|
+
const characterFont = commandFont === "infer" ? normalized.characterFont : commandFont;
|
|
4089
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
4090
|
+
if (characterFont !== "default") {
|
|
4091
|
+
editorNode.characterFont = characterFont;
|
|
4092
|
+
}
|
|
4093
|
+
const scripts = attachScripts(node, editorNode);
|
|
4094
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
4095
|
+
}
|
|
4096
|
+
function singleCommandChar(node) {
|
|
4097
|
+
if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
|
|
4098
|
+
return null;
|
|
4099
|
+
}
|
|
4100
|
+
const arg = node.mandatoryArgs[0];
|
|
4101
|
+
if (arg.chain.length !== 1 || !(arg.chain[0] instanceof CharNode)) {
|
|
4102
|
+
return null;
|
|
4103
|
+
}
|
|
4104
|
+
return arg.chain[0];
|
|
4105
|
+
}
|
|
4106
|
+
function wrappedAtomicCommandId(node) {
|
|
4107
|
+
if (node.name !== "\\mathbb" && node.name !== "\\mathrm") {
|
|
4108
|
+
return null;
|
|
4109
|
+
}
|
|
4110
|
+
const child = singleCommandChar(node);
|
|
4111
|
+
if (!child) {
|
|
4112
|
+
return null;
|
|
4113
|
+
}
|
|
4114
|
+
return commandIdForTex(`${node.name}{${child.expr}}`);
|
|
4115
|
+
}
|
|
4116
|
+
function editableWrapperCommand(node) {
|
|
4117
|
+
if (node.name !== "\\mathtt" && node.name !== "\\operatorname" && node.name !== "\\text" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
|
|
4118
|
+
return null;
|
|
4119
|
+
}
|
|
4120
|
+
if (node.name === "\\text" && node.sourceLatex && !node.sourceLatex.startsWith("\\text{")) {
|
|
4121
|
+
return null;
|
|
4122
|
+
}
|
|
4123
|
+
const child = singleCommandChar(node);
|
|
4124
|
+
if (node.name === "\\text" && child?.sourceLatex && !node.sourceLatex) return null;
|
|
4125
|
+
let editorNode;
|
|
4126
|
+
if (child) {
|
|
4127
|
+
const normalized = normalizeCharImportExpr(child.expr);
|
|
4128
|
+
editorNode = createEditorNode("char", normalized.expr);
|
|
4129
|
+
if (child.sourceLatex) editorNode.sourceLatex = child.sourceLatex;
|
|
4130
|
+
if (normalized.characterFont !== "default") {
|
|
4131
|
+
editorNode.characterFont = normalized.characterFont;
|
|
4132
|
+
}
|
|
4133
|
+
} else {
|
|
4134
|
+
if (node.optionalArgs.length || node.mandatoryArgs.length !== 1) return null;
|
|
4135
|
+
const nodes = node.mandatoryArgs[0]?.chain;
|
|
4136
|
+
if (!nodes || nodes.length !== 1 || !(nodes[0] instanceof CommandNode)) return null;
|
|
4137
|
+
const nested = charFromTextLikeCommand(nodes[0]);
|
|
4138
|
+
if (!nested?.editable) return null;
|
|
4139
|
+
editorNode = nested.node;
|
|
4140
|
+
}
|
|
4141
|
+
editorNode.wrapperCommand = node.name === "\\mathsf" ? "\\unit" : node.name;
|
|
4142
|
+
const scripts = attachScripts(node, editorNode);
|
|
4143
|
+
if (scripts) {
|
|
4144
|
+
return scripts;
|
|
4145
|
+
}
|
|
4146
|
+
if (!editorNode.sourceLatex && node.name === "\\mathsf" && child) {
|
|
4147
|
+
editorNode.sourceLatex = `\\mathsf{${child.expr}}`;
|
|
4148
|
+
}
|
|
4149
|
+
return { editable: true, node: editorNode };
|
|
4150
|
+
}
|
|
4151
|
+
function commandToEditorNode(node) {
|
|
4152
|
+
if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
|
|
4153
|
+
const frac = createFracNode();
|
|
4154
|
+
const numerator = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4155
|
+
const denominator = chainToEditorChain(node.mandatoryArgs[1]);
|
|
4156
|
+
if (!numerator.editable) {
|
|
4157
|
+
return numerator;
|
|
4158
|
+
}
|
|
4159
|
+
if (!denominator.editable) {
|
|
4160
|
+
return denominator;
|
|
4161
|
+
}
|
|
4162
|
+
frac.numerator = numerator.chain;
|
|
4163
|
+
frac.denominator = denominator.chain;
|
|
4164
|
+
const scripts = attachScripts(node, frac);
|
|
4165
|
+
if (scripts) {
|
|
4166
|
+
return scripts;
|
|
4167
|
+
}
|
|
4168
|
+
return { editable: true, node: frac };
|
|
4169
|
+
}
|
|
4170
|
+
if ((node.name === "\\sqrt" || node.name === "\\arabsqrt" || node.name === "\\arsqrt") && node.mandatoryArgs.length >= 1) {
|
|
4171
|
+
const sqrt = createSqrtNode();
|
|
4172
|
+
const radicand = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4173
|
+
if (!radicand.editable) {
|
|
4174
|
+
return radicand;
|
|
4175
|
+
}
|
|
4176
|
+
sqrt.radicand = radicand.chain;
|
|
4177
|
+
if (node.optionalArgs[0]) {
|
|
4178
|
+
const rootIndex = chainToEditorChain(node.optionalArgs[0]);
|
|
4179
|
+
if (!rootIndex.editable) {
|
|
4180
|
+
return rootIndex;
|
|
4181
|
+
}
|
|
4182
|
+
sqrt.rootIndex = rootIndex.chain;
|
|
4183
|
+
}
|
|
4184
|
+
const scripts = attachScripts(node, sqrt);
|
|
4185
|
+
if (scripts) {
|
|
4186
|
+
return scripts;
|
|
4187
|
+
}
|
|
4188
|
+
return { editable: true, node: sqrt };
|
|
4189
|
+
}
|
|
4190
|
+
if (node.name === "\\boxed" && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 1) {
|
|
4191
|
+
const boxed = createBoxedNode();
|
|
4192
|
+
const inner = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4193
|
+
if (!inner.editable) {
|
|
4194
|
+
return inner;
|
|
4195
|
+
}
|
|
4196
|
+
boxed.innerExpr = inner.chain;
|
|
4197
|
+
const scripts = attachScripts(node, boxed);
|
|
4198
|
+
return scripts ?? { editable: true, node: boxed };
|
|
4199
|
+
}
|
|
4200
|
+
if (node.name === "\\overset" && node.mandatoryArgs.length >= 2) {
|
|
4201
|
+
const overset = createOversetNode();
|
|
4202
|
+
const overExpr = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4203
|
+
const baseExpr = chainToEditorChain(node.mandatoryArgs[1]);
|
|
4204
|
+
if (!overExpr.editable) {
|
|
4205
|
+
return overExpr;
|
|
4206
|
+
}
|
|
4207
|
+
if (!baseExpr.editable) {
|
|
4208
|
+
return baseExpr;
|
|
4209
|
+
}
|
|
4210
|
+
overset.overExpr = overExpr.chain;
|
|
4211
|
+
overset.baseExpr = baseExpr.chain;
|
|
4212
|
+
const scripts = attachScripts(node, overset);
|
|
4213
|
+
if (scripts) {
|
|
4214
|
+
return scripts;
|
|
4215
|
+
}
|
|
4216
|
+
return { editable: true, node: overset };
|
|
4217
|
+
}
|
|
4218
|
+
if (node.name === "\\underset" && node.mandatoryArgs.length >= 2) {
|
|
4219
|
+
const underset = createUndersetNode();
|
|
4220
|
+
const underExpr = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4221
|
+
const baseExpr = chainToEditorChain(node.mandatoryArgs[1]);
|
|
4222
|
+
if (!underExpr.editable) {
|
|
4223
|
+
return underExpr;
|
|
4224
|
+
}
|
|
4225
|
+
if (!baseExpr.editable) {
|
|
4226
|
+
return baseExpr;
|
|
4227
|
+
}
|
|
4228
|
+
underset.underExpr = underExpr.chain;
|
|
4229
|
+
underset.baseExpr = baseExpr.chain;
|
|
4230
|
+
const scripts = attachScripts(node, underset);
|
|
4231
|
+
if (scripts) {
|
|
4232
|
+
return scripts;
|
|
4233
|
+
}
|
|
4234
|
+
return { editable: true, node: underset };
|
|
4235
|
+
}
|
|
4236
|
+
const accentId = accentCommandIdFromTex(node.name);
|
|
4237
|
+
if (accentId && node.mandatoryArgs.length >= 1) {
|
|
4238
|
+
const accent = createAccentNode(accentId);
|
|
4239
|
+
const baseExpr = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4240
|
+
if (!baseExpr.editable) {
|
|
4241
|
+
return baseExpr;
|
|
4242
|
+
}
|
|
4243
|
+
accent.baseExpr = baseExpr.chain;
|
|
4244
|
+
const scripts = attachScripts(node, accent);
|
|
4245
|
+
if (scripts) {
|
|
4246
|
+
return scripts;
|
|
4247
|
+
}
|
|
4248
|
+
return { editable: true, node: accent };
|
|
4249
|
+
}
|
|
4250
|
+
const wrappedAtomicId = wrappedAtomicCommandId(node);
|
|
4251
|
+
if (wrappedAtomicId) {
|
|
4252
|
+
const atomic = createEditorNode("atomicCommand", wrappedAtomicId);
|
|
4253
|
+
const scripts = attachScripts(node, atomic);
|
|
4254
|
+
if (scripts) {
|
|
4255
|
+
return scripts;
|
|
4256
|
+
}
|
|
4257
|
+
return { editable: true, node: atomic };
|
|
4258
|
+
}
|
|
4259
|
+
const wrapper = editableWrapperCommand(node);
|
|
4260
|
+
if (wrapper) {
|
|
4261
|
+
return wrapper;
|
|
4262
|
+
}
|
|
4263
|
+
const atomicId = commandIdForTex(node.name);
|
|
4264
|
+
if (atomicId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
|
|
4265
|
+
const atomic = createEditorNode("atomicCommand", atomicId);
|
|
4266
|
+
const scripts = attachScripts(node, atomic);
|
|
4267
|
+
if (scripts) {
|
|
4268
|
+
return scripts;
|
|
4269
|
+
}
|
|
4270
|
+
return { editable: true, node: atomic };
|
|
4271
|
+
}
|
|
4272
|
+
const operatorId = operatorCommandIdForTex(node.name);
|
|
4273
|
+
if (operatorId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
|
|
4274
|
+
const atomicOperator = createEditorNode("atomicOperatorCommand", operatorId);
|
|
4275
|
+
if (node.name === "\\le" || node.name === "\\ge") atomicOperator.sourceLatex = node.name;
|
|
4276
|
+
const scripts = attachScripts(node, atomicOperator);
|
|
4277
|
+
if (scripts) {
|
|
4278
|
+
return scripts;
|
|
4279
|
+
}
|
|
4280
|
+
return { editable: true, node: atomicOperator };
|
|
4281
|
+
}
|
|
4282
|
+
if (isStandardCommandTex(node.name) && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
|
|
4283
|
+
const standard = createEditorNode("standardCommand", node.name);
|
|
4284
|
+
const scripts = attachScripts(node, standard);
|
|
4285
|
+
if (scripts) {
|
|
4286
|
+
return scripts;
|
|
4287
|
+
}
|
|
4288
|
+
return { editable: true, node: standard };
|
|
4289
|
+
}
|
|
4290
|
+
const textLike = charFromTextLikeCommand(node);
|
|
4291
|
+
if (textLike) {
|
|
4292
|
+
return textLike;
|
|
4293
|
+
}
|
|
4294
|
+
return { editable: false, reason: `\u0623\u0645\u0631 \u0631\u064A\u0627\u0636\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.name}` };
|
|
4295
|
+
}
|
|
4296
|
+
function astNodeToEditorNode(node) {
|
|
4297
|
+
if (node instanceof CharNode) {
|
|
4298
|
+
const normalized = normalizeCharImportExpr(node.expr);
|
|
4299
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
4300
|
+
if (normalized.characterFont !== "default") {
|
|
4301
|
+
editorNode.characterFont = normalized.characterFont;
|
|
4302
|
+
}
|
|
4303
|
+
const scripts = attachScripts(node, editorNode);
|
|
4304
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
4305
|
+
}
|
|
4306
|
+
if (node instanceof NumberNode) {
|
|
4307
|
+
const editorNode = createEditorNode("number", node.expr);
|
|
4308
|
+
const scripts = attachScripts(node, editorNode);
|
|
4309
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
4310
|
+
}
|
|
4311
|
+
if (node instanceof OperatorNode) {
|
|
4312
|
+
return { editable: true, node: createEditorNode("operator", node.expr) };
|
|
4313
|
+
}
|
|
4314
|
+
if (node instanceof DelimiterNode) {
|
|
4315
|
+
const editorNode = createDelimiterNode(node.leftDelimExpr, node.rightDelimExpr);
|
|
4316
|
+
const inner = chainToEditorChain(node.innerExpr);
|
|
4317
|
+
if (!inner.editable) {
|
|
4318
|
+
return inner;
|
|
4319
|
+
}
|
|
4320
|
+
editorNode.innerExpr = inner.chain;
|
|
4321
|
+
const scripts = attachScripts(node, editorNode);
|
|
4322
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
4323
|
+
}
|
|
4324
|
+
if (node instanceof CommandNode) {
|
|
4325
|
+
return commandToEditorNode(node);
|
|
4326
|
+
}
|
|
4327
|
+
if (node instanceof EnvNode) {
|
|
4328
|
+
return envToEditorNode(node);
|
|
4329
|
+
}
|
|
4330
|
+
return { editable: false, reason: `\u0639\u0642\u062F\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627: ${node.nodeType}` };
|
|
4331
|
+
}
|
|
4332
|
+
var VERTICAL_DELIMITER_COMMAND_PAIRS = {
|
|
4333
|
+
"\\vert": "\\vert",
|
|
4334
|
+
"\\lvert": "\\rvert",
|
|
4335
|
+
"\\Vert": "\\Vert",
|
|
4336
|
+
"\\lVert": "\\rVert",
|
|
4337
|
+
"\\|": "\\|"
|
|
4338
|
+
};
|
|
4339
|
+
function isBareCommand(node, name) {
|
|
4340
|
+
return node instanceof CommandNode && node.name === name && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0;
|
|
4341
|
+
}
|
|
4342
|
+
function normalizeVerticalDelimiterCommands(chain) {
|
|
4343
|
+
const normalized = [];
|
|
4344
|
+
for (let index = 0; index < chain.chain.length; index += 1) {
|
|
4345
|
+
const left = chain.chain[index];
|
|
4346
|
+
if (!(left instanceof CommandNode) || left.superscript || left.subscript) {
|
|
4347
|
+
normalized.push(left);
|
|
4348
|
+
continue;
|
|
4349
|
+
}
|
|
4350
|
+
const rightName = VERTICAL_DELIMITER_COMMAND_PAIRS[left.name];
|
|
4351
|
+
if (!rightName || left.optionalArgs.length > 0 || left.mandatoryArgs.length > 0) {
|
|
4352
|
+
normalized.push(left);
|
|
4353
|
+
continue;
|
|
4354
|
+
}
|
|
4355
|
+
let rightIndex = -1;
|
|
4356
|
+
for (let candidate = index + 1; candidate < chain.chain.length; candidate += 1) {
|
|
4357
|
+
if (isBareCommand(chain.chain[candidate], rightName)) {
|
|
4358
|
+
rightIndex = candidate;
|
|
4359
|
+
break;
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
if (rightIndex < 0) {
|
|
4363
|
+
normalized.push(left);
|
|
4364
|
+
continue;
|
|
4365
|
+
}
|
|
4366
|
+
const right = chain.chain[rightIndex];
|
|
4367
|
+
const delimiter = new DelimiterNode(
|
|
4368
|
+
left.name,
|
|
4369
|
+
new ChainNode(chain.chain.slice(index + 1, rightIndex)),
|
|
4370
|
+
right.name
|
|
4371
|
+
);
|
|
4372
|
+
delimiter.superscript = right.superscript;
|
|
4373
|
+
delimiter.subscript = right.subscript;
|
|
4374
|
+
normalized.push(delimiter);
|
|
4375
|
+
index = rightIndex;
|
|
4376
|
+
}
|
|
4377
|
+
return new ChainNode(normalized);
|
|
4378
|
+
}
|
|
4379
|
+
function chainToEditorChain(chain, script = false) {
|
|
4380
|
+
if (script && chain.chain.length === 1) {
|
|
4381
|
+
const wrapper = chain.chain[0];
|
|
4382
|
+
if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
|
|
4383
|
+
if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
|
|
4384
|
+
return { editable: false, reason: "\u0635\u064A\u063A\u0629 \u0645\u062C\u0645\u0648\u0639\u0629 \u0627\u0644\u0641\u0647\u0627\u0631\u0633 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629" };
|
|
4385
|
+
}
|
|
4386
|
+
const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
|
|
4387
|
+
if (!imported.editable) return imported;
|
|
4388
|
+
const atoms = [];
|
|
4389
|
+
for (const node of imported.chain.nodes) {
|
|
4390
|
+
if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
|
|
4391
|
+
atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
|
|
4392
|
+
} else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
|
|
4393
|
+
atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
|
|
4394
|
+
} else {
|
|
4395
|
+
atoms.push(node);
|
|
4396
|
+
}
|
|
4397
|
+
}
|
|
4398
|
+
imported.chain.nodes = atoms;
|
|
4399
|
+
if (!isValidIndexSequence(imported.chain)) {
|
|
4400
|
+
return { editable: false, reason: "\u0645\u062D\u062A\u0648\u0649 \u0645\u062C\u0645\u0648\u0639\u0629 \u0627\u0644\u0641\u0647\u0627\u0631\u0633 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645" };
|
|
4401
|
+
}
|
|
4402
|
+
imported.chain.indexSequence = true;
|
|
4403
|
+
return imported;
|
|
4404
|
+
}
|
|
4405
|
+
}
|
|
4406
|
+
const nodes = [];
|
|
4407
|
+
for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
|
|
4408
|
+
const converted = astNodeToEditorNode(astNode);
|
|
4409
|
+
if (!converted.editable) {
|
|
4410
|
+
return converted;
|
|
4411
|
+
}
|
|
4412
|
+
nodes.push(converted.node);
|
|
4413
|
+
}
|
|
4414
|
+
return { editable: true, chain: createEditorChain(nodes) };
|
|
4415
|
+
}
|
|
4416
|
+
function mathObjectToEditorSession(math) {
|
|
4417
|
+
if (math.lines.length !== 1) {
|
|
4418
|
+
return { editable: false, reason: "\u062A\u062D\u0631\u064A\u0631 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0627\u062A \u0645\u062A\u0639\u062F\u062F\u0629 \u0627\u0644\u0623\u0633\u0637\u0631 \u062F\u0627\u062E\u0644 \u0627\u0644\u0645\u0633\u062A\u0646\u062F \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u0628\u0639\u062F" };
|
|
4419
|
+
}
|
|
4420
|
+
const english = chainToEditorChain(math.lines[0]);
|
|
4421
|
+
if (!english.editable) {
|
|
4422
|
+
return english;
|
|
4423
|
+
}
|
|
4424
|
+
const arabic = cloneChainWithFreshIds(english.chain);
|
|
4425
|
+
const session = createEditorSession(english.chain, arabic, "english");
|
|
4426
|
+
session.sync = buildInitialSyncMap(session.englishTree, session.arabicTree);
|
|
4427
|
+
return { editable: true, session: cloneEditorSession(session) };
|
|
4428
|
+
}
|
|
4429
|
+
|
|
4430
|
+
// src/document/mathBridge.ts
|
|
4431
|
+
function mathTokenToEditorSession(math, side = "arabic") {
|
|
4432
|
+
if (!math) {
|
|
4433
|
+
return { editable: false, reason: "\u0647\u0630\u0647 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u0645\u062D\u0641\u0648\u0638\u0629 \u0643\u0646\u0635 \u062E\u0627\u0645 \u0641\u0642\u0637 \u062D\u0627\u0644\u064A\u0627" };
|
|
4434
|
+
}
|
|
4435
|
+
const result = mathObjectToEditorSession(math);
|
|
4436
|
+
if (!result.editable) {
|
|
4437
|
+
return result;
|
|
4438
|
+
}
|
|
4439
|
+
result.session.activeSide = side;
|
|
4440
|
+
result.session.sync = buildInitialSyncMap(result.session.englishTree, result.session.arabicTree);
|
|
4441
|
+
return result;
|
|
4442
|
+
}
|
|
4443
|
+
function mathSourceFromSession(session, side, opening = "$", closing = "$", presentation = false) {
|
|
4444
|
+
const inner = side === "english" ? renderEnglishLatexFromSession(session) : presentation ? renderArabicPreviewLatexFromSession(session) : renderArabicLatexFromSession(session);
|
|
4445
|
+
if (opening === "$" || opening === "\\(") {
|
|
4446
|
+
return opening + inner + closing;
|
|
4447
|
+
}
|
|
4448
|
+
if (opening === "$$" || opening === "\\[") {
|
|
4449
|
+
return `${opening}
|
|
4450
|
+
${inner}
|
|
4451
|
+
${closing}`;
|
|
4452
|
+
}
|
|
4453
|
+
return `${opening}
|
|
4454
|
+
${inner}
|
|
4455
|
+
${closing}`;
|
|
4456
|
+
}
|
|
4457
|
+
function mathTokenSourceForSide(token, side, digitForm, presentation = false) {
|
|
4458
|
+
if (!token.math || token.sourceOwner === "raw") {
|
|
4459
|
+
return token.source;
|
|
4460
|
+
}
|
|
4461
|
+
if (!presentation && token.sourceSide === side && digitForm === void 0) {
|
|
4462
|
+
return token.source;
|
|
4463
|
+
}
|
|
4464
|
+
const result = mathTokenToEditorSession(token.math, side);
|
|
4465
|
+
if (!result.editable) {
|
|
4466
|
+
return token.source;
|
|
4467
|
+
}
|
|
4468
|
+
const session = digitForm === void 0 ? result.session : setCurrentDigitForm(result.session, digitForm);
|
|
4469
|
+
return mathSourceFromSession(session, side, token.opening, token.closing, presentation);
|
|
4470
|
+
}
|
|
2651
4471
|
|
|
2652
4472
|
// src/document/keys.ts
|
|
2653
4473
|
var DOCUMENT_KEY_PATTERN = /^[\p{L}\p{M}\p{Nd}:._-]+$/u;
|
|
@@ -2772,6 +4592,471 @@ function getDocumentReferenceIndex(document2) {
|
|
|
2772
4592
|
};
|
|
2773
4593
|
}
|
|
2774
4594
|
|
|
4595
|
+
// src/document/arabicPreamble.ts
|
|
4596
|
+
function fontOptions(digitsMapping, includeScript = true) {
|
|
4597
|
+
const parts = [];
|
|
4598
|
+
if (includeScript) {
|
|
4599
|
+
parts.push("Script=Arabic");
|
|
4600
|
+
}
|
|
4601
|
+
if (digitsMapping !== "digits") {
|
|
4602
|
+
parts.push(`Mapping=${digitsMapping}`);
|
|
4603
|
+
}
|
|
4604
|
+
if (parts.length === 0) {
|
|
4605
|
+
return "";
|
|
4606
|
+
}
|
|
4607
|
+
return `[${parts.join(",")}]`;
|
|
4608
|
+
}
|
|
4609
|
+
function arabicXeLatexPreamblePkg(twocolumn = false) {
|
|
4610
|
+
const classOptions = twocolumn ? "12pt,a4paper,notitlepage,twocolumn" : "12pt,a4paper,notitlepage";
|
|
4611
|
+
return `
|
|
4612
|
+
\\documentclass[${classOptions}]{article}
|
|
4613
|
+
` + String.raw`\usepackage{amsmath,amsfonts,amssymb,mathrsfs,tikz,fancyhdr, mathtools}
|
|
4614
|
+
\usepackage{fontspec} % For loading OpenType fonts
|
|
4615
|
+
\usepackage{unicode-math} % For setting the math font
|
|
4616
|
+
\usepackage{polyglossia} % For Arabic support
|
|
4617
|
+
\usepackage{array}
|
|
4618
|
+
\usepackage{cancel}
|
|
4619
|
+
\usepackage{bidi}
|
|
4620
|
+
\usepackage{multirow}
|
|
4621
|
+
\usepackage{booktabs}
|
|
4622
|
+
\usepackage{graphicx} % For \reflectbox
|
|
4623
|
+
\usepackage{xcolor}
|
|
4624
|
+
\usepackage{tikz}
|
|
4625
|
+
\usepackage{tcolorbox} % For tcolorbox environment
|
|
4626
|
+
\usepackage{textcomp} % For \textrightarrow command
|
|
4627
|
+
\usepackage{url}
|
|
4628
|
+
|
|
4629
|
+
|
|
4630
|
+
% visit : https://www.symbolcopy.com/punctuation-symbol.html
|
|
4631
|
+
% for inversed punctuation
|
|
4632
|
+
|
|
4633
|
+
% save inverted comma for use - copy paste -> ،
|
|
4634
|
+
% save back tick for use - copy paste -> ` + "`";
|
|
4635
|
+
}
|
|
4636
|
+
function arabicXeLatexPreambleFont(digitsMapping = "arabicdigits") {
|
|
4637
|
+
const customFonts = NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.latexFontCommand && font.latexFontFamily).map((font) => `\\newfontfamily${font.latexFontCommand}${fontOptions(digitsMapping)}{${font.latexFontFamily}}`).join("\n");
|
|
4638
|
+
const mathFontOptions = fontOptions(digitsMapping, false);
|
|
4639
|
+
return `
|
|
4640
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4641
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4642
|
+
% Persian digits: Mapping=farsidigits
|
|
4643
|
+
% Arabic-Indic digits: Mapping=arabicdigits
|
|
4644
|
+
% Western digits: omit Mapping entirely
|
|
4645
|
+
\\setdefaultlanguage[calendar=gregorian]{arabic} % from polyglossia
|
|
4646
|
+
\\setmainfont${fontOptions(digitsMapping)}{Amiri}
|
|
4647
|
+
${customFonts}
|
|
4648
|
+
\\newfontfamily\\boldarabic${fontOptions(digitsMapping)}{Amiri Bold}
|
|
4649
|
+
\\newfontfamily\\italicarabic${fontOptions(digitsMapping)}{Amiri Italic}
|
|
4650
|
+
|
|
4651
|
+
% for polyglossia url I dont know, sugggested by cursor
|
|
4652
|
+
\\newfontfamily\\arabicfonttt${fontOptions(digitsMapping)}{Amiri}
|
|
4653
|
+
\\newfontfamily\\arabicfontsf${fontOptions(digitsMapping)}{Amiri}
|
|
4654
|
+
|
|
4655
|
+
|
|
4656
|
+
% Explicitly set math font to XITS Math
|
|
4657
|
+
\\setmathfont${mathFontOptions}{XITS Math} % Ensure XITS Math is correctly installed and available
|
|
4658
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4659
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4660
|
+
`;
|
|
4661
|
+
}
|
|
4662
|
+
function arabicXeLatexPreambleCmd() {
|
|
4663
|
+
const fontCommands = NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.macro && font.latexFontCommand).map((font) => `\\newcommand{${font.macro}}[1]{\\text{${font.latexFontCommand}{#1}}}`).join("\n");
|
|
4664
|
+
return String.raw`
|
|
4665
|
+
% Run with XeLaTeX compiler
|
|
4666
|
+
${fontCommands}
|
|
4667
|
+
\newcommand{\butexmirror}[1]{\reflectbox{\(#1\)}}
|
|
4668
|
+
|
|
4669
|
+
\newcommand{\arabN}{\text{\diwanioutlineshaded{ط}}}
|
|
4670
|
+
\newcommand{\arabZ}{\text{\diwanioutlineshaded{ص}}}
|
|
4671
|
+
\newcommand{\arabQ}{\text{\diwanioutlineshaded{ن}}}
|
|
4672
|
+
\newcommand{\arabR}{\text{\diwanioutlineshaded{ح}}}
|
|
4673
|
+
\newcommand{\arabC}{\text{\diwanioutlineshaded{ع}}}
|
|
4674
|
+
\newcommand{\arabH}{\text{\diwanioutlineshaded{ر}}}
|
|
4675
|
+
|
|
4676
|
+
|
|
4677
|
+
\newcommand{\lowerscript}[1]{\raisebox{-4pt}{\scriptsize #1}}
|
|
4678
|
+
\newcommand{\llowerscript}[1]{\raisebox{-8pt}{\scriptsize #1}}
|
|
4679
|
+
\newcommand{\lllowerscript}[2]{\raisebox{#2pt}{\scriptsize #1}}
|
|
4680
|
+
|
|
4681
|
+
\newcommand{\arabdsub}[3]{\prescript{}{#1}{\prescript{}{#2}{#3}}} % arabic double subscript
|
|
4682
|
+
\newcommand{\arabsub}[2]{\prescript{}{#1}{#2}} % arabic single subscript
|
|
4683
|
+
|
|
4684
|
+
|
|
4685
|
+
|
|
4686
|
+
\newcommand{\upperscript}[1]{\raisebox{8pt}{\scriptsize #1}}
|
|
4687
|
+
\newcommand{\uupperscript}[2]{\raisebox{#2pt}{\scriptsize #1}}
|
|
4688
|
+
\newcommand{\vertbar}{\rule[-1ex]{0.5pt}{2.5ex}}
|
|
4689
|
+
\newcommand{\horzbar}{\rule[.5ex]{2.5ex}{0.5pt}}
|
|
4690
|
+
|
|
4691
|
+
|
|
4692
|
+
\newcommand{\arsqrt}[2][]{\reflectbox{\(\sqrt[\reflectbox{\(#1\)}]{\reflectbox{\(#2\)}}\)}}
|
|
4693
|
+
\newcommand{\arabsqrt}[2][]{\arsqrt[#1]{#2}}
|
|
4694
|
+
\newcommand{\arabvec}[1]{\reflectbox{$\vec{\reflectbox{$#1$}}$}}
|
|
4695
|
+
|
|
4696
|
+
\newcommand{\arabexp}[1]{{}^{#1}\!\raisebox{-4.5pt}{\text{\diwani{ه}}}}
|
|
4697
|
+
\newcommand{\arablog}[2]{\left(\text{#2}\right)\!\prescript{}{\text{#1}}{\text{\diwani{لو}}}}
|
|
4698
|
+
\newcommand{\arabnlog}[1]{\left(\text{#1}\right)\!\prescript{}{\text{\diwani{ه}}}{\text{\diwani{لو}}}}
|
|
4699
|
+
|
|
4700
|
+
\newcommand{\arabcos}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{جتا}}}}
|
|
4701
|
+
\newcommand{\arabsin}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{جا}}}}
|
|
4702
|
+
\newcommand{\arabtan}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ظا}}}}
|
|
4703
|
+
\newcommand{\arabcot}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ظتا}}}}
|
|
4704
|
+
\newcommand{\arabsec}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قا}}}}
|
|
4705
|
+
\newcommand{\arabcsc}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قتا}}}}
|
|
4706
|
+
|
|
4707
|
+
\newcommand{\arabacos}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قجتا}}}}
|
|
4708
|
+
\newcommand{\arabasin}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قجا}}}}
|
|
4709
|
+
\newcommand{\arabatan}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قظا}}}}
|
|
4710
|
+
\newcommand{\arabacot}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قظتا}}}}
|
|
4711
|
+
\newcommand{\arabasec}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ققا}}}}
|
|
4712
|
+
\newcommand{\arabacsc}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ققتا}}}}
|
|
4713
|
+
|
|
4714
|
+
|
|
4715
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4716
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4717
|
+
% summation
|
|
4718
|
+
\newcommand{\arablim}[2]{\underset{#2 \leftarrow #1}{\text{نـــــها}}}
|
|
4719
|
+
\newcommand{\arabsum}[2]{\underset{#1}{\overset{#2}{\text{مجـــ}}}}
|
|
4720
|
+
\newcommand{\arabprod}[2]{\underset{#1}{\overset{#2}{\text{جـــذ}}}}
|
|
4721
|
+
\newcommand{\arabint}[2]{\prescript{#2}{#1\!\!\!}\int}
|
|
4722
|
+
|
|
4723
|
+
|
|
4724
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4725
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4726
|
+
% we define this command to make it ease for change of notation later
|
|
4727
|
+
\newcommand{\ad}[0]{\text{ء}} % "ad" for arabic differentiation or derivative (ء" لإشتقاق")
|
|
4728
|
+
\newcommand{\arpi}[0]{\!\text{\diwani{ط}}}
|
|
4729
|
+
|
|
4730
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4731
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4732
|
+
% differentials
|
|
4733
|
+
|
|
4734
|
+
\newcommand{\arabdiff}[2]{\frac{#1\ad}{#2\ad}} % arabic differential
|
|
4735
|
+
\newcommand{\arabddiff}[2]{\frac{#1{}^{2}\ad}{{}^{2}#2\ad}} % arabic second differential
|
|
4736
|
+
|
|
4737
|
+
\newcommand{\arabode}[2][-5pt]{\stackrel{\raisebox{#1}{$\cdot$}}{\text{#2}}}
|
|
4738
|
+
\newcommand{\arabodde}[2][-5pt]{\stackrel{\raisebox{#1}{$\vcenter{\hbox{$\cdot\!\cdot$}}$}}{\text{#2}}}
|
|
4739
|
+
\newcommand{\araboddde}[2][-5pt]{\stackrel{\raisebox{#1}{$\vcenter{\hbox{$\cdot\!\cdot\!\cdot$}}$}}{\text{#2}}}
|
|
4740
|
+
\newcommand{\arabpde}[1]{\prescript{}{#1\!\!}{\nabla}} % arabic partial differential equation (PDE)
|
|
4741
|
+
|
|
4742
|
+
\newcommand{\arabprime}[0]{\reflectbox{$\prime$}\!} % arabic prime notation
|
|
4743
|
+
\newcommand{\arabpprime}[0]{\reflectbox{$\prime$}\reflectbox{$\prime$}\!} % arabic prime notation
|
|
4744
|
+
\newcommand{\arabppprime}[0]{\reflectbox{$\prime$}\reflectbox{$\prime$}\reflectbox{$\prime$}\!} % arabic prime notation
|
|
4745
|
+
|
|
4746
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4747
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4748
|
+
% probability
|
|
4749
|
+
\newcommand{\ap}[0]{\!\text{\diwani{حـ}}} % arabic Probability - used a lot so short form
|
|
4750
|
+
\newcommand{\arabExpct}[0]{\text{\diwani{توقـ}}} % arabic Expectation
|
|
4751
|
+
\newcommand{\arabVar}[0]{\!\text{\diwani{با}}} % arabic Variance
|
|
4752
|
+
\newcommand{\arabCov}[0]{\!\text{\diwani{ت}}} % arabic Covariance
|
|
4753
|
+
|
|
4754
|
+
|
|
4755
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4756
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4757
|
+
% custom commands specific to lesson
|
|
4758
|
+
\newcommand{\lagrange}[2]{\left(#2\right)\!\prescript{}{#1}{\text{\diwani{لا}}}}
|
|
4759
|
+
\newcommand{\xii}[0]{\left(\prescript{}{\text{يـ}}{\text{س}}\right)\!}
|
|
4760
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4761
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
4762
|
+
|
|
4763
|
+
|
|
4764
|
+
\newcommand{\arexp}[0]{\!\raisebox{-4.5pt}{\text{\diwani{ه}}}}
|
|
4765
|
+
\newcommand{\arlog}[0]{\!\!\text{\diwani{لو}}}
|
|
4766
|
+
\newcommand{\arln}[0]{\!\!\prescript{}{\text{\diwani{ه}}}{\text{\diwani{لو}}}}
|
|
4767
|
+
\newcommand{\ardet}[0]{\!\!\text{\diwani{محدد}}}
|
|
4768
|
+
|
|
4769
|
+
\newcommand{\arsum}[0]{\text{مجـــ}}
|
|
4770
|
+
\newcommand{\arprod}[0]{\text{جـــذ}}
|
|
4771
|
+
|
|
4772
|
+
\newcommand{\arlim}[0]{\text{نـــــها}}
|
|
4773
|
+
\newcommand{\ararg}[0]{\text{حج}}
|
|
4774
|
+
\newcommand{\armax}[0]{\text{أكبر}}
|
|
4775
|
+
\newcommand{\armin}[0]{\text{أصغر}}
|
|
4776
|
+
\newcommand{\arsup}[0]{\text{أعلى}}
|
|
4777
|
+
\newcommand{\arinf}[0]{\text{أدنى}}
|
|
4778
|
+
|
|
4779
|
+
\newcommand{\arsin}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جا}}}}
|
|
4780
|
+
\newcommand{\arcos}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جتا}}}}
|
|
4781
|
+
\newcommand{\artan}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظا}}}}
|
|
4782
|
+
\newcommand{\arcot}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظتا}}}}
|
|
4783
|
+
\newcommand{\arsec}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قا}}}}
|
|
4784
|
+
\newcommand{\arcsc}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قتا}}}}
|
|
4785
|
+
|
|
4786
|
+
\newcommand{\arasin}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجا}}}}
|
|
4787
|
+
\newcommand{\aracos}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجتا}}}}
|
|
4788
|
+
\newcommand{\aratan}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظا}}}}
|
|
4789
|
+
\newcommand{\aracot}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظتا}}}}
|
|
4790
|
+
\newcommand{\arasec}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققا}}}}
|
|
4791
|
+
\newcommand{\aracsc}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققتا}}}}
|
|
4792
|
+
|
|
4793
|
+
\newcommand{\arsinh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جزا}}}}
|
|
4794
|
+
\newcommand{\arcosh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جتزا}}}}
|
|
4795
|
+
\newcommand{\artanh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظزا}}}}
|
|
4796
|
+
\newcommand{\arcoth}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظتزا}}}}
|
|
4797
|
+
\newcommand{\arsech}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قزا}}}}
|
|
4798
|
+
\newcommand{\arcsch}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قتزا}}}}
|
|
4799
|
+
|
|
4800
|
+
\newcommand{\arasinh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجزا}}}}
|
|
4801
|
+
\newcommand{\aracosh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجتزا}}}}
|
|
4802
|
+
\newcommand{\aratanh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظزا}}}}
|
|
4803
|
+
\newcommand{\aracoth}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظتزا}}}}
|
|
4804
|
+
\newcommand{\arasech}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققزا}}}}
|
|
4805
|
+
\newcommand{\aracsch}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققتزا}}}}
|
|
4806
|
+
|
|
4807
|
+
\newcommand{\unit}[1]{\text{#1}}
|
|
4808
|
+
\newcommand{\idx}[1]{#1}
|
|
4809
|
+
\newcommand{\arbinom}[2]{\left(\begin{array}{c} #1 \\ #2 \end{array} \right)}
|
|
4810
|
+
`;
|
|
4811
|
+
}
|
|
4812
|
+
function getArabicXeLatexPreamble(digitsMappingOrOptions = "arabicdigits") {
|
|
4813
|
+
const options = typeof digitsMappingOrOptions === "string" ? { digitsMapping: digitsMappingOrOptions } : digitsMappingOrOptions;
|
|
4814
|
+
const digitsMapping = options.digitsMapping ?? "arabicdigits";
|
|
4815
|
+
const twocolumn = options.twocolumn === true;
|
|
4816
|
+
return arabicXeLatexPreamblePkg(twocolumn) + arabicXeLatexPreambleFont(digitsMapping) + arabicXeLatexPreambleCmd();
|
|
4817
|
+
}
|
|
4818
|
+
|
|
4819
|
+
// src/document/exportLatex.ts
|
|
4820
|
+
function editorMathLatexForCompile(token) {
|
|
4821
|
+
const source = token.math && token.sourceSide === "arabic" && token.source.includes("\\begin{cases}") ? mathTokenSourceForSide(token, "arabic", void 0, true) : token.source;
|
|
4822
|
+
return mirrorBuTeXOperatorsInTex(source, { target: "compile" });
|
|
4823
|
+
}
|
|
4824
|
+
function mathBodyLatex(token) {
|
|
4825
|
+
if (token.sourceOwner === "editor") {
|
|
4826
|
+
return stripDisplayMathDelimiters(editorMathLatexForCompile(token));
|
|
4827
|
+
}
|
|
4828
|
+
if (!token.math || token.sourceOwner === "raw") {
|
|
4829
|
+
return stripDisplayMathDelimiters(token.source);
|
|
4830
|
+
}
|
|
4831
|
+
const rendered = renderMathNodeLatex(token.math);
|
|
4832
|
+
return stripDisplayMathDelimiters(rendered);
|
|
4833
|
+
}
|
|
4834
|
+
function styledTextLatex(text, style) {
|
|
4835
|
+
let output = text;
|
|
4836
|
+
if (style?.bold) {
|
|
4837
|
+
output = `\\textbf{${output}}`;
|
|
4838
|
+
}
|
|
4839
|
+
if (style?.italic) {
|
|
4840
|
+
output = `\\textit{${output}}`;
|
|
4841
|
+
}
|
|
4842
|
+
if (style?.underline) {
|
|
4843
|
+
output = `\\underline{${output}}`;
|
|
4844
|
+
}
|
|
4845
|
+
return output;
|
|
4846
|
+
}
|
|
4847
|
+
function semanticRefPrefix(kind) {
|
|
4848
|
+
if (kind === "fig") {
|
|
4849
|
+
return "\u0627\u0644\u0634\u0643\u0644";
|
|
4850
|
+
}
|
|
4851
|
+
if (kind === "tab") {
|
|
4852
|
+
return "\u0627\u0644\u062C\u062F\u0648\u0644";
|
|
4853
|
+
}
|
|
4854
|
+
return "\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629";
|
|
4855
|
+
}
|
|
4856
|
+
function semanticRefNames(kind) {
|
|
4857
|
+
if (kind === "fig") {
|
|
4858
|
+
return ["\u0627\u0644\u0634\u0643\u0644", "\u0634\u0643\u0644", "Figure", "figure"];
|
|
4859
|
+
}
|
|
4860
|
+
if (kind === "tab") {
|
|
4861
|
+
return ["\u0627\u0644\u062C\u062F\u0648\u0644", "\u062C\u062F\u0648\u0644", "Table", "table"];
|
|
4862
|
+
}
|
|
4863
|
+
return ["\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629", "\u0645\u0639\u0627\u062F\u0644\u0629", "Equation", "equation"];
|
|
4864
|
+
}
|
|
4865
|
+
function previousTextAlreadyNamesKind(previousToken, kind) {
|
|
4866
|
+
if (previousToken?.kind !== "text") {
|
|
4867
|
+
return false;
|
|
4868
|
+
}
|
|
4869
|
+
const text = previousToken.text.trimEnd();
|
|
4870
|
+
return semanticRefNames(kind).some((name) => text.endsWith(name));
|
|
4871
|
+
}
|
|
4872
|
+
function refTokenLatexForDocument(token, labelKinds, previousToken) {
|
|
4873
|
+
const reference = refTokenLatex(token.keys, token.refCommand);
|
|
4874
|
+
if (!labelKinds || token.keys.length !== 1) {
|
|
4875
|
+
return reference;
|
|
4876
|
+
}
|
|
4877
|
+
const kind = labelKinds.get(token.keys[0]);
|
|
4878
|
+
if (!kind || previousTextAlreadyNamesKind(previousToken, kind)) {
|
|
4879
|
+
return reference;
|
|
4880
|
+
}
|
|
4881
|
+
return `${semanticRefPrefix(kind)}~${reference}`;
|
|
4882
|
+
}
|
|
4883
|
+
function tokenLatex(token, labelKinds, previousToken, unitId) {
|
|
4884
|
+
if (token.kind === "text") {
|
|
4885
|
+
return styledTextLatex(token.text, token.style);
|
|
4886
|
+
}
|
|
4887
|
+
if (token.kind === "cite") {
|
|
4888
|
+
return citeTokenLatex(token.keys);
|
|
4889
|
+
}
|
|
4890
|
+
if (token.kind === "ref") {
|
|
4891
|
+
return refTokenLatexForDocument(token, labelKinds, previousToken);
|
|
4892
|
+
}
|
|
4893
|
+
if (isNumberedEquation(token)) {
|
|
4894
|
+
const body = mathBodyLatex(token);
|
|
4895
|
+
const autoKey = implicitReferenceKey("eq", token.id, unitId);
|
|
4896
|
+
const aliases = [autoKey];
|
|
4897
|
+
if (token.labelEnabled && token.label?.trim() && token.label.trim() !== autoKey) aliases.push(token.label.trim());
|
|
4898
|
+
return "\\begin{equation}\n" + body + "\n" + aliases.map((key) => "\\label{" + key + "}").join("\n") + "\n\\end{equation}";
|
|
4899
|
+
}
|
|
4900
|
+
if (token.display && token.numbered === false && token.opening === "\\begin{equation}") {
|
|
4901
|
+
return "\\[" + mathBodyLatex(token) + "\\]";
|
|
4902
|
+
}
|
|
4903
|
+
if (token.sourceOwner === "editor") {
|
|
4904
|
+
return editorMathLatexForCompile(token);
|
|
4905
|
+
}
|
|
4906
|
+
if (!token.math || token.sourceOwner === "raw") {
|
|
4907
|
+
return token.source;
|
|
4908
|
+
}
|
|
4909
|
+
return renderMathNodeLatex(token.math);
|
|
4910
|
+
}
|
|
4911
|
+
function inlineFieldLatexWithLabelKinds(field, labelKinds, unitId) {
|
|
4912
|
+
return field.tokens.map((token, index) => tokenLatex(token, labelKinds, field.tokens[index - 1], unitId)).join("");
|
|
4913
|
+
}
|
|
4914
|
+
function textBlockLatex(block, labelKinds, unitId) {
|
|
4915
|
+
const content = inlineFieldLatexWithLabelKinds(block.field, labelKinds, unitId);
|
|
4916
|
+
const body = block.command === "\\paragraph" ? `\\par
|
|
4917
|
+
${content}` : `${block.command}{${content}}`;
|
|
4918
|
+
if (block.command !== "\\paragraph") {
|
|
4919
|
+
const keys = unitId ? [implicitHeadingReferenceKey(block.command.slice(1), block.id, unitId)] : [];
|
|
4920
|
+
if (block.label?.trim() && !keys.includes(block.label.trim())) keys.push(block.label.trim());
|
|
4921
|
+
return [body, ...keys.map((key) => `\\label{${key}}`)].join("\n");
|
|
4922
|
+
}
|
|
4923
|
+
if (block.command === "\\paragraph" && block.centered) {
|
|
4924
|
+
return `\\begin{center}
|
|
4925
|
+
${body}
|
|
4926
|
+
\\end{center}`;
|
|
4927
|
+
}
|
|
4928
|
+
return body;
|
|
4929
|
+
}
|
|
4930
|
+
function indent(value) {
|
|
4931
|
+
return value.split("\n").map((line) => ` ${line}`).join("\n");
|
|
4932
|
+
}
|
|
4933
|
+
function listBlockLatex(block, references, labelKinds, fixedFloats, unitId) {
|
|
4934
|
+
const items = block.items.map((item) => {
|
|
4935
|
+
const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child, references, labelKinds, fixedFloats, unitId))).join("");
|
|
4936
|
+
return ` \\item ${inlineFieldLatexWithLabelKinds(item.field, labelKinds, unitId)}${nested}`;
|
|
4937
|
+
}).join("\n");
|
|
4938
|
+
return `${block.command}
|
|
4939
|
+
${items}
|
|
4940
|
+
${block.closing}`;
|
|
4941
|
+
}
|
|
4942
|
+
function defaultGridColumnSpec(block) {
|
|
4943
|
+
const compact = block.columns.replace(/\s+/g, "");
|
|
4944
|
+
const columnCount = block.rows[0]?.length ?? 0;
|
|
4945
|
+
if (columnCount === 0 || compact.length !== columnCount || !/^[lcr]+$/.test(compact)) {
|
|
4946
|
+
return null;
|
|
4947
|
+
}
|
|
4948
|
+
return `|${compact.split("").join("|")}|`;
|
|
4949
|
+
}
|
|
4950
|
+
function tabularInnerLatex(block, labelKinds, unitId) {
|
|
4951
|
+
const rows = block.rows.map(
|
|
4952
|
+
(row) => ` ${row.map((cell) => inlineFieldLatexWithLabelKinds(cell, labelKinds, unitId)).join(" & ")}`
|
|
4953
|
+
);
|
|
4954
|
+
const gridColumns = defaultGridColumnSpec(block);
|
|
4955
|
+
if (gridColumns) {
|
|
4956
|
+
const griddedRows = rows.map((row) => `${row} \\\\ \\hline`).join("\n");
|
|
4957
|
+
return `${block.command}{${gridColumns}}
|
|
4958
|
+
\\hline
|
|
4959
|
+
${griddedRows}
|
|
4960
|
+
${block.closing}`;
|
|
4961
|
+
}
|
|
4962
|
+
return `${block.command}{${block.columns}}
|
|
4963
|
+
${rows.join(" \\\\\n")}
|
|
4964
|
+
${block.closing}`;
|
|
4965
|
+
}
|
|
4966
|
+
function floatCaptionLabelLines(block, counter, labelKinds, unitId) {
|
|
4967
|
+
const lines = [];
|
|
4968
|
+
const caption = inlineFieldLatexWithLabelKinds(block.captionField, labelKinds, unitId).trim();
|
|
4969
|
+
const hasCaption = block.captionEnabled && caption.length > 0;
|
|
4970
|
+
if (hasCaption) {
|
|
4971
|
+
lines.push(` \\caption{${caption}}`);
|
|
4972
|
+
}
|
|
4973
|
+
const hasManualLabel = block.labelEnabled && block.label.trim().length > 0;
|
|
4974
|
+
if (hasCaption || hasManualLabel) {
|
|
4975
|
+
if (!hasCaption) lines.push(" \\refstepcounter{" + counter + "}");
|
|
4976
|
+
const autoKey = implicitReferenceKey(counter === "figure" ? "fig" : "tab", block.id, unitId);
|
|
4977
|
+
lines.push(" \\label{" + autoKey + "}");
|
|
4978
|
+
if (hasManualLabel && block.label.trim() !== autoKey) lines.push(" \\label{" + block.label.trim() + "}");
|
|
4979
|
+
}
|
|
4980
|
+
return lines;
|
|
4981
|
+
}
|
|
4982
|
+
function tableBlockLatex(block, labelKinds, fixedFloats, unitId) {
|
|
4983
|
+
const placement = fixedFloats ? "H" : "htbp";
|
|
4984
|
+
const lines = [`\\begin{table}[${placement}]`];
|
|
4985
|
+
if (block.centered) {
|
|
4986
|
+
lines.push(" \\centering");
|
|
4987
|
+
}
|
|
4988
|
+
lines.push(...floatCaptionLabelLines(block, "table", labelKinds, unitId));
|
|
4989
|
+
lines.push(indent(tabularInnerLatex(block, labelKinds, unitId)));
|
|
4990
|
+
lines.push("\\end{table}");
|
|
4991
|
+
return lines.join("\n");
|
|
4992
|
+
}
|
|
4993
|
+
function remapImageWidthForColumns(value) {
|
|
4994
|
+
return value.replace(/\\textwidth\b/g, "\\columnwidth");
|
|
4995
|
+
}
|
|
4996
|
+
function imageOptionsLatex(block, constrainToColumn) {
|
|
4997
|
+
const entries = Object.entries(block.options).map(([key, value]) => {
|
|
4998
|
+
if (constrainToColumn && key === "width") {
|
|
4999
|
+
return [key, remapImageWidthForColumns(value)];
|
|
5000
|
+
}
|
|
5001
|
+
return [key, value];
|
|
5002
|
+
});
|
|
5003
|
+
if (entries.length === 0) {
|
|
5004
|
+
return "";
|
|
5005
|
+
}
|
|
5006
|
+
return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
|
|
5007
|
+
}
|
|
5008
|
+
function imageBlockLatex(block, labelKinds, fixedFloats, unitId) {
|
|
5009
|
+
const placement = fixedFloats ? "H" : "htbp";
|
|
5010
|
+
const lines = [`\\begin{figure}[${placement}]`];
|
|
5011
|
+
if (block.centered) {
|
|
5012
|
+
lines.push(" \\centering");
|
|
5013
|
+
}
|
|
5014
|
+
lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
|
|
5015
|
+
lines.push(...floatCaptionLabelLines(block, "figure", labelKinds, unitId));
|
|
5016
|
+
lines.push("\\end{figure}");
|
|
5017
|
+
return lines.join("\n");
|
|
5018
|
+
}
|
|
5019
|
+
function blockLatex(block, references, labelKinds, fixedFloats, unitId) {
|
|
5020
|
+
if (block.kind === "textBlock") {
|
|
5021
|
+
return textBlockLatex(block, labelKinds, unitId);
|
|
5022
|
+
}
|
|
5023
|
+
if (block.kind === "list") {
|
|
5024
|
+
return listBlockLatex(block, references, labelKinds, fixedFloats, unitId);
|
|
5025
|
+
}
|
|
5026
|
+
if (block.kind === "table") {
|
|
5027
|
+
return tableBlockLatex(block, labelKinds, fixedFloats, unitId);
|
|
5028
|
+
}
|
|
5029
|
+
if (block.kind === "image") {
|
|
5030
|
+
return imageBlockLatex(block, labelKinds, fixedFloats, unitId);
|
|
5031
|
+
}
|
|
5032
|
+
if (block.kind === "bibliography") {
|
|
5033
|
+
const width = String(Math.max(references.length, 9));
|
|
5034
|
+
const items = references.map((reference) => ` ${bibliographyEntryLatex(reference)}`).join("\n");
|
|
5035
|
+
return `${block.command}{${width}}
|
|
5036
|
+
${items}
|
|
5037
|
+
${block.closing}`;
|
|
5038
|
+
}
|
|
5039
|
+
return block.value;
|
|
5040
|
+
}
|
|
5041
|
+
function documentLabelKindMap(document2) {
|
|
5042
|
+
const map = /* @__PURE__ */ new Map();
|
|
5043
|
+
for (const [key, entry] of labelNumberMap(document2)) {
|
|
5044
|
+
map.set(key, entry.kind);
|
|
5045
|
+
}
|
|
5046
|
+
return map;
|
|
5047
|
+
}
|
|
5048
|
+
function documentContentLatex(document2, context) {
|
|
5049
|
+
if (!context?.unitId?.trim()) throw new Error("book-content export requires a stable unitId");
|
|
5050
|
+
const labelKinds = documentLabelKindMap(document2);
|
|
5051
|
+
for (const target of context?.targets ?? []) {
|
|
5052
|
+
if (target.kind === "fig" || target.kind === "tab" || target.kind === "eq") {
|
|
5053
|
+
labelKinds.set(target.key, target.kind);
|
|
5054
|
+
if (target.manualKey) labelKinds.set(target.manualKey, target.kind);
|
|
5055
|
+
}
|
|
5056
|
+
}
|
|
5057
|
+
return document2.blocks.filter((block) => block.kind !== "bibliography").map((block) => blockLatex(block, document2.references, labelKinds, false, context?.unitId)).filter((part) => part.length > 0).join("\n\n");
|
|
5058
|
+
}
|
|
5059
|
+
|
|
2775
5060
|
// src/book/utils.ts
|
|
2776
5061
|
var ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
2777
5062
|
function safeId(id) {
|
|
@@ -3208,6 +5493,7 @@ function bookContextForUnit(snapshot, unitId) {
|
|
|
3208
5493
|
kind: t.kind,
|
|
3209
5494
|
...t.caption !== void 0 ? { caption: t.caption } : {},
|
|
3210
5495
|
...t.displayLabel !== void 0 ? { displayLabel: t.displayLabel } : {},
|
|
5496
|
+
...t.ordinal !== void 0 ? { ordinal: t.ordinal } : {},
|
|
3211
5497
|
...t.manualKey !== void 0 ? { manualKey: t.manualKey } : {}
|
|
3212
5498
|
})) };
|
|
3213
5499
|
}
|
|
@@ -3221,9 +5507,221 @@ function validateBookSnapshot(snapshot) {
|
|
|
3221
5507
|
const resolution = resolveBookSnapshot(snapshot);
|
|
3222
5508
|
return { valid: resolution.issues.every((x) => x.severity !== "error"), issues: resolution.issues };
|
|
3223
5509
|
}
|
|
5510
|
+
|
|
5511
|
+
// src/book/exportLatex.ts
|
|
5512
|
+
var SAFE_PATH = /^[A-Za-z0-9][A-Za-z0-9._-]*(\/[A-Za-z0-9][A-Za-z0-9._-]*){0,3}$/;
|
|
5513
|
+
var IMAGE_EXT = /\.(?:png|jpe?g|pdf)$/i;
|
|
5514
|
+
function escapeLatex(value) {
|
|
5515
|
+
return value.replace(/[\\{}%#$&_~^]/g, (char) => ({
|
|
5516
|
+
"\\": "\\textbackslash{}",
|
|
5517
|
+
"{": "\\{",
|
|
5518
|
+
"}": "\\}",
|
|
5519
|
+
"%": "\\%",
|
|
5520
|
+
"#": "\\#",
|
|
5521
|
+
"$": "\\$",
|
|
5522
|
+
"&": "\\&",
|
|
5523
|
+
"_": "\\_",
|
|
5524
|
+
"~": "\\textasciitilde{}",
|
|
5525
|
+
"^": "\\textasciicircum{}"
|
|
5526
|
+
})[char] ?? char);
|
|
5527
|
+
}
|
|
5528
|
+
function visitAssets(blocks, collect) {
|
|
5529
|
+
for (const block of blocks) {
|
|
5530
|
+
if (block.command === "\\includegraphics") {
|
|
5531
|
+
if (!block.asset_id || typeof block.value !== "string") {
|
|
5532
|
+
throw new BookContractError("Book images require an asset_id and relative image path");
|
|
5533
|
+
}
|
|
5534
|
+
collect(block.asset_id, block.value);
|
|
5535
|
+
}
|
|
5536
|
+
for (const item of block.items ?? []) {
|
|
5537
|
+
visitAssets(item.blocks ?? [], collect);
|
|
5538
|
+
}
|
|
5539
|
+
}
|
|
5540
|
+
}
|
|
5541
|
+
function fingerprint(files, assets) {
|
|
5542
|
+
let value = 2166136261;
|
|
5543
|
+
const payload = JSON.stringify({ files, assets });
|
|
5544
|
+
for (const byte of new TextEncoder().encode(payload)) {
|
|
5545
|
+
value = Math.imul(value ^ byte, 16777619) >>> 0;
|
|
5546
|
+
}
|
|
5547
|
+
return "fnv1a32:" + value.toString(16).padStart(8, "0");
|
|
5548
|
+
}
|
|
5549
|
+
function heading(entry, resolution) {
|
|
5550
|
+
return resolution.outline.find((item) => item.id === entry.id)?.display_label ?? entry.title;
|
|
5551
|
+
}
|
|
5552
|
+
function unitBoundary(entry, projection, unnumbered) {
|
|
5553
|
+
const numbered = (entry.type === "chapter" || entry.type === "appendix") && entry.numbered;
|
|
5554
|
+
const lines = [];
|
|
5555
|
+
if (numbered) {
|
|
5556
|
+
const target = projection.targets.find((t) => t.unitId === entry.id && t.ownerId === entry.id);
|
|
5557
|
+
if (!target?.ordinal) throw new BookContractError("Missing Book numbering projection for " + entry.id);
|
|
5558
|
+
lines.push(
|
|
5559
|
+
"\\renewcommand{\\thechapter}{" + target.ordinal + "}",
|
|
5560
|
+
"\\refstepcounter{chapter}",
|
|
5561
|
+
"\\renewcommand{\\thesection}{\\thechapter.\\arabic{section}}"
|
|
5562
|
+
);
|
|
5563
|
+
} else {
|
|
5564
|
+
lines.push(
|
|
5565
|
+
"\\setcounter{section}{0}",
|
|
5566
|
+
"\\renewcommand{\\thesection}{\\arabic{section}}"
|
|
5567
|
+
);
|
|
5568
|
+
}
|
|
5569
|
+
for (const [kind, counter] of [["fig", "figure"], ["tab", "table"], ["eq", "equation"]]) {
|
|
5570
|
+
lines.push("\\setcounter{" + counter + "}{" + (numbered ? "0" : String(unnumbered[kind])) + "}");
|
|
5571
|
+
lines.push("\\renewcommand{\\the" + counter + "}{" + (numbered ? "\\thechapter." : "") + "\\arabic{" + counter + "}}");
|
|
5572
|
+
}
|
|
5573
|
+
const title = escapeLatex(heading(entry, projection));
|
|
5574
|
+
lines.push("\\chapter*{" + title + "}");
|
|
5575
|
+
if (entry.include_in_toc) {
|
|
5576
|
+
lines.push("\\addcontentsline{toc}{chapter}{" + title + "}");
|
|
5577
|
+
}
|
|
5578
|
+
if (numbered) {
|
|
5579
|
+
const target = projection.targets.find((t) => t.unitId === entry.id && t.ownerId === entry.id);
|
|
5580
|
+
if (target) lines.push("\\label{" + target.key + "}");
|
|
5581
|
+
if (entry.label && entry.label !== target?.key) lines.push("\\label{" + entry.label + "}");
|
|
5582
|
+
} else if (entry.label) {
|
|
5583
|
+
lines.push("\\label{" + entry.label + "}");
|
|
5584
|
+
}
|
|
5585
|
+
return lines.join("\n");
|
|
5586
|
+
}
|
|
5587
|
+
function bookPreamble(snapshot) {
|
|
5588
|
+
const arabicDigits = snapshot.manifest.meta.numbering?.digit_form !== "western";
|
|
5589
|
+
const articlePreamble = getArabicXeLatexPreamble({
|
|
5590
|
+
digitsMapping: arabicDigits ? "arabicdigits" : "digits"
|
|
5591
|
+
});
|
|
5592
|
+
const withoutClass = articlePreamble.replace(/\\documentclass\[[^\]]*\]\{article\}/, "");
|
|
5593
|
+
if (withoutClass === articlePreamble) throw new BookContractError("Arabic preamble class seam has changed");
|
|
5594
|
+
return [
|
|
5595
|
+
"\\NeedsTeXFormat{LaTeX2e}",
|
|
5596
|
+
"\\ProvidesPackage{book}[2026/11/14 BuTeX Arabic Book]",
|
|
5597
|
+
withoutClass.replace(/\\usepackage/g, "\\RequirePackage"),
|
|
5598
|
+
"\\renewcommand{\\figurename}{\u0627\u0644\u0634\u0643\u0644}",
|
|
5599
|
+
"\\renewcommand{\\tablename}{\u0627\u0644\u062C\u062F\u0648\u0644}",
|
|
5600
|
+
"\\renewcommand{\\contentsname}{\u0627\u0644\u0645\u062D\u062A\u0648\u064A\u0627\u062A}"
|
|
5601
|
+
].join("\n");
|
|
5602
|
+
}
|
|
5603
|
+
function normalizeBookEquationLabels(content, unitId, projection) {
|
|
5604
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
5605
|
+
let latex = content;
|
|
5606
|
+
for (const target of projection.targets) {
|
|
5607
|
+
if (target.kind !== "eq" || !target.manualKey || target.manualKey === target.key) continue;
|
|
5608
|
+
aliases.set(target.manualKey, target.key);
|
|
5609
|
+
if (target.unitId === unitId) {
|
|
5610
|
+
const automatic = "\\label{" + target.key + "}";
|
|
5611
|
+
const manual = "\\label{" + target.manualKey + "}";
|
|
5612
|
+
latex = latex.replace(automatic + "\n" + manual, automatic);
|
|
5613
|
+
}
|
|
5614
|
+
}
|
|
5615
|
+
if (!aliases.size) return latex;
|
|
5616
|
+
return latex.replace(/\\(eqref|ref)\{([^}]*)\}/g, (_whole, command, keys) => "\\" + command + "{" + keys.split(",").map((key) => aliases.get(key.trim()) ?? key).join(",") + "}");
|
|
5617
|
+
}
|
|
5618
|
+
function book2Latex(raw, _options = {}) {
|
|
5619
|
+
const snapshot = normalizeBookSnapshot(raw);
|
|
5620
|
+
const projection = resolveBookSnapshot(snapshot);
|
|
5621
|
+
const fatal = projection.issues.filter((issue2) => issue2.severity === "error");
|
|
5622
|
+
if (fatal.length) {
|
|
5623
|
+
throw new BookContractError("Book export blocked: " + fatal[0].code + " at " + fatal[0].path);
|
|
5624
|
+
}
|
|
5625
|
+
const files = {};
|
|
5626
|
+
const assets = [];
|
|
5627
|
+
const paths = /* @__PURE__ */ new Map();
|
|
5628
|
+
const addAsset = (assetId, path) => {
|
|
5629
|
+
const tail = path.split("/").at(-1) ?? "";
|
|
5630
|
+
const extensionless = !tail.includes(".");
|
|
5631
|
+
if (!SAFE_PATH.test(path) || path.split("/").some((part) => part.startsWith(".")) || !(IMAGE_EXT.test(path) || extensionless)) {
|
|
5632
|
+
throw new BookContractError("Unsafe or unsupported Book image path: " + path);
|
|
5633
|
+
}
|
|
5634
|
+
const alias = path.toLowerCase();
|
|
5635
|
+
const prior = paths.get(alias);
|
|
5636
|
+
if (prior && prior !== assetId) {
|
|
5637
|
+
throw new BookContractError("Multiple Book assets claim the same image path: " + path);
|
|
5638
|
+
}
|
|
5639
|
+
paths.set(alias, assetId);
|
|
5640
|
+
if (!assets.some((a) => a.asset_id === assetId && a.output_path === path)) {
|
|
5641
|
+
assets.push({ asset_id: assetId, output_path: path });
|
|
5642
|
+
}
|
|
5643
|
+
};
|
|
5644
|
+
const meta = snapshot.manifest.meta;
|
|
5645
|
+
const main = [
|
|
5646
|
+
"\\documentclass[12pt,a4paper]{book}",
|
|
5647
|
+
"\\usepackage{book}",
|
|
5648
|
+
"\\begin{document}"
|
|
5649
|
+
];
|
|
5650
|
+
const unnumbered = { fig: 0, tab: 0, eq: 0 };
|
|
5651
|
+
let hasBibliography = false;
|
|
5652
|
+
let hasToc = false;
|
|
5653
|
+
for (const entry of snapshot.manifest.entries) {
|
|
5654
|
+
if (entry.kind === "generated") {
|
|
5655
|
+
if (entry.generated === "title-page") {
|
|
5656
|
+
main.push(
|
|
5657
|
+
"\\begin{titlepage}\\centering",
|
|
5658
|
+
"{\\Huge " + escapeLatex(meta.title) + "\\par}",
|
|
5659
|
+
"\\vspace{2cm}",
|
|
5660
|
+
...meta.authors.map((author) => escapeLatex(author) + "\\par"),
|
|
5661
|
+
...meta.date ? [escapeLatex(meta.date) + "\\par"] : [],
|
|
5662
|
+
"\\end{titlepage}"
|
|
5663
|
+
);
|
|
5664
|
+
} else if (entry.generated === "table-of-contents") {
|
|
5665
|
+
hasToc = true;
|
|
5666
|
+
main.push("\\tableofcontents");
|
|
5667
|
+
} else if (entry.generated === "list-of-figures") {
|
|
5668
|
+
main.push("\\listoffigures");
|
|
5669
|
+
} else if (entry.generated === "list-of-tables") {
|
|
5670
|
+
main.push("\\listoftables");
|
|
5671
|
+
} else if (entry.generated === "bibliography") {
|
|
5672
|
+
hasBibliography = true;
|
|
5673
|
+
main.push("\\input{references.tex}");
|
|
5674
|
+
}
|
|
5675
|
+
continue;
|
|
5676
|
+
}
|
|
5677
|
+
const unitPath = "units/" + entry.id + ".tex";
|
|
5678
|
+
const doc = snapshot.documents[entry.id];
|
|
5679
|
+
visitAssets(doc.blocks, addAsset);
|
|
5680
|
+
const context = {
|
|
5681
|
+
unitId: entry.id,
|
|
5682
|
+
references: snapshot.references.references,
|
|
5683
|
+
targets: projection.targets
|
|
5684
|
+
};
|
|
5685
|
+
const content = normalizeBookEquationLabels(documentContentLatex(fromDocumentJson(doc), context), entry.id, projection);
|
|
5686
|
+
files[unitPath] = [unitBoundary(entry, projection, unnumbered), content, ""].join("\n\n");
|
|
5687
|
+
main.push("\\input{" + unitPath + "}");
|
|
5688
|
+
if (!((entry.type === "chapter" || entry.type === "appendix") && entry.numbered)) {
|
|
5689
|
+
for (const kind of ["fig", "tab", "eq"]) {
|
|
5690
|
+
unnumbered[kind] += projection.targets.filter((t) => t.unitId === entry.id && t.kind === kind && t.numbered).length;
|
|
5691
|
+
}
|
|
5692
|
+
}
|
|
5693
|
+
}
|
|
5694
|
+
if (!hasToc && _options.include_toc_if_missing) {
|
|
5695
|
+
main.splice(3, 0, "\\tableofcontents");
|
|
5696
|
+
}
|
|
5697
|
+
if (snapshot.references.references.length) {
|
|
5698
|
+
const entries = snapshot.references.references.map((ref) => " " + bibliographyEntryLatex(referenceFromJson(ref)));
|
|
5699
|
+
files["references.tex"] = [
|
|
5700
|
+
"\\begin{thebibliography}{" + String(Math.max(9, entries.length)) + "}",
|
|
5701
|
+
...entries,
|
|
5702
|
+
"\\end{thebibliography}",
|
|
5703
|
+
""
|
|
5704
|
+
].join("\n");
|
|
5705
|
+
if (!hasBibliography) main.push("\\input{references.tex}");
|
|
5706
|
+
} else if (hasBibliography) {
|
|
5707
|
+
files["references.tex"] = "% No shared references\n";
|
|
5708
|
+
}
|
|
5709
|
+
main.push("\\end{document}", "");
|
|
5710
|
+
files["main.tex"] = main.join("\n\n");
|
|
5711
|
+
files["book.sty"] = bookPreamble(snapshot);
|
|
5712
|
+
const ordered = Object.fromEntries(Object.entries(files).sort(([a], [b]) => a.localeCompare(b)));
|
|
5713
|
+
return {
|
|
5714
|
+
main_file: "main.tex",
|
|
5715
|
+
files: ordered,
|
|
5716
|
+
assets,
|
|
5717
|
+
diagnostics: projection.issues,
|
|
5718
|
+
fingerprint: fingerprint(ordered, assets)
|
|
5719
|
+
};
|
|
5720
|
+
}
|
|
3224
5721
|
export {
|
|
3225
5722
|
BookContractError,
|
|
3226
5723
|
applyBookCommand,
|
|
5724
|
+
book2Latex,
|
|
3227
5725
|
bookContextForUnit,
|
|
3228
5726
|
bookOutline,
|
|
3229
5727
|
getBookReferenceIndex,
|