@drghaliasri/butex 4.4.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/document2.d.mts +191 -80
- package/dist/document2.d.ts +191 -80
- package/dist/document2.js +683 -101
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +660 -101
- package/dist/document2.mjs.map +1 -1
- package/dist/react-document2.d.mts +160 -83
- package/dist/react-document2.d.ts +160 -83
- package/dist/react-document2.js +2039 -686
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +2002 -649
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +1 -1
package/dist/document2.mjs
CHANGED
|
@@ -6,6 +6,100 @@ function document2Id(prefix) {
|
|
|
6
6
|
return id;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
// src/editor/digits.ts
|
|
10
|
+
var WESTERN = "0123456789";
|
|
11
|
+
var ARABIC_INDIC = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
|
|
12
|
+
var PERSIAN_INDIC = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
|
|
13
|
+
var digitSets = {
|
|
14
|
+
western: WESTERN,
|
|
15
|
+
arabicIndic: ARABIC_INDIC,
|
|
16
|
+
persianIndic: PERSIAN_INDIC
|
|
17
|
+
};
|
|
18
|
+
function digitValue(char) {
|
|
19
|
+
const western = WESTERN.indexOf(char);
|
|
20
|
+
if (western >= 0) {
|
|
21
|
+
return western;
|
|
22
|
+
}
|
|
23
|
+
const arabicIndic = ARABIC_INDIC.indexOf(char);
|
|
24
|
+
if (arabicIndic >= 0) {
|
|
25
|
+
return arabicIndic;
|
|
26
|
+
}
|
|
27
|
+
return PERSIAN_INDIC.indexOf(char);
|
|
28
|
+
}
|
|
29
|
+
function formatDigits(value, digitForm = "western") {
|
|
30
|
+
const target = digitSets[digitForm];
|
|
31
|
+
return Array.from(value, (char) => {
|
|
32
|
+
const value2 = digitValue(char);
|
|
33
|
+
return value2 >= 0 ? target[value2] : char;
|
|
34
|
+
}).join("");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/document2/citations.ts
|
|
38
|
+
function referenceNumberMap(references) {
|
|
39
|
+
const map = /* @__PURE__ */ new Map();
|
|
40
|
+
references.forEach((reference, index) => {
|
|
41
|
+
if (!map.has(reference.key)) {
|
|
42
|
+
map.set(reference.key, index + 1);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return map;
|
|
46
|
+
}
|
|
47
|
+
function resolveCiteNumbers(keys, references) {
|
|
48
|
+
const map = referenceNumberMap(references);
|
|
49
|
+
return keys.map((key) => map.get(key) ?? null);
|
|
50
|
+
}
|
|
51
|
+
function formatCiteLabel(keys, references, options = {}) {
|
|
52
|
+
const documentDirection = options.documentDirection ?? "rtl";
|
|
53
|
+
const digitForm = options.digitForm ?? (documentDirection === "rtl" ? "arabicIndic" : "western");
|
|
54
|
+
const numbers = resolveCiteNumbers(keys, references).map((value) => value === null ? "?" : String(value));
|
|
55
|
+
const display = documentDirection === "rtl" ? [...numbers].reverse() : numbers;
|
|
56
|
+
const separator = documentDirection === "rtl" ? "\u060C" : ", ";
|
|
57
|
+
const body = display.map((part) => formatDigits(part, digitForm)).join(separator);
|
|
58
|
+
return `[${body}]`;
|
|
59
|
+
}
|
|
60
|
+
function formatBibliographyNumber(index, options = {}) {
|
|
61
|
+
const documentDirection = options.documentDirection ?? "rtl";
|
|
62
|
+
const digitForm = options.digitForm ?? (documentDirection === "rtl" ? "arabicIndic" : "western");
|
|
63
|
+
return formatDigits(String(index), digitForm);
|
|
64
|
+
}
|
|
65
|
+
function parseCiteKeys(source) {
|
|
66
|
+
const match = /^\\cite\{([^}]*)\}$/.exec(source.trim());
|
|
67
|
+
if (!match) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
return (match[1] ?? "").split(",").map((key) => key.trim()).filter((key) => key.length > 0);
|
|
71
|
+
}
|
|
72
|
+
function citeTokenLatex(keys) {
|
|
73
|
+
return `\\cite{${keys.join(",")}}`;
|
|
74
|
+
}
|
|
75
|
+
function referenceFromJson(json) {
|
|
76
|
+
return {
|
|
77
|
+
id: document2Id("ref"),
|
|
78
|
+
key: json.key,
|
|
79
|
+
authors: typeof json.authors === "string" ? json.authors : "",
|
|
80
|
+
title: typeof json.title === "string" ? json.title : "",
|
|
81
|
+
year: typeof json.year === "string" ? json.year : "",
|
|
82
|
+
url: typeof json.url === "string" ? json.url : "",
|
|
83
|
+
venue: typeof json.venue === "string" ? json.venue : ""
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function createEmptyReference2(partial = {}) {
|
|
87
|
+
return referenceFromJson({
|
|
88
|
+
key: partial.key ?? `ref${String(Date.now()).slice(-4)}`,
|
|
89
|
+
authors: partial.authors,
|
|
90
|
+
title: partial.title,
|
|
91
|
+
year: partial.year,
|
|
92
|
+
url: partial.url,
|
|
93
|
+
venue: partial.venue
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function bibliographyEntryLatex(reference) {
|
|
97
|
+
const parts = [reference.authors, reference.title, reference.venue, reference.year].filter((part) => part.trim().length > 0);
|
|
98
|
+
const body = parts.join(", ");
|
|
99
|
+
const url = reference.url.trim().length > 0 ? ` \\url{${reference.url}}` : "";
|
|
100
|
+
return `\\bibitem{${reference.key}} ${body}${url}`.trim();
|
|
101
|
+
}
|
|
102
|
+
|
|
9
103
|
// src/ast/commands/index.ts
|
|
10
104
|
function renderCommandCore(context) {
|
|
11
105
|
const optional = context.optionalArgs.map((arg) => `[${context.renderChain(arg)}]`).join("");
|
|
@@ -424,53 +518,84 @@ function environmentSpan(value, start) {
|
|
|
424
518
|
const end = closingStart + closing.length;
|
|
425
519
|
return { start, end, source: value.slice(start, end), opening, closing, display: true };
|
|
426
520
|
}
|
|
427
|
-
function
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
521
|
+
function citeSpan(value, start) {
|
|
522
|
+
if (!value.startsWith("\\cite{", start) || isEscaped(value, start)) {
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
const openBrace = start + "\\cite".length;
|
|
526
|
+
if (value[openBrace] !== "{") {
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
let depth = 0;
|
|
530
|
+
for (let i = openBrace; i < value.length; i += 1) {
|
|
531
|
+
const char = value[i];
|
|
532
|
+
if (char === "{" && !isEscaped(value, i)) {
|
|
533
|
+
depth += 1;
|
|
534
|
+
continue;
|
|
438
535
|
}
|
|
439
|
-
if (
|
|
440
|
-
|
|
441
|
-
if (
|
|
442
|
-
const end =
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
continue;
|
|
536
|
+
if (char === "}" && !isEscaped(value, i)) {
|
|
537
|
+
depth -= 1;
|
|
538
|
+
if (depth === 0) {
|
|
539
|
+
const end = i + 1;
|
|
540
|
+
const source = value.slice(start, end);
|
|
541
|
+
return { kind: "cite", start, end, source, keys: parseCiteKeys(source) };
|
|
446
542
|
}
|
|
447
543
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
544
|
+
}
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
function mathSpanAt(value, i) {
|
|
548
|
+
if (value.startsWith("\\begin{", i)) {
|
|
549
|
+
return environmentSpan(value, i);
|
|
550
|
+
}
|
|
551
|
+
if (value.startsWith("\\(", i)) {
|
|
552
|
+
const close = value.indexOf("\\)", i + 2);
|
|
553
|
+
if (close >= 0) {
|
|
554
|
+
const end = close + 2;
|
|
555
|
+
return { start: i, end, source: value.slice(i, end), opening: "\\(", closing: "\\)", display: false };
|
|
456
556
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
continue;
|
|
464
|
-
}
|
|
557
|
+
}
|
|
558
|
+
if (value.startsWith("\\[", i)) {
|
|
559
|
+
const close = value.indexOf("\\]", i + 2);
|
|
560
|
+
if (close >= 0) {
|
|
561
|
+
const end = close + 2;
|
|
562
|
+
return { start: i, end, source: value.slice(i, end), opening: "\\[", closing: "\\]", display: true };
|
|
465
563
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
564
|
+
}
|
|
565
|
+
if (value.startsWith("$$", i) && !isEscaped(value, i)) {
|
|
566
|
+
const close = value.indexOf("$$", i + 2);
|
|
567
|
+
if (close >= 0) {
|
|
568
|
+
const end = close + 2;
|
|
569
|
+
return { start: i, end, source: value.slice(i, end), opening: "$$", closing: "$$", display: true };
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (value[i] === "$" && !isEscaped(value, i)) {
|
|
573
|
+
const close = findClosingDollar(value, i + 1);
|
|
574
|
+
if (close >= 0) {
|
|
575
|
+
const end = close + 1;
|
|
576
|
+
return { start: i, end, source: value.slice(i, end), opening: "$", closing: "$", display: false };
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
function detectMathSpans2(value) {
|
|
582
|
+
return detectInlineSpans2(value).filter((span) => span.kind === "math").map(({ kind: _kind, ...span }) => span);
|
|
583
|
+
}
|
|
584
|
+
function detectInlineSpans2(value) {
|
|
585
|
+
const spans = [];
|
|
586
|
+
let i = 0;
|
|
587
|
+
while (i < value.length) {
|
|
588
|
+
const cite = citeSpan(value, i);
|
|
589
|
+
if (cite) {
|
|
590
|
+
spans.push(cite);
|
|
591
|
+
i = cite.end;
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
const math = mathSpanAt(value, i);
|
|
595
|
+
if (math) {
|
|
596
|
+
spans.push({ kind: "math", ...math });
|
|
597
|
+
i = math.end;
|
|
598
|
+
continue;
|
|
474
599
|
}
|
|
475
600
|
i += 1;
|
|
476
601
|
}
|
|
@@ -507,19 +632,53 @@ function pushDiagnostic(diagnostics, options, path, message) {
|
|
|
507
632
|
}
|
|
508
633
|
diagnostics.push({ code: "math_alignment", message, path });
|
|
509
634
|
}
|
|
635
|
+
function parseReferences(json) {
|
|
636
|
+
if (!Array.isArray(json)) {
|
|
637
|
+
return [];
|
|
638
|
+
}
|
|
639
|
+
const references = [];
|
|
640
|
+
for (const entry of json) {
|
|
641
|
+
if (!isObject2(entry) || typeof entry.key !== "string" || entry.key.trim().length === 0) {
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
references.push(
|
|
645
|
+
referenceFromJson({
|
|
646
|
+
key: entry.key.trim(),
|
|
647
|
+
authors: typeof entry.authors === "string" ? entry.authors : void 0,
|
|
648
|
+
title: typeof entry.title === "string" ? entry.title : void 0,
|
|
649
|
+
year: typeof entry.year === "string" ? entry.year : void 0,
|
|
650
|
+
url: typeof entry.url === "string" ? entry.url : void 0,
|
|
651
|
+
venue: typeof entry.venue === "string" ? entry.venue : void 0
|
|
652
|
+
})
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
return references;
|
|
656
|
+
}
|
|
510
657
|
function createInlineField2(value = "", mathObjects = [], options = {}, path = "$", diagnostics = []) {
|
|
511
658
|
const mode = options.mode ?? "english";
|
|
512
|
-
const spans =
|
|
659
|
+
const spans = detectInlineSpans2(value);
|
|
660
|
+
const mathSpans = spans.filter((span) => span.kind === "math");
|
|
513
661
|
const tokens = [];
|
|
514
662
|
let index = 0;
|
|
515
|
-
|
|
516
|
-
|
|
663
|
+
let mathObjectIndex = 0;
|
|
664
|
+
if (mathObjects.length > 0 && mathObjects.length !== mathSpans.length) {
|
|
665
|
+
pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(mathSpans.length)}, got ${String(mathObjects.length)}`);
|
|
517
666
|
}
|
|
518
|
-
|
|
667
|
+
for (const span of spans) {
|
|
519
668
|
if (span.start > index) {
|
|
520
669
|
tokens.push({ id: document2Id("text"), kind: "text", text: value.slice(index, span.start) });
|
|
521
670
|
}
|
|
522
|
-
|
|
671
|
+
if (span.kind === "cite") {
|
|
672
|
+
tokens.push({
|
|
673
|
+
id: document2Id("cite"),
|
|
674
|
+
kind: "cite",
|
|
675
|
+
keys: span.keys.length > 0 ? span.keys : []
|
|
676
|
+
});
|
|
677
|
+
index = span.end;
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
const mathJson = mathObjects[mathObjectIndex];
|
|
681
|
+
mathObjectIndex += 1;
|
|
523
682
|
if (mathJson && (mathJson.math_mode !== span.opening || mathJson.closing !== span.closing)) {
|
|
524
683
|
pushDiagnostic(diagnostics, options, path, "math_objects order mismatch");
|
|
525
684
|
}
|
|
@@ -551,7 +710,7 @@ function createInlineField2(value = "", mathObjects = [], options = {}, path = "
|
|
|
551
710
|
});
|
|
552
711
|
}
|
|
553
712
|
index = span.end;
|
|
554
|
-
}
|
|
713
|
+
}
|
|
555
714
|
if (index < value.length || tokens.length === 0) {
|
|
556
715
|
tokens.push({ id: document2Id("text"), kind: "text", text: value.slice(index) });
|
|
557
716
|
}
|
|
@@ -623,11 +782,14 @@ function parseTableBlock(json, options, path, diagnostics) {
|
|
|
623
782
|
};
|
|
624
783
|
}
|
|
625
784
|
function parseImageBlock(json) {
|
|
785
|
+
const assetId = typeof json.asset_id === "string" && json.asset_id.length > 0 ? json.asset_id : void 0;
|
|
786
|
+
const value = assetId !== void 0 ? typeof json.value === "string" ? json.value : "" : requireString(json.value, "\\includegraphics requires string value");
|
|
626
787
|
return {
|
|
627
788
|
id: document2Id("block"),
|
|
628
789
|
kind: "image",
|
|
629
790
|
command: "\\includegraphics",
|
|
630
|
-
value
|
|
791
|
+
value,
|
|
792
|
+
...assetId !== void 0 ? { assetId } : {},
|
|
631
793
|
options: isRecordOfStrings(json.options) ? json.options : {}
|
|
632
794
|
};
|
|
633
795
|
}
|
|
@@ -639,6 +801,14 @@ function parseRawBlock(json) {
|
|
|
639
801
|
value: typeof json.value === "string" ? json.value : ""
|
|
640
802
|
};
|
|
641
803
|
}
|
|
804
|
+
function parseBibliographyBlock() {
|
|
805
|
+
return {
|
|
806
|
+
id: document2Id("block"),
|
|
807
|
+
kind: "bibliography",
|
|
808
|
+
command: "\\begin{thebibliography}",
|
|
809
|
+
closing: "\\end{thebibliography}"
|
|
810
|
+
};
|
|
811
|
+
}
|
|
642
812
|
function parseBlock(json, options, path, diagnostics) {
|
|
643
813
|
if (TEXT_COMMANDS.has(json.command)) {
|
|
644
814
|
return parseTextBlock(json, options, path, diagnostics);
|
|
@@ -652,6 +822,9 @@ function parseBlock(json, options, path, diagnostics) {
|
|
|
652
822
|
if (json.command === "\\includegraphics") {
|
|
653
823
|
return parseImageBlock(json);
|
|
654
824
|
}
|
|
825
|
+
if (json.command === "\\begin{thebibliography}" || json.command === "\\bibliography") {
|
|
826
|
+
return parseBibliographyBlock();
|
|
827
|
+
}
|
|
655
828
|
if (json.command === "\\raw") {
|
|
656
829
|
return parseRawBlock(json);
|
|
657
830
|
}
|
|
@@ -672,12 +845,13 @@ function fromDocumentJson2(json, options = {}) {
|
|
|
672
845
|
const diagnostics = [];
|
|
673
846
|
return {
|
|
674
847
|
nodeType: "DocumentObject",
|
|
848
|
+
references: parseReferences(json.references),
|
|
675
849
|
blocks: json.blocks.map((block, index) => parseBlock(asBlockJson(block), options, `$.blocks[${String(index)}]`, diagnostics)),
|
|
676
850
|
diagnostics
|
|
677
851
|
};
|
|
678
852
|
}
|
|
679
853
|
function createEmptyDocument2() {
|
|
680
|
-
return { nodeType: "DocumentObject", blocks: [], diagnostics: [] };
|
|
854
|
+
return { nodeType: "DocumentObject", references: [], blocks: [], diagnostics: [] };
|
|
681
855
|
}
|
|
682
856
|
|
|
683
857
|
// src/editor/atomicCommands.ts
|
|
@@ -1700,34 +1874,6 @@ function renderDivideOperatorLatex(side) {
|
|
|
1700
1874
|
return side === "arabic" ? "\\backslash" : DIVIDE_OPERATOR_EN;
|
|
1701
1875
|
}
|
|
1702
1876
|
|
|
1703
|
-
// src/editor/digits.ts
|
|
1704
|
-
var WESTERN = "0123456789";
|
|
1705
|
-
var ARABIC_INDIC = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
|
|
1706
|
-
var PERSIAN_INDIC = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
|
|
1707
|
-
var digitSets = {
|
|
1708
|
-
western: WESTERN,
|
|
1709
|
-
arabicIndic: ARABIC_INDIC,
|
|
1710
|
-
persianIndic: PERSIAN_INDIC
|
|
1711
|
-
};
|
|
1712
|
-
function digitValue(char) {
|
|
1713
|
-
const western = WESTERN.indexOf(char);
|
|
1714
|
-
if (western >= 0) {
|
|
1715
|
-
return western;
|
|
1716
|
-
}
|
|
1717
|
-
const arabicIndic = ARABIC_INDIC.indexOf(char);
|
|
1718
|
-
if (arabicIndic >= 0) {
|
|
1719
|
-
return arabicIndic;
|
|
1720
|
-
}
|
|
1721
|
-
return PERSIAN_INDIC.indexOf(char);
|
|
1722
|
-
}
|
|
1723
|
-
function formatDigits(value, digitForm = "western") {
|
|
1724
|
-
const target = digitSets[digitForm];
|
|
1725
|
-
return Array.from(value, (char) => {
|
|
1726
|
-
const value2 = digitValue(char);
|
|
1727
|
-
return value2 >= 0 ? target[value2] : char;
|
|
1728
|
-
}).join("");
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
1877
|
// src/editor/render.ts
|
|
1732
1878
|
function selectedDigitForm(options) {
|
|
1733
1879
|
return options?.digitForm ?? "western";
|
|
@@ -3060,6 +3206,7 @@ function cloneBlock(block) {
|
|
|
3060
3206
|
function cloneDocument(document2) {
|
|
3061
3207
|
return {
|
|
3062
3208
|
nodeType: "DocumentObject",
|
|
3209
|
+
references: document2.references.map((reference) => ({ ...reference })),
|
|
3063
3210
|
blocks: document2.blocks.map(cloneBlock),
|
|
3064
3211
|
diagnostics: document2.diagnostics.map((diagnostic) => ({ ...diagnostic }))
|
|
3065
3212
|
};
|
|
@@ -3380,12 +3527,340 @@ function removeDocument2ListItem(document2, listBlockId, itemId) {
|
|
|
3380
3527
|
});
|
|
3381
3528
|
return next;
|
|
3382
3529
|
}
|
|
3530
|
+
function citeTokenFromKeys(keys) {
|
|
3531
|
+
return { id: document2Id("cite"), kind: "cite", keys: [...keys] };
|
|
3532
|
+
}
|
|
3533
|
+
function insertCiteTokenAtCaret(document2, fieldId, textTokenId, caretOffset, keys) {
|
|
3534
|
+
if (keys.length === 0) {
|
|
3535
|
+
return document2;
|
|
3536
|
+
}
|
|
3537
|
+
const next = cloneDocument(document2);
|
|
3538
|
+
const citeToken = citeTokenFromKeys(keys);
|
|
3539
|
+
visitFields(next.blocks, (field) => {
|
|
3540
|
+
if (field.id !== fieldId) {
|
|
3541
|
+
return false;
|
|
3542
|
+
}
|
|
3543
|
+
const textIndex = textTokenId ? field.tokens.findIndex((token) => token.id === textTokenId && token.kind === "text") : field.tokens.findIndex((token) => token.kind === "text");
|
|
3544
|
+
if (textIndex < 0) {
|
|
3545
|
+
field.tokens.push(citeToken);
|
|
3546
|
+
field.tokens.push({ id: document2Id("text"), kind: "text", text: "" });
|
|
3547
|
+
return true;
|
|
3548
|
+
}
|
|
3549
|
+
const current = field.tokens[textIndex];
|
|
3550
|
+
const [before, after] = splitTextTokenAt(current, caretOffset);
|
|
3551
|
+
const parts = [...field.tokens.slice(0, textIndex)];
|
|
3552
|
+
if (before.text.length > 0) {
|
|
3553
|
+
parts.push(before);
|
|
3554
|
+
}
|
|
3555
|
+
parts.push(citeToken);
|
|
3556
|
+
parts.push(after);
|
|
3557
|
+
parts.push(...field.tokens.slice(textIndex + 1));
|
|
3558
|
+
field.tokens = normalizeFieldTokens(parts);
|
|
3559
|
+
return true;
|
|
3560
|
+
});
|
|
3561
|
+
return next;
|
|
3562
|
+
}
|
|
3563
|
+
function updateCiteTokenKeys(document2, tokenId, keys) {
|
|
3564
|
+
if (keys.length === 0) {
|
|
3565
|
+
return document2;
|
|
3566
|
+
}
|
|
3567
|
+
const next = cloneDocument(document2);
|
|
3568
|
+
visitFields(next.blocks, (field) => {
|
|
3569
|
+
const token = field.tokens.find((entry) => entry.id === tokenId && entry.kind === "cite");
|
|
3570
|
+
if (!token) {
|
|
3571
|
+
return false;
|
|
3572
|
+
}
|
|
3573
|
+
token.keys = [...keys];
|
|
3574
|
+
return true;
|
|
3575
|
+
});
|
|
3576
|
+
return next;
|
|
3577
|
+
}
|
|
3578
|
+
function removeCiteTokenById(document2, tokenId) {
|
|
3579
|
+
const next = cloneDocument(document2);
|
|
3580
|
+
visitFields(next.blocks, (field) => {
|
|
3581
|
+
const index = field.tokens.findIndex((token) => token.id === tokenId && token.kind === "cite");
|
|
3582
|
+
if (index < 0) {
|
|
3583
|
+
return false;
|
|
3584
|
+
}
|
|
3585
|
+
field.tokens = normalizeFieldTokens(stitchTextAroundRemovedToken(field.tokens, index));
|
|
3586
|
+
return true;
|
|
3587
|
+
});
|
|
3588
|
+
return next;
|
|
3589
|
+
}
|
|
3590
|
+
function ensureDocument2BibliographyBlock(document2, afterBlockId) {
|
|
3591
|
+
if (document2.blocks.some((block2) => block2.kind === "bibliography")) {
|
|
3592
|
+
return document2;
|
|
3593
|
+
}
|
|
3594
|
+
const block = {
|
|
3595
|
+
id: document2Id("block"),
|
|
3596
|
+
kind: "bibliography",
|
|
3597
|
+
command: "\\begin{thebibliography}",
|
|
3598
|
+
closing: "\\end{thebibliography}"
|
|
3599
|
+
};
|
|
3600
|
+
return insertDocument2BlockAfter(document2, afterBlockId ?? null, block);
|
|
3601
|
+
}
|
|
3602
|
+
function addDocument2Reference(document2, partial = {}) {
|
|
3603
|
+
const next = cloneDocument(document2);
|
|
3604
|
+
next.references.push(createEmptyReference2(partial));
|
|
3605
|
+
return next;
|
|
3606
|
+
}
|
|
3607
|
+
function updateDocument2Reference(document2, referenceId, patch) {
|
|
3608
|
+
const next = cloneDocument(document2);
|
|
3609
|
+
const reference = next.references.find((entry) => entry.id === referenceId);
|
|
3610
|
+
if (!reference) {
|
|
3611
|
+
return document2;
|
|
3612
|
+
}
|
|
3613
|
+
if (typeof patch.key === "string" && patch.key.trim().length > 0) {
|
|
3614
|
+
reference.key = patch.key.trim();
|
|
3615
|
+
}
|
|
3616
|
+
if (typeof patch.authors === "string") {
|
|
3617
|
+
reference.authors = patch.authors;
|
|
3618
|
+
}
|
|
3619
|
+
if (typeof patch.title === "string") {
|
|
3620
|
+
reference.title = patch.title;
|
|
3621
|
+
}
|
|
3622
|
+
if (typeof patch.year === "string") {
|
|
3623
|
+
reference.year = patch.year;
|
|
3624
|
+
}
|
|
3625
|
+
if (typeof patch.url === "string") {
|
|
3626
|
+
reference.url = patch.url;
|
|
3627
|
+
}
|
|
3628
|
+
if (typeof patch.venue === "string") {
|
|
3629
|
+
reference.venue = patch.venue;
|
|
3630
|
+
}
|
|
3631
|
+
return next;
|
|
3632
|
+
}
|
|
3633
|
+
function removeDocument2Reference(document2, referenceId) {
|
|
3634
|
+
const next = cloneDocument(document2);
|
|
3635
|
+
next.references = next.references.filter((reference) => reference.id !== referenceId);
|
|
3636
|
+
return next;
|
|
3637
|
+
}
|
|
3638
|
+
function moveDocument2Reference(document2, referenceId, direction) {
|
|
3639
|
+
const next = cloneDocument(document2);
|
|
3640
|
+
const index = next.references.findIndex((reference2) => reference2.id === referenceId);
|
|
3641
|
+
const targetIndex = index + direction;
|
|
3642
|
+
if (index < 0 || targetIndex < 0 || targetIndex >= next.references.length) {
|
|
3643
|
+
return document2;
|
|
3644
|
+
}
|
|
3645
|
+
const [reference] = next.references.splice(index, 1);
|
|
3646
|
+
if (!reference) {
|
|
3647
|
+
return document2;
|
|
3648
|
+
}
|
|
3649
|
+
next.references.splice(targetIndex, 0, reference);
|
|
3650
|
+
return next;
|
|
3651
|
+
}
|
|
3652
|
+
function setDocument2References(document2, references) {
|
|
3653
|
+
const next = cloneDocument(document2);
|
|
3654
|
+
next.references = references.map((reference) => ({ ...reference }));
|
|
3655
|
+
return next;
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3658
|
+
// src/document2/arabicPreamble.ts
|
|
3659
|
+
function arabicXeLatexPreamblePkg() {
|
|
3660
|
+
return String.raw`
|
|
3661
|
+
\documentclass[12pt,a4paper]{article}
|
|
3662
|
+
\usepackage{amsmath,amsfonts,amssymb,mathrsfs,tikz,fancyhdr, mathtools}
|
|
3663
|
+
\usepackage{fontspec} % For loading OpenType fonts
|
|
3664
|
+
\usepackage{unicode-math} % For setting the math font
|
|
3665
|
+
\usepackage{polyglossia} % For Arabic support
|
|
3666
|
+
\usepackage{array}
|
|
3667
|
+
\usepackage{cancel}
|
|
3668
|
+
\usepackage{bidi} % For bidirectional text handling
|
|
3669
|
+
\usepackage{multirow}
|
|
3670
|
+
\usepackage{booktabs}
|
|
3671
|
+
\usepackage{graphicx} % For \reflectbox
|
|
3672
|
+
\usepackage{xcolor}
|
|
3673
|
+
\usepackage{tikz}
|
|
3674
|
+
\usepackage{tcolorbox} % For tcolorbox environment
|
|
3675
|
+
\usepackage{textcomp} % For \textrightarrow command
|
|
3676
|
+
|
|
3677
|
+
|
|
3678
|
+
% visit : https://www.symbolcopy.com/punctuation-symbol.html
|
|
3679
|
+
% for inversed punctuation
|
|
3680
|
+
|
|
3681
|
+
% save inverted comma for use - copy paste -> ،
|
|
3682
|
+
% save back tick for use - copy paste -> ` + "`";
|
|
3683
|
+
}
|
|
3684
|
+
function arabicXeLatexPreambleFont(digitsMapping = "arabicdigits") {
|
|
3685
|
+
return `
|
|
3686
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3687
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3688
|
+
% Toggle between eastern and western digits by changing the Mapping in the below fonts (inside math font as well) between "arabicdigits" and "digits"
|
|
3689
|
+
\\setdefaultlanguage[calendar=gregorian]{arabic} % from polyglossia
|
|
3690
|
+
\\setmainfont[Script=Arabic , Mapping=${digitsMapping}]{Amiri}
|
|
3691
|
+
\\newfontfamily\\diwani[Script=Arabic,Mapping=${digitsMapping}]{Diwani Letter}
|
|
3692
|
+
\\newfontfamily\\diwanioutlineshaded[Script=Arabic,Mapping=${digitsMapping}]{Diwani Outline Shaded}
|
|
3693
|
+
\\newfontfamily\\takween[Script=Arabic,Mapping=${digitsMapping}]{Takween}
|
|
3694
|
+
\\newfontfamily\\boldarabic[Script=Arabic,Mapping=${digitsMapping}]{Amiri Bold}
|
|
3695
|
+
\\newfontfamily\\italicarabic[Script=Arabic,Mapping=${digitsMapping}]{Amiri Italic}
|
|
3696
|
+
|
|
3697
|
+
% Explicitly set math font to XITS Math
|
|
3698
|
+
% Remove "Script=Arabic" to cancel reflected symbols and other RTL symbols
|
|
3699
|
+
\\setmathfont[Script=Arabic , Mapping=${digitsMapping}]{XITS Math} % Ensure XITS Math is correctly installed and available
|
|
3700
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3701
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3702
|
+
`;
|
|
3703
|
+
}
|
|
3704
|
+
function arabicXeLatexPreambleCmd() {
|
|
3705
|
+
return String.raw`
|
|
3706
|
+
% Run with XeLaTeX compiler
|
|
3707
|
+
\newcommand{\butextakween}[1]{\text{\takween{#1}}}
|
|
3708
|
+
\newcommand{\butexdiwani}[1]{\text{\diwani{#1}}}
|
|
3709
|
+
\newcommand{\butexdiwanioutline}[1]{\text{\diwanioutlineshaded{#1}}}
|
|
3710
|
+
|
|
3711
|
+
\newcommand{\arabN}{\text{\diwanioutlineshaded{ط}}}
|
|
3712
|
+
\newcommand{\arabZ}{\text{\diwanioutlineshaded{ص}}}
|
|
3713
|
+
\newcommand{\arabQ}{\text{\diwanioutlineshaded{ن}}}
|
|
3714
|
+
\newcommand{\arabR}{\text{\diwanioutlineshaded{ح}}}
|
|
3715
|
+
\newcommand{\arabC}{\text{\diwanioutlineshaded{ع}}}
|
|
3716
|
+
\newcommand{\arabH}{\text{\diwanioutlineshaded{ر}}}
|
|
3717
|
+
|
|
3718
|
+
|
|
3719
|
+
\newcommand{\lowerscript}[1]{\raisebox{-4pt}{\scriptsize #1}}
|
|
3720
|
+
\newcommand{\llowerscript}[1]{\raisebox{-8pt}{\scriptsize #1}}
|
|
3721
|
+
\newcommand{\lllowerscript}[2]{\raisebox{#2pt}{\scriptsize #1}}
|
|
3722
|
+
|
|
3723
|
+
\newcommand{\arabdsub}[3]{\prescript{}{#1}{\prescript{}{#2}{#3}}} % arabic double subscript
|
|
3724
|
+
\newcommand{\arabsub}[2]{\prescript{}{#1}{#2}} % arabic single subscript
|
|
3725
|
+
|
|
3726
|
+
|
|
3727
|
+
|
|
3728
|
+
\newcommand{\upperscript}[1]{\raisebox{8pt}{\scriptsize #1}}
|
|
3729
|
+
\newcommand{\uupperscript}[2]{\raisebox{#2pt}{\scriptsize #1}}
|
|
3730
|
+
\newcommand{\vertbar}{\rule[-1ex]{0.5pt}{2.5ex}}
|
|
3731
|
+
\newcommand{\horzbar}{\rule[.5ex]{2.5ex}{0.5pt}}
|
|
3732
|
+
|
|
3733
|
+
\newcommand{\arabsqrt}[2]{\reflectbox{\(\sqrt[\reflectbox{\(#1\)}]{\reflectbox{\(#2\)}}\)}}
|
|
3734
|
+
\newcommand{\arabvec}[1]{\reflectbox{$\vec{\reflectbox{$#1$}}$}}
|
|
3735
|
+
|
|
3736
|
+
\newcommand{\arabexp}[1]{{}^{#1}\!\raisebox{-4.5pt}{\text{\diwani{ه}}}}
|
|
3737
|
+
\newcommand{\arablog}[2]{\left(\text{#2}\right)\!\prescript{}{\text{#1}}{\text{\diwani{لو}}}}
|
|
3738
|
+
\newcommand{\arabnlog}[1]{\left(\text{#1}\right)\!\prescript{}{\text{\diwani{ه}}}{\text{\diwani{لو}}}}
|
|
3739
|
+
|
|
3740
|
+
\newcommand{\arabcos}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{جتا}}}}
|
|
3741
|
+
\newcommand{\arabsin}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{جا}}}}
|
|
3742
|
+
\newcommand{\arabtan}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ظا}}}}
|
|
3743
|
+
\newcommand{\arabcot}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ظتا}}}}
|
|
3744
|
+
\newcommand{\arabsec}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قا}}}}
|
|
3745
|
+
\newcommand{\arabcsc}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قتا}}}}
|
|
3746
|
+
|
|
3747
|
+
\newcommand{\arabacos}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قجتا}}}}
|
|
3748
|
+
\newcommand{\arabasin}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قجا}}}}
|
|
3749
|
+
\newcommand{\arabatan}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قظا}}}}
|
|
3750
|
+
\newcommand{\arabacot}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قظتا}}}}
|
|
3751
|
+
\newcommand{\arabasec}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ققا}}}}
|
|
3752
|
+
\newcommand{\arabacsc}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ققتا}}}}
|
|
3753
|
+
|
|
3754
|
+
|
|
3755
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3756
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3757
|
+
% summation
|
|
3758
|
+
\newcommand{\arablim}[2]{\underset{#2 \leftarrow #1}{\text{نـــــها}}}
|
|
3759
|
+
\newcommand{\arabsum}[2]{\underset{#1}{\overset{#2}{\text{مجـــ}}}}
|
|
3760
|
+
\newcommand{\arabprod}[2]{\underset{#1}{\overset{#2}{\text{جـــذ}}}}
|
|
3761
|
+
\newcommand{\arabint}[2]{\prescript{#2}{#1\!\!\!}\int}
|
|
3762
|
+
|
|
3763
|
+
|
|
3764
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3765
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3766
|
+
% we define this command to make it ease for change of notation later
|
|
3767
|
+
\newcommand{\ad}[0]{\text{ء}} % "ad" for arabic differentiation or derivative (ء" لإشتقاق")
|
|
3768
|
+
\newcommand{\arpi}[0]{\!\text{\diwani{ط}}}
|
|
3769
|
+
|
|
3770
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3771
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3772
|
+
% differentials
|
|
3773
|
+
|
|
3774
|
+
\newcommand{\arabdiff}[2]{\frac{#1\ad}{#2\ad}} % arabic differential
|
|
3775
|
+
\newcommand{\arabddiff}[2]{\frac{#1{}^{2}\ad}{{}^{2}#2\ad}} % arabic second differential
|
|
3776
|
+
|
|
3777
|
+
\newcommand{\arabode}[2][-5pt]{\stackrel{\raisebox{#1}{$\cdot$}}{\text{#2}}}
|
|
3778
|
+
\newcommand{\arabodde}[2][-5pt]{\stackrel{\raisebox{#1}{$\vcenter{\hbox{$\cdot\!\cdot$}}$}}{\text{#2}}}
|
|
3779
|
+
\newcommand{\araboddde}[2][-5pt]{\stackrel{\raisebox{#1}{$\vcenter{\hbox{$\cdot\!\cdot\!\cdot$}}$}}{\text{#2}}}
|
|
3780
|
+
\newcommand{\arabpde}[1]{\prescript{}{#1\!\!}{\nabla}} % arabic partial differential equation (PDE)
|
|
3781
|
+
|
|
3782
|
+
\newcommand{\arabprime}[0]{\reflectbox{$\prime$}\!} % arabic prime notation
|
|
3783
|
+
\newcommand{\arabpprime}[0]{\reflectbox{$\prime$}\reflectbox{$\prime$}\!} % arabic prime notation
|
|
3784
|
+
\newcommand{\arabppprime}[0]{\reflectbox{$\prime$}\reflectbox{$\prime$}\reflectbox{$\prime$}\!} % arabic prime notation
|
|
3785
|
+
|
|
3786
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3787
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3788
|
+
% probability
|
|
3789
|
+
\newcommand{\ap}[0]{\!\text{\diwani{حـ}}} % arabic Probability - used a lot so short form
|
|
3790
|
+
\newcommand{\arabExpct}[0]{\text{\diwani{توقـ}}} % arabic Expectation
|
|
3791
|
+
\newcommand{\arabVar}[0]{\!\text{\diwani{با}}} % arabic Variance
|
|
3792
|
+
\newcommand{\arabCov}[0]{\!\text{\diwani{ت}}} % arabic Covariance
|
|
3793
|
+
|
|
3794
|
+
|
|
3795
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3796
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3797
|
+
% custom commands specific to lesson
|
|
3798
|
+
\newcommand{\lagrange}[2]{\left(#2\right)\!\prescript{}{#1}{\text{\diwani{لا}}}}
|
|
3799
|
+
\newcommand{\xii}[0]{\left(\prescript{}{\text{يـ}}{\text{س}}\right)\!}
|
|
3800
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3801
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
3802
|
+
|
|
3803
|
+
|
|
3804
|
+
\newcommand{\arsqrt}[2][]{\reflectbox{\(\sqrt[\reflectbox{\(#1\)}]{\reflectbox{\(#2\)}}\)}}
|
|
3805
|
+
\newcommand{\arexp}[0]{\!\raisebox{-4.5pt}{\text{\diwani{ه}}}}
|
|
3806
|
+
\newcommand{\arlog}[0]{\!\!\text{\diwani{لو}}}
|
|
3807
|
+
\newcommand{\arln}[0]{\!\!\prescript{}{\text{\diwani{ه}}}{\text{\diwani{لو}}}}
|
|
3808
|
+
\newcommand{\ardet}[0]{\!\!\text{\diwani{محدد}}}
|
|
3809
|
+
|
|
3810
|
+
\newcommand{\arsum}[0]{\text{مجـــ}}
|
|
3811
|
+
\newcommand{\arprod}[0]{\text{جـــذ}}
|
|
3812
|
+
|
|
3813
|
+
\newcommand{\arlim}[0]{\text{نـــــها}}
|
|
3814
|
+
\newcommand{\armax}[0]{\text{أكبر}}
|
|
3815
|
+
\newcommand{\armin}[0]{\text{أصغر}}
|
|
3816
|
+
\newcommand{\arsup}[0]{\text{أعلى}}
|
|
3817
|
+
\newcommand{\arinf}[0]{\text{أدنى}}
|
|
3818
|
+
|
|
3819
|
+
\newcommand{\arsin}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جا}}}}
|
|
3820
|
+
\newcommand{\arcos}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جتا}}}}
|
|
3821
|
+
\newcommand{\artan}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظا}}}}
|
|
3822
|
+
\newcommand{\arcot}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظتا}}}}
|
|
3823
|
+
\newcommand{\arsec}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قا}}}}
|
|
3824
|
+
\newcommand{\arcsc}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قتا}}}}
|
|
3825
|
+
|
|
3826
|
+
\newcommand{\arasin}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجا}}}}
|
|
3827
|
+
\newcommand{\aracos}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجتا}}}}
|
|
3828
|
+
\newcommand{\aratan}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظا}}}}
|
|
3829
|
+
\newcommand{\aracot}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظتا}}}}
|
|
3830
|
+
\newcommand{\arasec}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققا}}}}
|
|
3831
|
+
\newcommand{\aracsc}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققتا}}}}
|
|
3832
|
+
|
|
3833
|
+
\newcommand{\arsinh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جزا}}}}
|
|
3834
|
+
\newcommand{\arcosh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جتزا}}}}
|
|
3835
|
+
\newcommand{\artanh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظزا}}}}
|
|
3836
|
+
\newcommand{\arcoth}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظتزا}}}}
|
|
3837
|
+
\newcommand{\arsech}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قزا}}}}
|
|
3838
|
+
\newcommand{\arcsch}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قتزا}}}}
|
|
3839
|
+
|
|
3840
|
+
\newcommand{\arasinh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجزا}}}}
|
|
3841
|
+
\newcommand{\aracosh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجتزا}}}}
|
|
3842
|
+
\newcommand{\aratanh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظزا}}}}
|
|
3843
|
+
\newcommand{\aracoth}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظتزا}}}}
|
|
3844
|
+
\newcommand{\arasech}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققزا}}}}
|
|
3845
|
+
\newcommand{\aracsch}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققتزا}}}}
|
|
3846
|
+
|
|
3847
|
+
\newcommand{\unit}[1]{\text{#1}}
|
|
3848
|
+
\newcommand{\idx}[1]{#1}
|
|
3849
|
+
\newcommand{\arbinom}[2]{\left(\begin{array}{c} #1 \\ #2 \end{array} \right)}
|
|
3850
|
+
`;
|
|
3851
|
+
}
|
|
3852
|
+
function getArabicXeLatexPreamble(digitsMapping = "arabicdigits") {
|
|
3853
|
+
return arabicXeLatexPreamblePkg() + arabicXeLatexPreambleFont(digitsMapping) + arabicXeLatexPreambleCmd();
|
|
3854
|
+
}
|
|
3383
3855
|
|
|
3384
3856
|
// src/document2/exportLatex.ts
|
|
3385
3857
|
function tokenLatex(token) {
|
|
3386
3858
|
if (token.kind === "text") {
|
|
3387
3859
|
return token.text;
|
|
3388
3860
|
}
|
|
3861
|
+
if (token.kind === "cite") {
|
|
3862
|
+
return citeTokenLatex(token.keys);
|
|
3863
|
+
}
|
|
3389
3864
|
if (!token.math || token.sourceOwner === "raw" || token.sourceOwner === "editor") {
|
|
3390
3865
|
return token.source;
|
|
3391
3866
|
}
|
|
@@ -3400,9 +3875,9 @@ function textBlockLatex(block) {
|
|
|
3400
3875
|
function indent(value) {
|
|
3401
3876
|
return value.split("\n").map((line) => ` ${line}`).join("\n");
|
|
3402
3877
|
}
|
|
3403
|
-
function listBlockLatex(block) {
|
|
3878
|
+
function listBlockLatex(block, references) {
|
|
3404
3879
|
const items = block.items.map((item) => {
|
|
3405
|
-
const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child))).join("");
|
|
3880
|
+
const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child, references))).join("");
|
|
3406
3881
|
return ` \\item ${inlineFieldLatex(item.field)}${nested}`;
|
|
3407
3882
|
}).join("\n");
|
|
3408
3883
|
return `${block.command}
|
|
@@ -3422,12 +3897,12 @@ function imageOptionsLatex(block) {
|
|
|
3422
3897
|
}
|
|
3423
3898
|
return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
|
|
3424
3899
|
}
|
|
3425
|
-
function blockLatex(block) {
|
|
3900
|
+
function blockLatex(block, references) {
|
|
3426
3901
|
if (block.kind === "textBlock") {
|
|
3427
3902
|
return textBlockLatex(block);
|
|
3428
3903
|
}
|
|
3429
3904
|
if (block.kind === "list") {
|
|
3430
|
-
return listBlockLatex(block);
|
|
3905
|
+
return listBlockLatex(block, references);
|
|
3431
3906
|
}
|
|
3432
3907
|
if (block.kind === "table") {
|
|
3433
3908
|
return tableBlockLatex(block);
|
|
@@ -3435,10 +3910,29 @@ function blockLatex(block) {
|
|
|
3435
3910
|
if (block.kind === "image") {
|
|
3436
3911
|
return `${block.command}${imageOptionsLatex(block)}{${block.value}}`;
|
|
3437
3912
|
}
|
|
3913
|
+
if (block.kind === "bibliography") {
|
|
3914
|
+
const width = String(Math.max(references.length, 9));
|
|
3915
|
+
const items = references.map((reference) => ` ${bibliographyEntryLatex(reference)}`).join("\n");
|
|
3916
|
+
return `${block.command}{${width}}
|
|
3917
|
+
${items}
|
|
3918
|
+
${block.closing}`;
|
|
3919
|
+
}
|
|
3438
3920
|
return block.value;
|
|
3439
3921
|
}
|
|
3440
|
-
function document2Latex(document2) {
|
|
3441
|
-
|
|
3922
|
+
function document2Latex(document2, options = {}) {
|
|
3923
|
+
const body = document2.blocks.map((block) => blockLatex(block, document2.references)).join("\n\n");
|
|
3924
|
+
const wrapDocument = options.wrapDocument !== false;
|
|
3925
|
+
if (!wrapDocument) {
|
|
3926
|
+
return body;
|
|
3927
|
+
}
|
|
3928
|
+
const preamble = getArabicXeLatexPreamble(options.digitsMapping ?? "arabicdigits");
|
|
3929
|
+
return `${preamble}
|
|
3930
|
+
\\begin{document}
|
|
3931
|
+
|
|
3932
|
+
${body}
|
|
3933
|
+
|
|
3934
|
+
\\end{document}
|
|
3935
|
+
`;
|
|
3442
3936
|
}
|
|
3443
3937
|
|
|
3444
3938
|
// src/document2/history.ts
|
|
@@ -3476,16 +3970,24 @@ function document2HistoryCanRedo(stacks) {
|
|
|
3476
3970
|
|
|
3477
3971
|
// src/document2/previewModel.ts
|
|
3478
3972
|
function mathTex(token, equationSide) {
|
|
3479
|
-
if (token.kind === "text") {
|
|
3480
|
-
return token.text;
|
|
3481
|
-
}
|
|
3482
3973
|
return mathTokenSourceForSide(token, equationSide);
|
|
3483
3974
|
}
|
|
3484
|
-
function previewInlines(field, islands, output, equationSide) {
|
|
3975
|
+
function previewInlines(field, islands, output, equationSide, document2, previewOptions) {
|
|
3485
3976
|
return field.tokens.map((token) => {
|
|
3486
3977
|
if (token.kind === "text") {
|
|
3487
3978
|
return { kind: "text", text: token.text };
|
|
3488
3979
|
}
|
|
3980
|
+
if (token.kind === "cite") {
|
|
3981
|
+
return {
|
|
3982
|
+
kind: "cite",
|
|
3983
|
+
id: token.id,
|
|
3984
|
+
keys: [...token.keys],
|
|
3985
|
+
label: formatCiteLabel(token.keys, document2.references, {
|
|
3986
|
+
documentDirection: previewOptions.documentDirection,
|
|
3987
|
+
digitForm: previewOptions.digitForm
|
|
3988
|
+
})
|
|
3989
|
+
};
|
|
3990
|
+
}
|
|
3489
3991
|
const island = {
|
|
3490
3992
|
id: token.id,
|
|
3491
3993
|
tex: mathTex(token, equationSide),
|
|
@@ -3497,21 +3999,22 @@ function previewInlines(field, islands, output, equationSide) {
|
|
|
3497
3999
|
return { kind: "math", ...island };
|
|
3498
4000
|
});
|
|
3499
4001
|
}
|
|
3500
|
-
function textBlockPreview(block, islands, output, equationSide) {
|
|
4002
|
+
function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
4003
|
+
const inlines = previewInlines(block.field, islands, output, equationSide, document2, previewOptions);
|
|
3501
4004
|
if (block.command === "\\section") {
|
|
3502
|
-
return { kind: "heading", id: block.id, level: 1, inlines
|
|
4005
|
+
return { kind: "heading", id: block.id, level: 1, inlines };
|
|
3503
4006
|
}
|
|
3504
4007
|
if (block.command === "\\subsection") {
|
|
3505
|
-
return { kind: "heading", id: block.id, level: 2, inlines
|
|
4008
|
+
return { kind: "heading", id: block.id, level: 2, inlines };
|
|
3506
4009
|
}
|
|
3507
4010
|
if (block.command === "\\subsubsection") {
|
|
3508
|
-
return { kind: "heading", id: block.id, level: 3, inlines
|
|
4011
|
+
return { kind: "heading", id: block.id, level: 3, inlines };
|
|
3509
4012
|
}
|
|
3510
|
-
return { kind: "paragraph", id: block.id, inlines
|
|
4013
|
+
return { kind: "paragraph", id: block.id, inlines };
|
|
3511
4014
|
}
|
|
3512
|
-
function blockPreview(block, islands, output, equationSide) {
|
|
4015
|
+
function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
3513
4016
|
if (block.kind === "textBlock") {
|
|
3514
|
-
return textBlockPreview(block, islands, output, equationSide);
|
|
4017
|
+
return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
|
|
3515
4018
|
}
|
|
3516
4019
|
if (block.kind === "list") {
|
|
3517
4020
|
return {
|
|
@@ -3520,23 +4023,56 @@ function blockPreview(block, islands, output, equationSide) {
|
|
|
3520
4023
|
ordered: block.command === "\\begin{enumerate}",
|
|
3521
4024
|
items: block.items.map((item) => ({
|
|
3522
4025
|
id: item.id,
|
|
3523
|
-
inlines: previewInlines(item.field, islands, output, equationSide),
|
|
3524
|
-
blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide))
|
|
4026
|
+
inlines: previewInlines(item.field, islands, output, equationSide, document2, previewOptions),
|
|
4027
|
+
blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions))
|
|
3525
4028
|
}))
|
|
3526
4029
|
};
|
|
3527
4030
|
}
|
|
3528
4031
|
if (block.kind === "table") {
|
|
3529
|
-
return {
|
|
4032
|
+
return {
|
|
4033
|
+
kind: "table",
|
|
4034
|
+
id: block.id,
|
|
4035
|
+
rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions)))
|
|
4036
|
+
};
|
|
3530
4037
|
}
|
|
3531
4038
|
if (block.kind === "image") {
|
|
3532
|
-
return {
|
|
4039
|
+
return {
|
|
4040
|
+
kind: "image",
|
|
4041
|
+
id: block.id,
|
|
4042
|
+
src: block.value,
|
|
4043
|
+
...block.assetId !== void 0 ? { assetId: block.assetId } : {},
|
|
4044
|
+
options: block.options
|
|
4045
|
+
};
|
|
4046
|
+
}
|
|
4047
|
+
if (block.kind === "bibliography") {
|
|
4048
|
+
return {
|
|
4049
|
+
kind: "bibliography",
|
|
4050
|
+
id: block.id,
|
|
4051
|
+
items: document2.references.map((reference, index) => ({
|
|
4052
|
+
id: reference.id,
|
|
4053
|
+
numberLabel: formatBibliographyNumber(index + 1, {
|
|
4054
|
+
documentDirection: previewOptions.documentDirection,
|
|
4055
|
+
digitForm: previewOptions.digitForm
|
|
4056
|
+
}),
|
|
4057
|
+
key: reference.key,
|
|
4058
|
+
authors: reference.authors,
|
|
4059
|
+
title: reference.title,
|
|
4060
|
+
year: reference.year,
|
|
4061
|
+
url: reference.url,
|
|
4062
|
+
venue: reference.venue
|
|
4063
|
+
}))
|
|
4064
|
+
};
|
|
3533
4065
|
}
|
|
3534
4066
|
return { kind: "omit", id: block.id };
|
|
3535
4067
|
}
|
|
3536
|
-
function document2Preview(document2, output = "svg", equationSide = "arabic") {
|
|
4068
|
+
function document2Preview(document2, output = "svg", equationSide = "arabic", previewOptions = {}) {
|
|
3537
4069
|
const mathIslands = [];
|
|
4070
|
+
const options = {
|
|
4071
|
+
documentDirection: previewOptions.documentDirection ?? "rtl",
|
|
4072
|
+
digitForm: previewOptions.digitForm ?? (previewOptions.documentDirection === "ltr" ? "western" : "arabicIndic")
|
|
4073
|
+
};
|
|
3538
4074
|
return {
|
|
3539
|
-
blocks: document2.blocks.map((block) => blockPreview(block, mathIslands, output, equationSide)),
|
|
4075
|
+
blocks: document2.blocks.map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options)),
|
|
3540
4076
|
mathIslands
|
|
3541
4077
|
};
|
|
3542
4078
|
}
|
|
@@ -3545,22 +4081,35 @@ export {
|
|
|
3545
4081
|
addDocument2ImageBlock,
|
|
3546
4082
|
addDocument2ListBlock,
|
|
3547
4083
|
addDocument2ListItem,
|
|
4084
|
+
addDocument2Reference,
|
|
3548
4085
|
addDocument2TableBlock,
|
|
3549
4086
|
addDocument2TextBlock,
|
|
4087
|
+
arabicXeLatexPreambleCmd,
|
|
4088
|
+
arabicXeLatexPreambleFont,
|
|
4089
|
+
arabicXeLatexPreamblePkg,
|
|
4090
|
+
bibliographyEntryLatex,
|
|
4091
|
+
citeTokenLatex,
|
|
3550
4092
|
cloneDocument2Node,
|
|
3551
4093
|
createDocument2History,
|
|
3552
4094
|
createEmptyArabicEquationSession,
|
|
3553
4095
|
createEmptyDocument2,
|
|
3554
4096
|
createEmptyEquationSession,
|
|
4097
|
+
createEmptyReference2,
|
|
3555
4098
|
createInlineField2,
|
|
4099
|
+
detectInlineSpans2,
|
|
3556
4100
|
detectMathSpans2,
|
|
3557
4101
|
document2HistoryCanRedo,
|
|
3558
4102
|
document2HistoryCanUndo,
|
|
3559
4103
|
document2Latex,
|
|
3560
4104
|
document2Preview,
|
|
4105
|
+
ensureDocument2BibliographyBlock,
|
|
3561
4106
|
findFirstInlineField,
|
|
4107
|
+
formatBibliographyNumber,
|
|
4108
|
+
formatCiteLabel,
|
|
3562
4109
|
fromDocumentJson2,
|
|
4110
|
+
getArabicXeLatexPreamble,
|
|
3563
4111
|
inlineFieldLatex,
|
|
4112
|
+
insertCiteTokenAtCaret,
|
|
3564
4113
|
insertDocument2BlockAfter,
|
|
3565
4114
|
insertMathToken,
|
|
3566
4115
|
insertMathTokenAtCaret,
|
|
@@ -3572,14 +4121,24 @@ export {
|
|
|
3572
4121
|
mathTokenToArabicEditorSession,
|
|
3573
4122
|
mathTokenToEditorSession,
|
|
3574
4123
|
moveDocument2BlockById,
|
|
4124
|
+
moveDocument2Reference,
|
|
4125
|
+
parseCiteKeys,
|
|
3575
4126
|
pushDocument2Snapshot,
|
|
4127
|
+
referenceFromJson,
|
|
4128
|
+
referenceNumberMap,
|
|
4129
|
+
removeCiteTokenById,
|
|
3576
4130
|
removeDocument2BlockById,
|
|
3577
4131
|
removeDocument2ListItem,
|
|
4132
|
+
removeDocument2Reference,
|
|
3578
4133
|
removeMathTokenById,
|
|
3579
4134
|
replaceMathTokenFromSession,
|
|
4135
|
+
resolveCiteNumbers,
|
|
3580
4136
|
restoreDocument2Redo,
|
|
3581
4137
|
restoreDocument2Undo,
|
|
4138
|
+
setDocument2References,
|
|
4139
|
+
updateCiteTokenKeys,
|
|
3582
4140
|
updateDocument2ImageValue,
|
|
4141
|
+
updateDocument2Reference,
|
|
3583
4142
|
updateTextToken
|
|
3584
4143
|
};
|
|
3585
4144
|
//# sourceMappingURL=document2.mjs.map
|