@drghaliasri/butex 7.1.3 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document.d.mts +1 -2
- package/dist/document.d.ts +1 -2
- package/dist/document.js +55 -0
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +55 -0
- package/dist/document.mjs.map +1 -1
- package/dist/document2-cli.js +1712 -1
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +1 -1
- package/dist/document2.d.ts +1 -1
- package/dist/document2.js +66 -0
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +66 -0
- package/dist/document2.mjs.map +1 -1
- package/dist/index.d.mts +129 -2
- package/dist/index.d.ts +129 -2
- package/dist/index.global.js +98 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -0
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.js +77 -0
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +77 -0
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2-preview.js +61 -0
- package/dist/react-document2-preview.js.map +1 -1
- package/dist/react-document2-preview.mjs +61 -0
- package/dist/react-document2-preview.mjs.map +1 -1
- package/dist/react-document2.d.mts +1 -1
- package/dist/react-document2.d.ts +1 -1
- package/dist/react-document2.js +118 -0
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +118 -0
- package/dist/react-document2.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +77 -0
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +77 -0
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/document2-cli.js
CHANGED
|
@@ -1503,6 +1503,526 @@ function fromDocumentJson2(json, options = {}) {
|
|
|
1503
1503
|
};
|
|
1504
1504
|
}
|
|
1505
1505
|
|
|
1506
|
+
// src/editor/accentCommands.ts
|
|
1507
|
+
var ACCENT_COMMANDS = {
|
|
1508
|
+
vec: {
|
|
1509
|
+
id: "vec",
|
|
1510
|
+
englishTex: "\\vec",
|
|
1511
|
+
arabicTex: "\\arabvec",
|
|
1512
|
+
placement: "over",
|
|
1513
|
+
label: "\u20D7",
|
|
1514
|
+
title: "\u0633\u0647\u0645 \u0641\u0648\u0642"
|
|
1515
|
+
},
|
|
1516
|
+
hat: {
|
|
1517
|
+
id: "hat",
|
|
1518
|
+
englishTex: "\\hat",
|
|
1519
|
+
arabicTex: "\\hat",
|
|
1520
|
+
placement: "over",
|
|
1521
|
+
label: "\u02C6",
|
|
1522
|
+
title: "\u0642\u0628\u0639\u0629"
|
|
1523
|
+
},
|
|
1524
|
+
tilde: {
|
|
1525
|
+
id: "tilde",
|
|
1526
|
+
englishTex: "\\tilde",
|
|
1527
|
+
arabicTex: "\\tilde",
|
|
1528
|
+
placement: "over",
|
|
1529
|
+
label: "\u02DC",
|
|
1530
|
+
title: "\u0645\u062F\u0629"
|
|
1531
|
+
},
|
|
1532
|
+
dot: {
|
|
1533
|
+
id: "dot",
|
|
1534
|
+
englishTex: "\\dot",
|
|
1535
|
+
arabicTex: "\\dot",
|
|
1536
|
+
placement: "over",
|
|
1537
|
+
label: "\u02D9",
|
|
1538
|
+
title: "\u0646\u0642\u0637\u0629 \u0641\u0648\u0642"
|
|
1539
|
+
},
|
|
1540
|
+
ddot: {
|
|
1541
|
+
id: "ddot",
|
|
1542
|
+
englishTex: "\\ddot",
|
|
1543
|
+
arabicTex: "\\ddot",
|
|
1544
|
+
placement: "over",
|
|
1545
|
+
label: "\xA8",
|
|
1546
|
+
title: "\u0646\u0642\u0637\u062A\u0627\u0646 \u0641\u0648\u0642"
|
|
1547
|
+
},
|
|
1548
|
+
dddot: {
|
|
1549
|
+
id: "dddot",
|
|
1550
|
+
englishTex: "\\dddot",
|
|
1551
|
+
arabicTex: "\\dddot",
|
|
1552
|
+
placement: "over",
|
|
1553
|
+
label: "\u20DB",
|
|
1554
|
+
title: "\u062B\u0644\u0627\u062B \u0646\u0642\u0627\u0637 \u0641\u0648\u0642"
|
|
1555
|
+
},
|
|
1556
|
+
bar: {
|
|
1557
|
+
id: "bar",
|
|
1558
|
+
englishTex: "\\bar",
|
|
1559
|
+
arabicTex: "\\bar",
|
|
1560
|
+
placement: "over",
|
|
1561
|
+
label: "\xAF",
|
|
1562
|
+
title: "\u062E\u0637 \u0641\u0648\u0642"
|
|
1563
|
+
},
|
|
1564
|
+
check: {
|
|
1565
|
+
id: "check",
|
|
1566
|
+
englishTex: "\\check",
|
|
1567
|
+
arabicTex: "\\check",
|
|
1568
|
+
placement: "over",
|
|
1569
|
+
label: "\u02C7",
|
|
1570
|
+
title: "\u0639\u0644\u0627\u0645\u0629 \u062A\u062D\u0642\u0642"
|
|
1571
|
+
},
|
|
1572
|
+
breve: {
|
|
1573
|
+
id: "breve",
|
|
1574
|
+
englishTex: "\\breve",
|
|
1575
|
+
arabicTex: "\\breve",
|
|
1576
|
+
placement: "over",
|
|
1577
|
+
label: "\u02D8",
|
|
1578
|
+
title: "\u0642\u0648\u0633 \u0642\u0635\u064A\u0631"
|
|
1579
|
+
},
|
|
1580
|
+
acute: {
|
|
1581
|
+
id: "acute",
|
|
1582
|
+
englishTex: "\\acute",
|
|
1583
|
+
arabicTex: "\\grave",
|
|
1584
|
+
placement: "over",
|
|
1585
|
+
label: "\xB4",
|
|
1586
|
+
title: "\u0646\u0628\u0631\u0629 \u062D\u0627\u062F\u0629"
|
|
1587
|
+
},
|
|
1588
|
+
grave: {
|
|
1589
|
+
id: "grave",
|
|
1590
|
+
englishTex: "\\grave",
|
|
1591
|
+
arabicTex: "\\acute",
|
|
1592
|
+
placement: "over",
|
|
1593
|
+
label: "`",
|
|
1594
|
+
title: "\u0646\u0628\u0631\u0629 \u062B\u0642\u064A\u0644\u0629"
|
|
1595
|
+
},
|
|
1596
|
+
overline: {
|
|
1597
|
+
id: "overline",
|
|
1598
|
+
englishTex: "\\overline",
|
|
1599
|
+
arabicTex: "\\overline",
|
|
1600
|
+
placement: "over",
|
|
1601
|
+
label: "\u203E",
|
|
1602
|
+
title: "\u062E\u0637 \u0639\u0644\u0648\u064A \u0645\u0645\u062A\u062F"
|
|
1603
|
+
},
|
|
1604
|
+
underline: {
|
|
1605
|
+
id: "underline",
|
|
1606
|
+
englishTex: "\\underline",
|
|
1607
|
+
arabicTex: "\\underline",
|
|
1608
|
+
placement: "under",
|
|
1609
|
+
label: "_",
|
|
1610
|
+
title: "\u062E\u0637 \u0633\u0641\u0644\u064A"
|
|
1611
|
+
},
|
|
1612
|
+
overleftarrow: {
|
|
1613
|
+
id: "overleftarrow",
|
|
1614
|
+
englishTex: "\\overleftarrow",
|
|
1615
|
+
arabicTex: "\\overrightarrow",
|
|
1616
|
+
placement: "over",
|
|
1617
|
+
label: "\u2190",
|
|
1618
|
+
title: "\u0633\u0647\u0645 \u0639\u0644\u0648\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0633\u0627\u0631"
|
|
1619
|
+
},
|
|
1620
|
+
overrightarrow: {
|
|
1621
|
+
id: "overrightarrow",
|
|
1622
|
+
englishTex: "\\overrightarrow",
|
|
1623
|
+
arabicTex: "\\overleftarrow",
|
|
1624
|
+
placement: "over",
|
|
1625
|
+
label: "\u2192",
|
|
1626
|
+
title: "\u0633\u0647\u0645 \u0639\u0644\u0648\u064A \u0625\u0644\u0649 \u0627\u0644\u064A\u0645\u064A\u0646"
|
|
1627
|
+
},
|
|
1628
|
+
overleftrightarrow: {
|
|
1629
|
+
id: "overleftrightarrow",
|
|
1630
|
+
englishTex: "\\overleftrightarrow",
|
|
1631
|
+
arabicTex: "\\overleftrightarrow",
|
|
1632
|
+
placement: "over",
|
|
1633
|
+
label: "\u2194",
|
|
1634
|
+
title: "\u0633\u0647\u0645 \u0639\u0644\u0648\u064A \u0645\u0632\u062F\u0648\u062C \u0627\u0644\u0627\u062A\u062C\u0627\u0647"
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
function accentCommandSpec(id) {
|
|
1638
|
+
return Object.prototype.hasOwnProperty.call(ACCENT_COMMANDS, id) ? ACCENT_COMMANDS[id] : null;
|
|
1639
|
+
}
|
|
1640
|
+
function accentCommandIdFromTex(tex) {
|
|
1641
|
+
const normalized = tex.startsWith("\\") ? tex : `\\${tex}`;
|
|
1642
|
+
for (const spec of Object.values(ACCENT_COMMANDS)) {
|
|
1643
|
+
if (spec.englishTex === normalized) {
|
|
1644
|
+
return spec.id;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
for (const spec of Object.values(ACCENT_COMMANDS)) {
|
|
1648
|
+
if (spec.arabicTex === normalized) {
|
|
1649
|
+
return spec.id;
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
return null;
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
// src/editor/atomicCommands.ts
|
|
1656
|
+
var ATOMIC_COMMANDS = {
|
|
1657
|
+
///////////////////////// Functions ////////////////////////////////
|
|
1658
|
+
//////////////// Trigonometric Functions
|
|
1659
|
+
cos: {
|
|
1660
|
+
id: "cos",
|
|
1661
|
+
category: "function",
|
|
1662
|
+
englishTex: "\\cos",
|
|
1663
|
+
arabicTex: "\\arcos",
|
|
1664
|
+
arabicLabel: "\u062C\u062A\u0627",
|
|
1665
|
+
title: "\u062C\u064A\u0628 \u0627\u0644\u062A\u0645\u0627\u0645"
|
|
1666
|
+
},
|
|
1667
|
+
sin: {
|
|
1668
|
+
id: "sin",
|
|
1669
|
+
category: "function",
|
|
1670
|
+
englishTex: "\\sin",
|
|
1671
|
+
arabicTex: "\\arsin",
|
|
1672
|
+
arabicLabel: "\u062C\u0627",
|
|
1673
|
+
title: "\u062C\u064A\u0628"
|
|
1674
|
+
},
|
|
1675
|
+
tan: {
|
|
1676
|
+
id: "tan",
|
|
1677
|
+
category: "function",
|
|
1678
|
+
englishTex: "\\tan",
|
|
1679
|
+
arabicTex: "\\artan",
|
|
1680
|
+
arabicLabel: "\u0638\u0627",
|
|
1681
|
+
title: "\u0638\u0644"
|
|
1682
|
+
},
|
|
1683
|
+
cot: {
|
|
1684
|
+
id: "cot",
|
|
1685
|
+
category: "function",
|
|
1686
|
+
englishTex: "\\cot",
|
|
1687
|
+
arabicTex: "\\arcot",
|
|
1688
|
+
arabicLabel: "\u0638\u062A\u0627",
|
|
1689
|
+
title: "\u0638\u0644 \u062A\u0645\u0627\u0645"
|
|
1690
|
+
},
|
|
1691
|
+
sec: {
|
|
1692
|
+
id: "sec",
|
|
1693
|
+
category: "function",
|
|
1694
|
+
englishTex: "\\sec",
|
|
1695
|
+
arabicTex: "\\arsec",
|
|
1696
|
+
arabicLabel: "\u0642\u0627",
|
|
1697
|
+
title: "\u0642\u0627\u0637\u0639"
|
|
1698
|
+
},
|
|
1699
|
+
csc: {
|
|
1700
|
+
id: "csc",
|
|
1701
|
+
category: "function",
|
|
1702
|
+
englishTex: "\\csc",
|
|
1703
|
+
arabicTex: "\\arcsc",
|
|
1704
|
+
arabicLabel: "\u0642\u062A\u0627",
|
|
1705
|
+
title: "\u0642\u0627\u0637\u0639 \u062A\u0645\u0627\u0645"
|
|
1706
|
+
},
|
|
1707
|
+
/////////////////// Arc Trigonometric Functions
|
|
1708
|
+
arccos: {
|
|
1709
|
+
id: "arccos",
|
|
1710
|
+
category: "function",
|
|
1711
|
+
englishTex: "\\arccos",
|
|
1712
|
+
arabicTex: "\\aracos",
|
|
1713
|
+
arabicLabel: "\u0642\u062C\u062A\u0627",
|
|
1714
|
+
title: "\u0642\u0627\u0637\u0639 \u062C\u064A\u0628 \u0627\u0644\u062A\u0645\u0627\u0645"
|
|
1715
|
+
},
|
|
1716
|
+
arcsin: {
|
|
1717
|
+
id: "arcsin",
|
|
1718
|
+
category: "function",
|
|
1719
|
+
englishTex: "\\arcsin",
|
|
1720
|
+
arabicTex: "\\arasin",
|
|
1721
|
+
arabicLabel: "\u0642\u062C\u0627",
|
|
1722
|
+
title: "\u0642\u0627\u0637\u0639 \u062C\u064A\u0628"
|
|
1723
|
+
},
|
|
1724
|
+
arctan: {
|
|
1725
|
+
id: "arctan",
|
|
1726
|
+
category: "function",
|
|
1727
|
+
englishTex: "\\arctan",
|
|
1728
|
+
arabicTex: "\\aratan",
|
|
1729
|
+
arabicLabel: "\u0642\u0638\u0627",
|
|
1730
|
+
title: "\u0642\u0627\u0637\u0639 \u0638\u0644"
|
|
1731
|
+
},
|
|
1732
|
+
arccot: {
|
|
1733
|
+
id: "arccot",
|
|
1734
|
+
category: "function",
|
|
1735
|
+
englishTex: "\\arccot",
|
|
1736
|
+
arabicTex: "\\aracot",
|
|
1737
|
+
arabicLabel: "\u0642\u0638\u062A\u0627",
|
|
1738
|
+
title: "\u0642\u0627\u0637\u0639 \u0638\u0644 \u0627\u0644\u062A\u0645\u0627\u0645"
|
|
1739
|
+
},
|
|
1740
|
+
arcsec: {
|
|
1741
|
+
id: "arcsec",
|
|
1742
|
+
category: "function",
|
|
1743
|
+
englishTex: "\\arcsec",
|
|
1744
|
+
arabicTex: "\\arasec",
|
|
1745
|
+
arabicLabel: "\u0642\u0642\u0627",
|
|
1746
|
+
title: "\u0642\u0627\u0637\u0639 \u0627\u0644\u0642\u0627\u0637\u0639"
|
|
1747
|
+
},
|
|
1748
|
+
arccsc: {
|
|
1749
|
+
id: "arccsc",
|
|
1750
|
+
category: "function",
|
|
1751
|
+
englishTex: "\\arccsc",
|
|
1752
|
+
arabicTex: "\\aracsc",
|
|
1753
|
+
arabicLabel: "\u0642\u0642\u062A\u0627",
|
|
1754
|
+
title: "\u0642\u0627\u0637\u0639 \u0627\u0644\u0642\u0627\u0637\u0639 \u0627\u0644\u062A\u0645\u0627\u0645"
|
|
1755
|
+
},
|
|
1756
|
+
///////////////// Hyperbolic Functions
|
|
1757
|
+
cosh: {
|
|
1758
|
+
id: "cosh",
|
|
1759
|
+
category: "function",
|
|
1760
|
+
englishTex: "\\cosh",
|
|
1761
|
+
arabicTex: "\\arcosh",
|
|
1762
|
+
arabicLabel: "\u062C\u062A\u0632\u0627",
|
|
1763
|
+
title: "\u062C\u064A\u0628 \u0627\u0644\u062A\u0645\u0627\u0645 \u0627\u0644\u0632\u0627\u0626\u062F"
|
|
1764
|
+
},
|
|
1765
|
+
sinh: {
|
|
1766
|
+
id: "sinh",
|
|
1767
|
+
category: "function",
|
|
1768
|
+
englishTex: "\\sinh",
|
|
1769
|
+
arabicTex: "\\arsinh",
|
|
1770
|
+
arabicLabel: "\u062C\u0632\u0627",
|
|
1771
|
+
title: "\u062C\u064A\u0628 \u0627\u0644\u0632\u0627\u0626\u062F"
|
|
1772
|
+
},
|
|
1773
|
+
tanh: {
|
|
1774
|
+
id: "tanh",
|
|
1775
|
+
category: "function",
|
|
1776
|
+
englishTex: "\\tanh",
|
|
1777
|
+
arabicTex: "\\artanh",
|
|
1778
|
+
arabicLabel: "\u0638\u0632\u0627",
|
|
1779
|
+
title: "\u0638\u0644 \u0627\u0644\u0632\u0627\u0626\u062F"
|
|
1780
|
+
},
|
|
1781
|
+
coth: {
|
|
1782
|
+
id: "coth",
|
|
1783
|
+
category: "function",
|
|
1784
|
+
englishTex: "\\coth",
|
|
1785
|
+
arabicTex: "\\arcoth",
|
|
1786
|
+
arabicLabel: "\u0638\u062A\u0632\u0627",
|
|
1787
|
+
title: "\u0638\u0644 \u062A\u0645\u0627\u0645 \u0627\u0644\u0632\u0627\u0626\u062F"
|
|
1788
|
+
},
|
|
1789
|
+
////// These function somehow doesnt exist in LaTeX and therefore MathJax, skip for now. no problem.
|
|
1790
|
+
// sech: {
|
|
1791
|
+
// id: 'sech',
|
|
1792
|
+
// category: 'function',
|
|
1793
|
+
// englishTex: '\\sech',
|
|
1794
|
+
// arabicTex: '\\arsech',
|
|
1795
|
+
// arabicLabel: 'قزا',
|
|
1796
|
+
// title: 'قاطع الزائد',
|
|
1797
|
+
// },
|
|
1798
|
+
// csch: {
|
|
1799
|
+
// id: 'csch',
|
|
1800
|
+
// category: 'function',
|
|
1801
|
+
// englishTex: '\\csch',
|
|
1802
|
+
// arabicTex: '\\arcsch',
|
|
1803
|
+
// arabicLabel: 'قتزا',
|
|
1804
|
+
// title: 'قاطع تمام الزائد',
|
|
1805
|
+
// },
|
|
1806
|
+
///////////////// arc Hyperbolic Functions
|
|
1807
|
+
///// Not on MathJax, skip for now, it is okay.
|
|
1808
|
+
////////////////////// Limits & Series ////////////////////////////////
|
|
1809
|
+
sum: {
|
|
1810
|
+
id: "sum",
|
|
1811
|
+
category: "limits_series",
|
|
1812
|
+
englishTex: "\\sum",
|
|
1813
|
+
arabicTex: "\\arsum",
|
|
1814
|
+
arabicLabel: "\u0645\u062C\u0640\u0640\u0640",
|
|
1815
|
+
title: "\u0645\u062C\u0645\u0648\u0639"
|
|
1816
|
+
},
|
|
1817
|
+
prod: {
|
|
1818
|
+
id: "prod",
|
|
1819
|
+
category: "limits_series",
|
|
1820
|
+
englishTex: "\\prod",
|
|
1821
|
+
arabicTex: "\\arprod",
|
|
1822
|
+
arabicLabel: "\u062C\u0640\u0640\u0640\u062F",
|
|
1823
|
+
title: "\u062C\u062F\u0627\u0621"
|
|
1824
|
+
},
|
|
1825
|
+
lim: {
|
|
1826
|
+
id: "lim",
|
|
1827
|
+
category: "limits_series",
|
|
1828
|
+
englishTex: "\\lim",
|
|
1829
|
+
arabicTex: "\\arlim",
|
|
1830
|
+
arabicLabel: "\u0646\u0640\u0640\u0640\u0640\u0640\u0647\u0627",
|
|
1831
|
+
title: "\u062D\u062F"
|
|
1832
|
+
},
|
|
1833
|
+
arg: {
|
|
1834
|
+
id: "arg",
|
|
1835
|
+
category: "limits_series",
|
|
1836
|
+
englishTex: "\\arg",
|
|
1837
|
+
arabicTex: "\\ararg",
|
|
1838
|
+
arabicLabel: "\u062D\u062C",
|
|
1839
|
+
title: "\u062D\u062C\u0629"
|
|
1840
|
+
},
|
|
1841
|
+
max: {
|
|
1842
|
+
id: "max",
|
|
1843
|
+
category: "limits_series",
|
|
1844
|
+
englishTex: "\\max",
|
|
1845
|
+
arabicTex: "\\armax",
|
|
1846
|
+
arabicLabel: "\u0623\u0643\u0628\u0631",
|
|
1847
|
+
title: "\u0623\u0643\u0628\u0631"
|
|
1848
|
+
},
|
|
1849
|
+
min: {
|
|
1850
|
+
id: "min",
|
|
1851
|
+
category: "limits_series",
|
|
1852
|
+
englishTex: "\\min",
|
|
1853
|
+
arabicTex: "\\armin",
|
|
1854
|
+
arabicLabel: "\u0623\u0635\u063A\u0631",
|
|
1855
|
+
title: "\u0623\u0635\u063A\u0631"
|
|
1856
|
+
},
|
|
1857
|
+
sup: {
|
|
1858
|
+
id: "sup",
|
|
1859
|
+
category: "limits_series",
|
|
1860
|
+
englishTex: "\\sup",
|
|
1861
|
+
arabicTex: "\\arsup",
|
|
1862
|
+
arabicLabel: "\u0623\u0639\u0644\u0649",
|
|
1863
|
+
title: "\u0623\u0639\u0644\u0649"
|
|
1864
|
+
},
|
|
1865
|
+
inf: {
|
|
1866
|
+
id: "inf",
|
|
1867
|
+
category: "limits_series",
|
|
1868
|
+
englishTex: "\\inf",
|
|
1869
|
+
arabicTex: "\\arinf",
|
|
1870
|
+
arabicLabel: "\u0623\u062F\u0646\u0649",
|
|
1871
|
+
title: "\u0623\u062F\u0646\u0649"
|
|
1872
|
+
},
|
|
1873
|
+
////////////////////// Logarithmic and Exponential and Determinant Functions ////////////////////////////////
|
|
1874
|
+
pi: {
|
|
1875
|
+
id: "pi",
|
|
1876
|
+
category: "function2",
|
|
1877
|
+
englishTex: "\\pi",
|
|
1878
|
+
arabicTex: "\\arpi",
|
|
1879
|
+
arabicLabel: "\u0637",
|
|
1880
|
+
title: "\u0646\u0633\u0628\u0629 \u0627\u0644\u062F\u0627\u0626\u0631\u0629"
|
|
1881
|
+
},
|
|
1882
|
+
exp: {
|
|
1883
|
+
id: "exp",
|
|
1884
|
+
category: "function2",
|
|
1885
|
+
englishTex: "\\exp",
|
|
1886
|
+
arabicTex: "\\arexp",
|
|
1887
|
+
arabicLabel: "\u0647\u0640",
|
|
1888
|
+
title: "\u0623\u0633\u064A\u0629"
|
|
1889
|
+
},
|
|
1890
|
+
ln: {
|
|
1891
|
+
id: "ln",
|
|
1892
|
+
category: "function2",
|
|
1893
|
+
englishTex: "\\ln",
|
|
1894
|
+
arabicTex: "\\arln",
|
|
1895
|
+
arabicRenderTex: "\\prescript{}{\\arexp}{\\arlog}",
|
|
1896
|
+
arabicLabel: "\u0644\u0648",
|
|
1897
|
+
title: "\u0644\u0648\u063A\u0627\u0631\u064A\u062A\u0645 \u0637\u0628\u064A\u0639\u064A"
|
|
1898
|
+
},
|
|
1899
|
+
log: {
|
|
1900
|
+
id: "log",
|
|
1901
|
+
category: "function2",
|
|
1902
|
+
englishTex: "\\log",
|
|
1903
|
+
arabicTex: "\\arlog",
|
|
1904
|
+
arabicLabel: "\u0644\u0648",
|
|
1905
|
+
title: "\u0644\u0648\u063A\u0627\u0631\u064A\u062A\u0645"
|
|
1906
|
+
},
|
|
1907
|
+
det: {
|
|
1908
|
+
id: "det",
|
|
1909
|
+
category: "function2",
|
|
1910
|
+
englishTex: "\\det",
|
|
1911
|
+
arabicTex: "\\ardet",
|
|
1912
|
+
arabicLabel: "\u0645\u062D\u062F\u062F",
|
|
1913
|
+
title: "\u0645\u062D\u062F\u062F"
|
|
1914
|
+
},
|
|
1915
|
+
////////////////////// Derivatives ////////////////////////////////
|
|
1916
|
+
ad: {
|
|
1917
|
+
id: "ad",
|
|
1918
|
+
category: "derivative",
|
|
1919
|
+
englishTex: "\\mathrm{d}",
|
|
1920
|
+
englishLabel: "d",
|
|
1921
|
+
arabicTex: "\\ad",
|
|
1922
|
+
arabicLabel: "\u0621",
|
|
1923
|
+
title: "\u0639\u0644\u0627\u0645\u0629 \u0627\u0644\u0627\u0634\u062A\u0642\u0627\u0642"
|
|
1924
|
+
},
|
|
1925
|
+
////////////////////// Groups /////////////////////////////////
|
|
1926
|
+
N: {
|
|
1927
|
+
id: "N",
|
|
1928
|
+
category: "groups",
|
|
1929
|
+
englishTex: "\\mathbb{N}",
|
|
1930
|
+
arabicTex: "\\arabN",
|
|
1931
|
+
arabicLabel: "\u0637",
|
|
1932
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u0637\u0628\u064A\u0639\u064A\u0629"
|
|
1933
|
+
},
|
|
1934
|
+
Z: {
|
|
1935
|
+
id: "Z",
|
|
1936
|
+
category: "groups",
|
|
1937
|
+
englishTex: "\\mathbb{Z}",
|
|
1938
|
+
arabicTex: "\\arabZ",
|
|
1939
|
+
arabicLabel: "\u0635",
|
|
1940
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u0635\u062D\u064A\u062D\u0629"
|
|
1941
|
+
},
|
|
1942
|
+
Q: {
|
|
1943
|
+
id: "Q",
|
|
1944
|
+
category: "groups",
|
|
1945
|
+
englishTex: "\\mathbb{Q}",
|
|
1946
|
+
arabicTex: "\\arabQ",
|
|
1947
|
+
arabicLabel: "\u0646",
|
|
1948
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u0646\u0633\u0628\u064A\u0629"
|
|
1949
|
+
},
|
|
1950
|
+
R: {
|
|
1951
|
+
id: "R",
|
|
1952
|
+
category: "groups",
|
|
1953
|
+
englishTex: "\\mathbb{R}",
|
|
1954
|
+
arabicTex: "\\arabR",
|
|
1955
|
+
arabicLabel: "\u062D",
|
|
1956
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u062D\u0642\u064A\u0642\u064A\u0629"
|
|
1957
|
+
},
|
|
1958
|
+
C: {
|
|
1959
|
+
id: "C",
|
|
1960
|
+
category: "groups",
|
|
1961
|
+
englishTex: "\\mathbb{C}",
|
|
1962
|
+
arabicTex: "\\arabC",
|
|
1963
|
+
arabicLabel: "\u0639",
|
|
1964
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u0639\u064F\u0642\u062F\u064A\u0629"
|
|
1965
|
+
},
|
|
1966
|
+
H: {
|
|
1967
|
+
id: "H",
|
|
1968
|
+
category: "groups",
|
|
1969
|
+
englishTex: "\\mathbb{H}",
|
|
1970
|
+
arabicTex: "\\arabH",
|
|
1971
|
+
arabicLabel: "\u0631",
|
|
1972
|
+
title: "\u0623\u0639\u062F\u0627\u062F \u0631\u0628\u0627\u0639\u064A\u0629"
|
|
1973
|
+
},
|
|
1974
|
+
////////////////////// Operations ////////////////////////////
|
|
1975
|
+
////////////////////// Spacing ////////////////////////////////
|
|
1976
|
+
negThinSpace: {
|
|
1977
|
+
id: "negThinSpace",
|
|
1978
|
+
category: "spacing",
|
|
1979
|
+
englishTex: "\\!",
|
|
1980
|
+
arabicTex: "\\!",
|
|
1981
|
+
arabicLabel: "",
|
|
1982
|
+
title: "\u0641\u0631\u0627\u063A \u0633\u0627\u0644\u0628 \u0631\u0641\u064A\u0639",
|
|
1983
|
+
spacing: { direction: "negative", level: 1 }
|
|
1984
|
+
},
|
|
1985
|
+
mediumSpace: {
|
|
1986
|
+
id: "mediumSpace",
|
|
1987
|
+
category: "spacing",
|
|
1988
|
+
englishTex: "\\:",
|
|
1989
|
+
arabicTex: "\\:",
|
|
1990
|
+
arabicLabel: "",
|
|
1991
|
+
title: "\u0641\u0631\u0627\u063A \u0645\u062A\u0648\u0633\u0637",
|
|
1992
|
+
spacing: { direction: "positive", level: 1 }
|
|
1993
|
+
},
|
|
1994
|
+
thickSpace: {
|
|
1995
|
+
id: "thickSpace",
|
|
1996
|
+
category: "spacing",
|
|
1997
|
+
englishTex: "\\;",
|
|
1998
|
+
arabicTex: "\\;",
|
|
1999
|
+
arabicLabel: "",
|
|
2000
|
+
title: "\u0641\u0631\u0627\u063A \u0639\u0631\u064A\u0636",
|
|
2001
|
+
spacing: { direction: "positive", level: 2 }
|
|
2002
|
+
},
|
|
2003
|
+
quadSpace: {
|
|
2004
|
+
id: "quadSpace",
|
|
2005
|
+
category: "spacing",
|
|
2006
|
+
englishTex: "\\quad",
|
|
2007
|
+
arabicTex: "\\quad",
|
|
2008
|
+
arabicLabel: "",
|
|
2009
|
+
title: "\u0641\u0631\u0627\u063A \u0643\u0628\u064A\u0631",
|
|
2010
|
+
spacing: { direction: "positive", level: 3 }
|
|
2011
|
+
},
|
|
2012
|
+
qquadSpace: {
|
|
2013
|
+
id: "qquadSpace",
|
|
2014
|
+
category: "spacing",
|
|
2015
|
+
englishTex: "\\qquad",
|
|
2016
|
+
arabicTex: "\\qquad",
|
|
2017
|
+
arabicLabel: "",
|
|
2018
|
+
title: "\u0641\u0631\u0627\u063A \u0643\u0628\u064A\u0631 \u062C\u062F\u0627",
|
|
2019
|
+
spacing: { direction: "positive", level: 4 }
|
|
2020
|
+
}
|
|
2021
|
+
};
|
|
2022
|
+
function atomicCommandSpec(id) {
|
|
2023
|
+
return Object.prototype.hasOwnProperty.call(ATOMIC_COMMANDS, id) ? ATOMIC_COMMANDS[id] : null;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
1506
2026
|
// src/editor/atomicCommandsOperators.ts
|
|
1507
2027
|
var ATOMIC_OPERATOR_COMMANDS = {
|
|
1508
2028
|
inf: {
|
|
@@ -2111,6 +2631,230 @@ function mirrorBuTeXOperatorsInTex(tex, options = {}) {
|
|
|
2111
2631
|
}
|
|
2112
2632
|
return result;
|
|
2113
2633
|
}
|
|
2634
|
+
function atomicOperatorCommandSpec(id) {
|
|
2635
|
+
return Object.prototype.hasOwnProperty.call(ATOMIC_OPERATOR_COMMANDS, id) ? ATOMIC_OPERATOR_COMMANDS[id] : null;
|
|
2636
|
+
}
|
|
2637
|
+
|
|
2638
|
+
// src/editor/standardCommands.ts
|
|
2639
|
+
var STANDARD_COMMANDS = {
|
|
2640
|
+
"\\alpha": { tex: "\\alpha", label: "\u03B1", title: "alpha" },
|
|
2641
|
+
"\\beta": { tex: "\\beta", label: "\u03B2", title: "beta" },
|
|
2642
|
+
"\\gamma": { tex: "\\gamma", label: "\u03B3", title: "gamma" },
|
|
2643
|
+
"\\delta": { tex: "\\delta", label: "\u03B4", title: "delta" },
|
|
2644
|
+
"\\epsilon": { tex: "\\epsilon", label: "\u03B5", title: "epsilon" },
|
|
2645
|
+
"\\eta": { tex: "\\eta", label: "\u03B7", title: "eta" },
|
|
2646
|
+
"\\theta": { tex: "\\theta", label: "\u03B8", title: "theta" },
|
|
2647
|
+
"\\lambda": { tex: "\\lambda", label: "\u03BB", title: "lambda" },
|
|
2648
|
+
"\\mu": { tex: "\\mu", label: "\u03BC", title: "mu" },
|
|
2649
|
+
"\\rho": { tex: "\\rho", label: "\u03C1", title: "rho" },
|
|
2650
|
+
"\\sigma": { tex: "\\sigma", label: "\u03C3", title: "sigma" },
|
|
2651
|
+
"\\tau": { tex: "\\tau", label: "\u03C4", title: "tau" },
|
|
2652
|
+
"\\phi": { tex: "\\phi", label: "\u03C6", title: "phi" },
|
|
2653
|
+
"\\chi": { tex: "\\chi", label: "\u03C7", title: "chi" },
|
|
2654
|
+
"\\psi": { tex: "\\psi", label: "\u03C8", title: "psi" },
|
|
2655
|
+
"\\omega": { tex: "\\omega", label: "\u03C9", title: "omega" },
|
|
2656
|
+
"\\zeta": { tex: "\\zeta", label: "\u03B6", title: "zeta" },
|
|
2657
|
+
"\\nabla": { tex: "\\nabla", label: "\u2207", title: "nabla" },
|
|
2658
|
+
"\\Delta": { tex: "\\Delta", label: "\u0394", title: "Delta" },
|
|
2659
|
+
"\\partial": { tex: "\\partial", label: "\u2202", title: "partial derivative" },
|
|
2660
|
+
"\\Longleftrightarrow": { tex: "\\Longleftrightarrow", label: "\u27FA", title: "long equivalence arrow" },
|
|
2661
|
+
"\\backslash": { tex: "\\backslash", label: "\u2216", title: "reverse solidus" }
|
|
2662
|
+
};
|
|
2663
|
+
function standardCommandSpec(tex) {
|
|
2664
|
+
return Object.prototype.hasOwnProperty.call(STANDARD_COMMANDS, tex) ? STANDARD_COMMANDS[tex] : null;
|
|
2665
|
+
}
|
|
2666
|
+
function isStandardCommandTex(tex) {
|
|
2667
|
+
return standardCommandSpec(tex) !== null;
|
|
2668
|
+
}
|
|
2669
|
+
|
|
2670
|
+
// src/editor/factory.ts
|
|
2671
|
+
var nextId2 = 1;
|
|
2672
|
+
function makeId(prefix) {
|
|
2673
|
+
const id = `${prefix}_${String(nextId2)}`;
|
|
2674
|
+
nextId2 += 1;
|
|
2675
|
+
return id;
|
|
2676
|
+
}
|
|
2677
|
+
function createEditorChain(nodes = []) {
|
|
2678
|
+
return {
|
|
2679
|
+
id: makeId("chain"),
|
|
2680
|
+
nodes
|
|
2681
|
+
};
|
|
2682
|
+
}
|
|
2683
|
+
function createEditorNode(kind, expr) {
|
|
2684
|
+
return {
|
|
2685
|
+
id: makeId("node"),
|
|
2686
|
+
kind,
|
|
2687
|
+
expr,
|
|
2688
|
+
characterFont: void 0,
|
|
2689
|
+
superscript: null,
|
|
2690
|
+
subscript: null,
|
|
2691
|
+
leftDelimExpr: "",
|
|
2692
|
+
rightDelimExpr: "",
|
|
2693
|
+
innerExpr: null,
|
|
2694
|
+
numerator: null,
|
|
2695
|
+
denominator: null,
|
|
2696
|
+
radicand: null,
|
|
2697
|
+
rootIndex: null,
|
|
2698
|
+
overExpr: null,
|
|
2699
|
+
underExpr: null,
|
|
2700
|
+
baseExpr: null,
|
|
2701
|
+
envName: null,
|
|
2702
|
+
matrixStyle: null,
|
|
2703
|
+
matrixRows: null,
|
|
2704
|
+
columnAlignments: null
|
|
2705
|
+
};
|
|
2706
|
+
}
|
|
2707
|
+
function createDelimiterNode(leftDelimExpr2, rightDelimExpr2) {
|
|
2708
|
+
return {
|
|
2709
|
+
...createEditorNode("delimiter", ""),
|
|
2710
|
+
leftDelimExpr: leftDelimExpr2,
|
|
2711
|
+
rightDelimExpr: rightDelimExpr2,
|
|
2712
|
+
innerExpr: createEditorChain()
|
|
2713
|
+
};
|
|
2714
|
+
}
|
|
2715
|
+
function createFracNode() {
|
|
2716
|
+
return {
|
|
2717
|
+
...createEditorNode("frac", ""),
|
|
2718
|
+
numerator: createEditorChain(),
|
|
2719
|
+
denominator: createEditorChain()
|
|
2720
|
+
};
|
|
2721
|
+
}
|
|
2722
|
+
function createSqrtNode() {
|
|
2723
|
+
return {
|
|
2724
|
+
...createEditorNode("sqrt", ""),
|
|
2725
|
+
radicand: createEditorChain(),
|
|
2726
|
+
rootIndex: createEditorChain()
|
|
2727
|
+
};
|
|
2728
|
+
}
|
|
2729
|
+
function createOversetNode() {
|
|
2730
|
+
return {
|
|
2731
|
+
...createEditorNode("overset", ""),
|
|
2732
|
+
overExpr: createEditorChain(),
|
|
2733
|
+
baseExpr: createEditorChain()
|
|
2734
|
+
};
|
|
2735
|
+
}
|
|
2736
|
+
function createUndersetNode() {
|
|
2737
|
+
return {
|
|
2738
|
+
...createEditorNode("underset", ""),
|
|
2739
|
+
underExpr: createEditorChain(),
|
|
2740
|
+
baseExpr: createEditorChain()
|
|
2741
|
+
};
|
|
2742
|
+
}
|
|
2743
|
+
function createAccentNode(accentId) {
|
|
2744
|
+
return {
|
|
2745
|
+
...createEditorNode("accent", accentId),
|
|
2746
|
+
baseExpr: createEditorChain()
|
|
2747
|
+
};
|
|
2748
|
+
}
|
|
2749
|
+
function createGridEnvNode(envName, rows, columns2, columnAlignments) {
|
|
2750
|
+
const safeRows = Math.max(1, Math.min(12, Math.trunc(rows)));
|
|
2751
|
+
const safeColumns = Math.max(1, Math.min(12, Math.trunc(columns2)));
|
|
2752
|
+
const matrixStyles = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
|
|
2753
|
+
const isMatrix = matrixStyles.has(envName) && envName !== "array" && envName !== "aligned";
|
|
2754
|
+
return {
|
|
2755
|
+
...createEditorNode("env", ""),
|
|
2756
|
+
envName,
|
|
2757
|
+
matrixStyle: isMatrix ? envName : null,
|
|
2758
|
+
matrixRows: Array.from(
|
|
2759
|
+
{ length: safeRows },
|
|
2760
|
+
() => Array.from({ length: safeColumns }, () => createEditorChain())
|
|
2761
|
+
),
|
|
2762
|
+
columnAlignments: envName === "array" ? Array.from({ length: safeColumns }, (_, index) => columnAlignments?.[index] ?? "c") : null
|
|
2763
|
+
};
|
|
2764
|
+
}
|
|
2765
|
+
function cloneEditorSession(session) {
|
|
2766
|
+
return {
|
|
2767
|
+
englishTree: structuredClone(session.englishTree),
|
|
2768
|
+
arabicTree: structuredClone(session.arabicTree),
|
|
2769
|
+
activeSide: session.activeSide,
|
|
2770
|
+
splitLeafTyping: session.splitLeafTyping,
|
|
2771
|
+
forceSplitNextLeaf: session.forceSplitNextLeaf,
|
|
2772
|
+
arabicReverseNumberTyping: session.arabicReverseNumberTyping,
|
|
2773
|
+
currentCharacterFont: session.currentCharacterFont ?? "default",
|
|
2774
|
+
currentDigitForm: session.currentDigitForm ?? "western",
|
|
2775
|
+
caret: { ...session.caret },
|
|
2776
|
+
selection: session.selection ? { ...session.selection } : null,
|
|
2777
|
+
selectedNodeId: session.selectedNodeId,
|
|
2778
|
+
selectedStructureNodeId: session.selectedStructureNodeId,
|
|
2779
|
+
sync: structuredClone(session.sync),
|
|
2780
|
+
debugLog: session.debugLog.slice()
|
|
2781
|
+
};
|
|
2782
|
+
}
|
|
2783
|
+
function collectNodeIds(chain, ids) {
|
|
2784
|
+
for (const node of chain.nodes) {
|
|
2785
|
+
ids.push(node.id);
|
|
2786
|
+
if (node.superscript) {
|
|
2787
|
+
collectNodeIds(node.superscript, ids);
|
|
2788
|
+
}
|
|
2789
|
+
if (node.subscript) {
|
|
2790
|
+
collectNodeIds(node.subscript, ids);
|
|
2791
|
+
}
|
|
2792
|
+
if (node.innerExpr) {
|
|
2793
|
+
collectNodeIds(node.innerExpr, ids);
|
|
2794
|
+
}
|
|
2795
|
+
if (node.numerator) {
|
|
2796
|
+
collectNodeIds(node.numerator, ids);
|
|
2797
|
+
}
|
|
2798
|
+
if (node.denominator) {
|
|
2799
|
+
collectNodeIds(node.denominator, ids);
|
|
2800
|
+
}
|
|
2801
|
+
if (node.rootIndex) {
|
|
2802
|
+
collectNodeIds(node.rootIndex, ids);
|
|
2803
|
+
}
|
|
2804
|
+
if (node.radicand) {
|
|
2805
|
+
collectNodeIds(node.radicand, ids);
|
|
2806
|
+
}
|
|
2807
|
+
if (node.overExpr) {
|
|
2808
|
+
collectNodeIds(node.overExpr, ids);
|
|
2809
|
+
}
|
|
2810
|
+
if (node.underExpr) {
|
|
2811
|
+
collectNodeIds(node.underExpr, ids);
|
|
2812
|
+
}
|
|
2813
|
+
if (node.baseExpr) {
|
|
2814
|
+
collectNodeIds(node.baseExpr, ids);
|
|
2815
|
+
}
|
|
2816
|
+
if (node.matrixRows) {
|
|
2817
|
+
for (const row of node.matrixRows) {
|
|
2818
|
+
for (const cell of row) {
|
|
2819
|
+
collectNodeIds(cell, ids);
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
function buildInitialSyncMap(englishTree, arabicTree) {
|
|
2826
|
+
const englishIds = [];
|
|
2827
|
+
const arabicIds = [];
|
|
2828
|
+
collectNodeIds(englishTree, englishIds);
|
|
2829
|
+
collectNodeIds(arabicTree, arabicIds);
|
|
2830
|
+
const all = /* @__PURE__ */ new Set([...englishIds, ...arabicIds]);
|
|
2831
|
+
const sync = {};
|
|
2832
|
+
for (const nodeId of all) {
|
|
2833
|
+
sync[nodeId] = { expr: "synced" };
|
|
2834
|
+
}
|
|
2835
|
+
return sync;
|
|
2836
|
+
}
|
|
2837
|
+
function createEditorSession(englishTree, arabicTree, activeSide = "arabic") {
|
|
2838
|
+
return {
|
|
2839
|
+
englishTree,
|
|
2840
|
+
arabicTree,
|
|
2841
|
+
activeSide,
|
|
2842
|
+
splitLeafTyping: false,
|
|
2843
|
+
forceSplitNextLeaf: false,
|
|
2844
|
+
arabicReverseNumberTyping: true,
|
|
2845
|
+
currentCharacterFont: "default",
|
|
2846
|
+
currentDigitForm: "western",
|
|
2847
|
+
caret: {
|
|
2848
|
+
chainId: englishTree.id,
|
|
2849
|
+
index: 0
|
|
2850
|
+
},
|
|
2851
|
+
selection: null,
|
|
2852
|
+
selectedNodeId: null,
|
|
2853
|
+
selectedStructureNodeId: null,
|
|
2854
|
+
sync: buildInitialSyncMap(englishTree, arabicTree),
|
|
2855
|
+
debugLog: []
|
|
2856
|
+
};
|
|
2857
|
+
}
|
|
2114
2858
|
|
|
2115
2859
|
// src/editor/characterFonts.ts
|
|
2116
2860
|
var CHARACTER_FONT_SPECS = [
|
|
@@ -2175,6 +2919,237 @@ var CHARACTER_FONT_OPTIONS = CHARACTER_FONT_SPECS.map(({ id, label }) => ({ id,
|
|
|
2175
2919
|
var NON_DEFAULT_CHARACTER_FONT_SPECS = CHARACTER_FONT_SPECS.filter(
|
|
2176
2920
|
(font) => font.id !== "default" && typeof font.macro === "string"
|
|
2177
2921
|
);
|
|
2922
|
+
function characterFontSpec(fontId) {
|
|
2923
|
+
return CHARACTER_FONT_SPECS.find((font) => font.id === fontId) ?? CHARACTER_FONT_SPECS[0];
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2926
|
+
// src/editor/divideOperator.ts
|
|
2927
|
+
var DIVIDE_OPERATOR_EN = "/";
|
|
2928
|
+
var DIVIDE_OPERATOR_AR = "\\";
|
|
2929
|
+
function isDivideOperatorExpr(expr) {
|
|
2930
|
+
return expr === DIVIDE_OPERATOR_EN || expr === DIVIDE_OPERATOR_AR;
|
|
2931
|
+
}
|
|
2932
|
+
function renderDivideOperatorLatex(side) {
|
|
2933
|
+
return side === "arabic" ? "\\backslash" : DIVIDE_OPERATOR_EN;
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
// src/editor/render.ts
|
|
2937
|
+
function selectedDigitForm(options) {
|
|
2938
|
+
return options?.digitForm ?? "western";
|
|
2939
|
+
}
|
|
2940
|
+
function latinScripts(node, options) {
|
|
2941
|
+
let scripts = "";
|
|
2942
|
+
if (node.superscript) {
|
|
2943
|
+
scripts += `^{${renderChainEnglish(node.superscript, options)}}`;
|
|
2944
|
+
}
|
|
2945
|
+
if (node.subscript) {
|
|
2946
|
+
scripts += `_{${renderChainEnglish(node.subscript, options)}}`;
|
|
2947
|
+
}
|
|
2948
|
+
return scripts;
|
|
2949
|
+
}
|
|
2950
|
+
function optionalRootIndexEnglish(node, options) {
|
|
2951
|
+
if (!node.rootIndex) {
|
|
2952
|
+
return "";
|
|
2953
|
+
}
|
|
2954
|
+
const rendered = renderChainEnglish(node.rootIndex, options);
|
|
2955
|
+
return rendered === "" ? "" : `[${rendered}]`;
|
|
2956
|
+
}
|
|
2957
|
+
function optionalRootIndexArabic(node, options) {
|
|
2958
|
+
if (!node.rootIndex) {
|
|
2959
|
+
return "";
|
|
2960
|
+
}
|
|
2961
|
+
const rendered = renderChainArabic(node.rootIndex, options);
|
|
2962
|
+
return rendered === "" ? "" : `[${rendered}]`;
|
|
2963
|
+
}
|
|
2964
|
+
function arabicScripts(node, content, options) {
|
|
2965
|
+
const sup = node.superscript ? renderChainArabic(node.superscript, options) : "";
|
|
2966
|
+
const sub = node.subscript ? renderChainArabic(node.subscript, options) : "";
|
|
2967
|
+
if (sup !== "" || sub !== "") {
|
|
2968
|
+
return `\\prescript{${sup}}{${sub}}{${content}}`;
|
|
2969
|
+
}
|
|
2970
|
+
return content;
|
|
2971
|
+
}
|
|
2972
|
+
function renderMatrixRowsEnglish(node, options) {
|
|
2973
|
+
if (!node.matrixRows) {
|
|
2974
|
+
return "";
|
|
2975
|
+
}
|
|
2976
|
+
const envName = node.envName ?? node.matrixStyle;
|
|
2977
|
+
if (!envName) {
|
|
2978
|
+
return "";
|
|
2979
|
+
}
|
|
2980
|
+
const rows = node.matrixRows.map((row) => row.map((cell) => renderChainEnglish(cell, options)).join(" & "));
|
|
2981
|
+
if (envName === "array") {
|
|
2982
|
+
const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows[0]?.length ?? 0).join("");
|
|
2983
|
+
return `\\begin{array}{${spec || "c"}}${rows.join(" \\\\\n")}\\end{array}`;
|
|
2984
|
+
}
|
|
2985
|
+
return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
|
|
2986
|
+
}
|
|
2987
|
+
function reverseAlignmentForArabic(alignment) {
|
|
2988
|
+
if (alignment === "l") {
|
|
2989
|
+
return "r";
|
|
2990
|
+
}
|
|
2991
|
+
if (alignment === "r") {
|
|
2992
|
+
return "l";
|
|
2993
|
+
}
|
|
2994
|
+
return "c";
|
|
2995
|
+
}
|
|
2996
|
+
function renderMatrixRowsArabic(node, options) {
|
|
2997
|
+
if (!node.matrixRows) {
|
|
2998
|
+
return "";
|
|
2999
|
+
}
|
|
3000
|
+
const envName = node.envName ?? node.matrixStyle;
|
|
3001
|
+
if (!envName) {
|
|
3002
|
+
return "";
|
|
3003
|
+
}
|
|
3004
|
+
const rows = node.matrixRows.map(
|
|
3005
|
+
(row) => row.slice().reverse().map((cell) => renderChainArabic(cell, options)).join(" & ")
|
|
3006
|
+
);
|
|
3007
|
+
if (envName === "array") {
|
|
3008
|
+
const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows[0]?.length ?? 0).reverse().map(reverseAlignmentForArabic).join("");
|
|
3009
|
+
return `\\begin{array}{${spec || "c"}}${rows.join(" \\\\\n")}\\end{array}`;
|
|
3010
|
+
}
|
|
3011
|
+
return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
|
|
3012
|
+
}
|
|
3013
|
+
function renderAccentEnglish(command, accent, base, options) {
|
|
3014
|
+
const baseTex = base ? renderChainEnglish(base, options) : "";
|
|
3015
|
+
const accentTex = accent ? renderChainEnglish(accent, options) : "";
|
|
3016
|
+
if (accentTex === "") {
|
|
3017
|
+
return baseTex;
|
|
3018
|
+
}
|
|
3019
|
+
return `\\${command}{${accentTex}}{${baseTex}}`;
|
|
3020
|
+
}
|
|
3021
|
+
function renderAccentArabic(command, accent, base, options) {
|
|
3022
|
+
const baseTex = base ? renderChainArabic(base, options) : "";
|
|
3023
|
+
const accentTex = accent ? renderChainArabic(accent, options) : "";
|
|
3024
|
+
if (accentTex === "") {
|
|
3025
|
+
return baseTex;
|
|
3026
|
+
}
|
|
3027
|
+
return `\\${command}{${accentTex}}{${baseTex}}`;
|
|
3028
|
+
}
|
|
3029
|
+
function escapeText(s) {
|
|
3030
|
+
return s.replace(/\\/g, "\\textbackslash{}").replace(/[{}]/g, "\\$&");
|
|
3031
|
+
}
|
|
3032
|
+
function renderCharContent(node, options) {
|
|
3033
|
+
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3034
|
+
const font = node.characterFont ?? "default";
|
|
3035
|
+
const macro = characterFontSpec(font).macro;
|
|
3036
|
+
if (macro) {
|
|
3037
|
+
return `${macro}{${escapeText(expr)}}`;
|
|
3038
|
+
}
|
|
3039
|
+
return expr;
|
|
3040
|
+
}
|
|
3041
|
+
function renderNodeEnglish(node, options) {
|
|
3042
|
+
if (node.kind === "delimiter" && node.innerExpr) {
|
|
3043
|
+
return `${node.leftDelimExpr}${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
|
|
3044
|
+
}
|
|
3045
|
+
if (node.kind === "frac" && node.numerator && node.denominator) {
|
|
3046
|
+
const body = `\\frac{${renderChainEnglish(node.numerator, options)}}{${renderChainEnglish(node.denominator, options)}}`;
|
|
3047
|
+
return `${body}${latinScripts(node, options)}`;
|
|
3048
|
+
}
|
|
3049
|
+
if (node.kind === "sqrt" && node.radicand) {
|
|
3050
|
+
const body = `\\sqrt${optionalRootIndexEnglish(node, options)}{${renderChainEnglish(node.radicand, options)}}`;
|
|
3051
|
+
return `${body}${latinScripts(node, options)}`;
|
|
3052
|
+
}
|
|
3053
|
+
if (node.kind === "overset" && node.baseExpr) {
|
|
3054
|
+
const body = renderAccentEnglish("overset", node.overExpr, node.baseExpr, options);
|
|
3055
|
+
return `${body}${latinScripts(node, options)}`;
|
|
3056
|
+
}
|
|
3057
|
+
if (node.kind === "underset" && node.baseExpr) {
|
|
3058
|
+
const body = renderAccentEnglish("underset", node.underExpr, node.baseExpr, options);
|
|
3059
|
+
return `${body}${latinScripts(node, options)}`;
|
|
3060
|
+
}
|
|
3061
|
+
if (node.kind === "accent" && node.baseExpr) {
|
|
3062
|
+
const cmd = accentCommandSpec(node.expr)?.englishTex ?? `\\${node.expr}`;
|
|
3063
|
+
const body = `${cmd}{${renderChainEnglish(node.baseExpr, options)}}`;
|
|
3064
|
+
return `${body}${latinScripts(node, options)}`;
|
|
3065
|
+
}
|
|
3066
|
+
if (node.kind === "env") {
|
|
3067
|
+
return `${renderMatrixRowsEnglish(node, options)}${latinScripts(node, options)}`;
|
|
3068
|
+
}
|
|
3069
|
+
if (node.kind === "atomicCommand") {
|
|
3070
|
+
const body = atomicCommandSpec(node.expr)?.englishTex ?? node.expr;
|
|
3071
|
+
return `${body}${latinScripts(node, options)}`;
|
|
3072
|
+
}
|
|
3073
|
+
if (node.kind === "atomicOperatorCommand") {
|
|
3074
|
+
const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
|
|
3075
|
+
return `${body}${latinScripts(node, options)}`;
|
|
3076
|
+
}
|
|
3077
|
+
if (node.kind === "standardCommand") {
|
|
3078
|
+
return `${node.expr}${latinScripts(node, options)}`;
|
|
3079
|
+
}
|
|
3080
|
+
if (node.kind === "char") {
|
|
3081
|
+
return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
|
|
3082
|
+
}
|
|
3083
|
+
if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
|
|
3084
|
+
return `${renderDivideOperatorLatex("english")}${latinScripts(node, options)}`;
|
|
3085
|
+
}
|
|
3086
|
+
return `${formatDigits(node.expr, selectedDigitForm(options))}${latinScripts(node, options)}`;
|
|
3087
|
+
}
|
|
3088
|
+
function renderNodeArabic(node, options) {
|
|
3089
|
+
if (node.kind === "delimiter" && node.innerExpr) {
|
|
3090
|
+
const content = `${node.leftDelimExpr}${renderChainArabic(node.innerExpr, options)}${node.rightDelimExpr}`;
|
|
3091
|
+
return arabicScripts(node, content, options);
|
|
3092
|
+
}
|
|
3093
|
+
if (node.kind === "frac" && node.numerator && node.denominator) {
|
|
3094
|
+
const content = `\\frac{${renderChainArabic(node.numerator, options)}}{${renderChainArabic(node.denominator, options)}}`;
|
|
3095
|
+
return arabicScripts(node, content, options);
|
|
3096
|
+
}
|
|
3097
|
+
if (node.kind === "sqrt" && node.radicand) {
|
|
3098
|
+
const content = `\\arsqrt${optionalRootIndexArabic(node, options)}{${renderChainArabic(node.radicand, options)}}`;
|
|
3099
|
+
return arabicScripts(node, content, options);
|
|
3100
|
+
}
|
|
3101
|
+
if (node.kind === "overset" && node.baseExpr) {
|
|
3102
|
+
const content = renderAccentArabic("overset", node.overExpr, node.baseExpr, options);
|
|
3103
|
+
return arabicScripts(node, content, options);
|
|
3104
|
+
}
|
|
3105
|
+
if (node.kind === "underset" && node.baseExpr) {
|
|
3106
|
+
const content = renderAccentArabic("underset", node.underExpr, node.baseExpr, options);
|
|
3107
|
+
return arabicScripts(node, content, options);
|
|
3108
|
+
}
|
|
3109
|
+
if (node.kind === "accent" && node.baseExpr) {
|
|
3110
|
+
const cmd = accentCommandSpec(node.expr)?.arabicTex ?? `\\${node.expr}`;
|
|
3111
|
+
const content = `${cmd}{${renderChainArabic(node.baseExpr, options)}}`;
|
|
3112
|
+
return arabicScripts(node, content, options);
|
|
3113
|
+
}
|
|
3114
|
+
if (node.kind === "env") {
|
|
3115
|
+
return arabicScripts(node, renderMatrixRowsArabic(node, options), options);
|
|
3116
|
+
}
|
|
3117
|
+
if (node.kind === "atomicCommand") {
|
|
3118
|
+
const spec = atomicCommandSpec(node.expr);
|
|
3119
|
+
const content = spec?.arabicRenderTex ?? spec?.arabicTex ?? node.expr;
|
|
3120
|
+
return arabicScripts(node, content, options);
|
|
3121
|
+
}
|
|
3122
|
+
if (node.kind === "atomicOperatorCommand") {
|
|
3123
|
+
const spec = atomicOperatorCommandSpec(node.expr);
|
|
3124
|
+
const tex = spec?.Tex ?? node.expr;
|
|
3125
|
+
const content = spec?.mirror ? `\\butexmirror{${tex}}` : tex;
|
|
3126
|
+
return arabicScripts(node, content, options);
|
|
3127
|
+
}
|
|
3128
|
+
if (node.kind === "standardCommand") {
|
|
3129
|
+
return arabicScripts(node, node.expr, options);
|
|
3130
|
+
}
|
|
3131
|
+
if (node.kind === "char") {
|
|
3132
|
+
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3133
|
+
const content = renderCharContent(node, options);
|
|
3134
|
+
return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
|
|
3135
|
+
}
|
|
3136
|
+
if (node.kind === "operator" && isDivideOperatorExpr(node.expr)) {
|
|
3137
|
+
return arabicScripts(node, renderDivideOperatorLatex("arabic"), options);
|
|
3138
|
+
}
|
|
3139
|
+
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
3140
|
+
}
|
|
3141
|
+
function renderChainEnglish(chain, options) {
|
|
3142
|
+
return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
|
|
3143
|
+
}
|
|
3144
|
+
function renderChainArabic(chain, options) {
|
|
3145
|
+
return chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options)).join(" ");
|
|
3146
|
+
}
|
|
3147
|
+
function renderEnglishLatexFromSession(session) {
|
|
3148
|
+
return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
3149
|
+
}
|
|
3150
|
+
function renderArabicLatexFromSession(session) {
|
|
3151
|
+
return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
3152
|
+
}
|
|
2178
3153
|
|
|
2179
3154
|
// src/editor/display/delimiter.ts
|
|
2180
3155
|
var DELIMITER_CSS = `
|
|
@@ -2678,6 +3653,19 @@ var ATOMIC_OPERATOR_COMMAND_CSS = `
|
|
|
2678
3653
|
}
|
|
2679
3654
|
`.trim();
|
|
2680
3655
|
|
|
3656
|
+
// src/editor/display/standardCommand.ts
|
|
3657
|
+
var STANDARD_COMMAND_CSS = `
|
|
3658
|
+
.standard-command {
|
|
3659
|
+
display: inline-flex;
|
|
3660
|
+
align-items: center;
|
|
3661
|
+
justify-content: center;
|
|
3662
|
+
min-width: 0.9em;
|
|
3663
|
+
font-family: "Cambria Math", "Times New Roman", serif;
|
|
3664
|
+
font-size: 1.05em;
|
|
3665
|
+
line-height: 1;
|
|
3666
|
+
}
|
|
3667
|
+
`.trim();
|
|
3668
|
+
|
|
2681
3669
|
// src/editor/styles.ts
|
|
2682
3670
|
var CHARACTER_FONT_CSS = NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.cssClass && font.browserFontStack).map((font) => `.${font.cssClass} {
|
|
2683
3671
|
font-family: ${font.browserFontStack};
|
|
@@ -2887,6 +3875,8 @@ ${MATRIX_ENV_CSS}
|
|
|
2887
3875
|
${ATOMIC_COMMAND_CSS}
|
|
2888
3876
|
|
|
2889
3877
|
${ATOMIC_OPERATOR_COMMAND_CSS}
|
|
3878
|
+
|
|
3879
|
+
${STANDARD_COMMAND_CSS}
|
|
2890
3880
|
`.trim();
|
|
2891
3881
|
|
|
2892
3882
|
// src/document/normalizeCharImport.ts
|
|
@@ -2897,6 +3887,61 @@ var WRAPPER_SPECS = [
|
|
|
2897
3887
|
]),
|
|
2898
3888
|
{ prefix: "\\text" }
|
|
2899
3889
|
];
|
|
3890
|
+
function readBracedArg(source, openBraceIndex) {
|
|
3891
|
+
if (source[openBraceIndex] !== "{") {
|
|
3892
|
+
return null;
|
|
3893
|
+
}
|
|
3894
|
+
let depth = 0;
|
|
3895
|
+
for (let index = openBraceIndex; index < source.length; index += 1) {
|
|
3896
|
+
const char = source[index];
|
|
3897
|
+
if (char === "{") {
|
|
3898
|
+
depth += 1;
|
|
3899
|
+
} else if (char === "}") {
|
|
3900
|
+
depth -= 1;
|
|
3901
|
+
if (depth === 0) {
|
|
3902
|
+
return { inner: source.slice(openBraceIndex + 1, index), end: index + 1 };
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
}
|
|
3906
|
+
return null;
|
|
3907
|
+
}
|
|
3908
|
+
function peelWrapper(source) {
|
|
3909
|
+
for (const wrapper of WRAPPER_SPECS) {
|
|
3910
|
+
if (!source.startsWith(wrapper.prefix)) {
|
|
3911
|
+
continue;
|
|
3912
|
+
}
|
|
3913
|
+
const braced = readBracedArg(source, wrapper.prefix.length);
|
|
3914
|
+
if (!braced || braced.end !== source.length) {
|
|
3915
|
+
continue;
|
|
3916
|
+
}
|
|
3917
|
+
return { inner: braced.inner, font: wrapper.font };
|
|
3918
|
+
}
|
|
3919
|
+
return null;
|
|
3920
|
+
}
|
|
3921
|
+
function normalizeCharImportExpr(expr) {
|
|
3922
|
+
const original = expr;
|
|
3923
|
+
let current = expr;
|
|
3924
|
+
let characterFont = "default";
|
|
3925
|
+
let changed = false;
|
|
3926
|
+
while (true) {
|
|
3927
|
+
const peeled = peelWrapper(current);
|
|
3928
|
+
if (!peeled) {
|
|
3929
|
+
break;
|
|
3930
|
+
}
|
|
3931
|
+
current = peeled.inner;
|
|
3932
|
+
if (peeled.font) {
|
|
3933
|
+
characterFont = peeled.font;
|
|
3934
|
+
}
|
|
3935
|
+
changed = true;
|
|
3936
|
+
}
|
|
3937
|
+
if (!changed) {
|
|
3938
|
+
return { expr: original, characterFont: "default" };
|
|
3939
|
+
}
|
|
3940
|
+
if (current.includes("\\")) {
|
|
3941
|
+
return { expr: original, characterFont: "default" };
|
|
3942
|
+
}
|
|
3943
|
+
return { expr: current, characterFont };
|
|
3944
|
+
}
|
|
2900
3945
|
|
|
2901
3946
|
// src/document/mathEditorAdapter.ts
|
|
2902
3947
|
var COMMAND_FONT_MAP = Object.fromEntries([
|
|
@@ -2909,6 +3954,575 @@ var COMMAND_FONT_MAP = Object.fromEntries([
|
|
|
2909
3954
|
var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
|
|
2910
3955
|
NON_DEFAULT_CHARACTER_FONT_SPECS.map((font) => [font.id, font.macro])
|
|
2911
3956
|
);
|
|
3957
|
+
function charEditorNodeToAstNode(node) {
|
|
3958
|
+
const font = node.characterFont ?? "default";
|
|
3959
|
+
const charNode = new CharNode(node.expr);
|
|
3960
|
+
if (font === "default") {
|
|
3961
|
+
return charNode;
|
|
3962
|
+
}
|
|
3963
|
+
return new CommandNode(CHAR_FONT_EXPORT_TEX[font], [], [new ChainNode([charNode])]);
|
|
3964
|
+
}
|
|
3965
|
+
function commandIdForTex(tex) {
|
|
3966
|
+
for (const spec of Object.values(ATOMIC_COMMANDS)) {
|
|
3967
|
+
const renderTex = spec.arabicRenderTex;
|
|
3968
|
+
if (spec.englishTex === tex || spec.arabicTex === tex || renderTex === tex) {
|
|
3969
|
+
return spec.id;
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3972
|
+
return null;
|
|
3973
|
+
}
|
|
3974
|
+
function operatorCommandIdForTex(tex) {
|
|
3975
|
+
for (const spec of Object.values(ATOMIC_OPERATOR_COMMANDS)) {
|
|
3976
|
+
if (spec.Tex === tex) {
|
|
3977
|
+
return spec.id;
|
|
3978
|
+
}
|
|
3979
|
+
}
|
|
3980
|
+
return null;
|
|
3981
|
+
}
|
|
3982
|
+
function cloneChainWithFreshIds(chain) {
|
|
3983
|
+
return structuredClone(chain);
|
|
3984
|
+
}
|
|
3985
|
+
function attachScripts(astNode, editorNode) {
|
|
3986
|
+
if (astNode.superscript) {
|
|
3987
|
+
const sup = chainToEditorChain(astNode.superscript);
|
|
3988
|
+
if (!sup.editable) {
|
|
3989
|
+
return sup;
|
|
3990
|
+
}
|
|
3991
|
+
editorNode.superscript = sup.chain;
|
|
3992
|
+
}
|
|
3993
|
+
if (astNode.subscript) {
|
|
3994
|
+
const sub = chainToEditorChain(astNode.subscript);
|
|
3995
|
+
if (!sub.editable) {
|
|
3996
|
+
return sub;
|
|
3997
|
+
}
|
|
3998
|
+
editorNode.subscript = sub.chain;
|
|
3999
|
+
}
|
|
4000
|
+
return null;
|
|
4001
|
+
}
|
|
4002
|
+
var MATRIX_ENV_NAMES = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
|
|
4003
|
+
function isGridEnvName(value) {
|
|
4004
|
+
return MATRIX_ENV_NAMES.has(value) || value === "array" || value === "aligned";
|
|
4005
|
+
}
|
|
4006
|
+
function isMatrixEnvName(value) {
|
|
4007
|
+
return MATRIX_ENV_NAMES.has(value);
|
|
4008
|
+
}
|
|
4009
|
+
function parseEnvOpening(opening) {
|
|
4010
|
+
const match = /^\\begin\{([^}]+)\}(?:\{([lcr]+)\})?$/.exec(opening);
|
|
4011
|
+
if (!match) {
|
|
4012
|
+
return null;
|
|
4013
|
+
}
|
|
4014
|
+
const envName = match[1] ?? "";
|
|
4015
|
+
if (!isGridEnvName(envName)) {
|
|
4016
|
+
return null;
|
|
4017
|
+
}
|
|
4018
|
+
if (envName === "array") {
|
|
4019
|
+
const spec = match[2] ?? "c";
|
|
4020
|
+
return {
|
|
4021
|
+
envName,
|
|
4022
|
+
alignments: spec.split("").map((alignment) => alignment)
|
|
4023
|
+
};
|
|
4024
|
+
}
|
|
4025
|
+
return { envName };
|
|
4026
|
+
}
|
|
4027
|
+
function splitEnvLine(line) {
|
|
4028
|
+
const cells = [];
|
|
4029
|
+
let current = [];
|
|
4030
|
+
for (const node of line.chain) {
|
|
4031
|
+
if (node instanceof OperatorNode && node.expr === "&") {
|
|
4032
|
+
cells.push(new ChainNode(current));
|
|
4033
|
+
current = [];
|
|
4034
|
+
} else {
|
|
4035
|
+
current.push(node);
|
|
4036
|
+
}
|
|
4037
|
+
}
|
|
4038
|
+
cells.push(new ChainNode(current));
|
|
4039
|
+
return cells;
|
|
4040
|
+
}
|
|
4041
|
+
function envToEditorNode(node) {
|
|
4042
|
+
const parsed = parseEnvOpening(node.opening);
|
|
4043
|
+
if (!parsed) {
|
|
4044
|
+
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}` };
|
|
4045
|
+
}
|
|
4046
|
+
const expectedClosing = `\\end{${parsed.envName}}`;
|
|
4047
|
+
if (node.closing !== expectedClosing) {
|
|
4048
|
+
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}` };
|
|
4049
|
+
}
|
|
4050
|
+
const rowCells = node.lines.map(splitEnvLine);
|
|
4051
|
+
const rows = Math.max(1, rowCells.length);
|
|
4052
|
+
const columns2 = Math.max(1, ...rowCells.map((row) => row.length));
|
|
4053
|
+
const env = createGridEnvNode(parsed.envName, rows, columns2, parsed.alignments);
|
|
4054
|
+
for (let rowIndex = 0; rowIndex < rows; rowIndex += 1) {
|
|
4055
|
+
const row = rowCells[rowIndex] ?? [];
|
|
4056
|
+
for (let columnIndex = 0; columnIndex < columns2; columnIndex += 1) {
|
|
4057
|
+
const cell = chainToEditorChain(row[columnIndex] ?? new ChainNode());
|
|
4058
|
+
if (!cell.editable) {
|
|
4059
|
+
return cell;
|
|
4060
|
+
}
|
|
4061
|
+
env.matrixRows[rowIndex][columnIndex] = cell.chain;
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
if (parsed.envName === "array") {
|
|
4065
|
+
env.columnAlignments = Array.from(
|
|
4066
|
+
{ length: columns2 },
|
|
4067
|
+
(_, index) => parsed.alignments?.[index] ?? "c"
|
|
4068
|
+
);
|
|
4069
|
+
}
|
|
4070
|
+
if (isMatrixEnvName(parsed.envName)) {
|
|
4071
|
+
env.matrixStyle = parsed.envName;
|
|
4072
|
+
}
|
|
4073
|
+
const scripts = attachScripts(node, env);
|
|
4074
|
+
return scripts ?? { editable: true, node: env };
|
|
4075
|
+
}
|
|
4076
|
+
function charFromTextLikeCommand(node) {
|
|
4077
|
+
const commandFont = COMMAND_FONT_MAP[node.name];
|
|
4078
|
+
if (commandFont === void 0) {
|
|
4079
|
+
return null;
|
|
4080
|
+
}
|
|
4081
|
+
if (node.optionalArgs.length > 0 || node.mandatoryArgs.length !== 1) {
|
|
4082
|
+
return null;
|
|
4083
|
+
}
|
|
4084
|
+
const arg = node.mandatoryArgs[0];
|
|
4085
|
+
if (arg.chain.length !== 1) {
|
|
4086
|
+
return null;
|
|
4087
|
+
}
|
|
4088
|
+
const child = arg.chain[0];
|
|
4089
|
+
if (child instanceof CommandNode) {
|
|
4090
|
+
const nested = charFromTextLikeCommand(child);
|
|
4091
|
+
if (!nested?.editable) {
|
|
4092
|
+
return null;
|
|
4093
|
+
}
|
|
4094
|
+
if (commandFont !== "infer") {
|
|
4095
|
+
nested.node.characterFont = commandFont;
|
|
4096
|
+
}
|
|
4097
|
+
const scripts2 = attachScripts(node, nested.node);
|
|
4098
|
+
return scripts2 ?? nested;
|
|
4099
|
+
}
|
|
4100
|
+
if (!(child instanceof CharNode)) {
|
|
4101
|
+
return null;
|
|
4102
|
+
}
|
|
4103
|
+
const normalized = normalizeCharImportExpr(child.expr);
|
|
4104
|
+
const characterFont = commandFont === "infer" ? normalized.characterFont : commandFont;
|
|
4105
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
4106
|
+
if (characterFont !== "default") {
|
|
4107
|
+
editorNode.characterFont = characterFont;
|
|
4108
|
+
}
|
|
4109
|
+
const scripts = attachScripts(node, editorNode);
|
|
4110
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
4111
|
+
}
|
|
4112
|
+
function commandToEditorNode(node) {
|
|
4113
|
+
if (node.name === "\\frac" && node.mandatoryArgs.length >= 2) {
|
|
4114
|
+
const frac = createFracNode();
|
|
4115
|
+
const numerator = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4116
|
+
const denominator = chainToEditorChain(node.mandatoryArgs[1]);
|
|
4117
|
+
if (!numerator.editable) {
|
|
4118
|
+
return numerator;
|
|
4119
|
+
}
|
|
4120
|
+
if (!denominator.editable) {
|
|
4121
|
+
return denominator;
|
|
4122
|
+
}
|
|
4123
|
+
frac.numerator = numerator.chain;
|
|
4124
|
+
frac.denominator = denominator.chain;
|
|
4125
|
+
const scripts = attachScripts(node, frac);
|
|
4126
|
+
if (scripts) {
|
|
4127
|
+
return scripts;
|
|
4128
|
+
}
|
|
4129
|
+
return { editable: true, node: frac };
|
|
4130
|
+
}
|
|
4131
|
+
if ((node.name === "\\sqrt" || node.name === "\\arabsqrt" || node.name === "\\arsqrt") && node.mandatoryArgs.length >= 1) {
|
|
4132
|
+
const sqrt = createSqrtNode();
|
|
4133
|
+
const radicand = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4134
|
+
if (!radicand.editable) {
|
|
4135
|
+
return radicand;
|
|
4136
|
+
}
|
|
4137
|
+
sqrt.radicand = radicand.chain;
|
|
4138
|
+
if (node.optionalArgs[0]) {
|
|
4139
|
+
const rootIndex = chainToEditorChain(node.optionalArgs[0]);
|
|
4140
|
+
if (!rootIndex.editable) {
|
|
4141
|
+
return rootIndex;
|
|
4142
|
+
}
|
|
4143
|
+
sqrt.rootIndex = rootIndex.chain;
|
|
4144
|
+
}
|
|
4145
|
+
const scripts = attachScripts(node, sqrt);
|
|
4146
|
+
if (scripts) {
|
|
4147
|
+
return scripts;
|
|
4148
|
+
}
|
|
4149
|
+
return { editable: true, node: sqrt };
|
|
4150
|
+
}
|
|
4151
|
+
if (node.name === "\\overset" && node.mandatoryArgs.length >= 2) {
|
|
4152
|
+
const overset = createOversetNode();
|
|
4153
|
+
const overExpr = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4154
|
+
const baseExpr = chainToEditorChain(node.mandatoryArgs[1]);
|
|
4155
|
+
if (!overExpr.editable) {
|
|
4156
|
+
return overExpr;
|
|
4157
|
+
}
|
|
4158
|
+
if (!baseExpr.editable) {
|
|
4159
|
+
return baseExpr;
|
|
4160
|
+
}
|
|
4161
|
+
overset.overExpr = overExpr.chain;
|
|
4162
|
+
overset.baseExpr = baseExpr.chain;
|
|
4163
|
+
const scripts = attachScripts(node, overset);
|
|
4164
|
+
if (scripts) {
|
|
4165
|
+
return scripts;
|
|
4166
|
+
}
|
|
4167
|
+
return { editable: true, node: overset };
|
|
4168
|
+
}
|
|
4169
|
+
if (node.name === "\\underset" && node.mandatoryArgs.length >= 2) {
|
|
4170
|
+
const underset = createUndersetNode();
|
|
4171
|
+
const underExpr = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4172
|
+
const baseExpr = chainToEditorChain(node.mandatoryArgs[1]);
|
|
4173
|
+
if (!underExpr.editable) {
|
|
4174
|
+
return underExpr;
|
|
4175
|
+
}
|
|
4176
|
+
if (!baseExpr.editable) {
|
|
4177
|
+
return baseExpr;
|
|
4178
|
+
}
|
|
4179
|
+
underset.underExpr = underExpr.chain;
|
|
4180
|
+
underset.baseExpr = baseExpr.chain;
|
|
4181
|
+
const scripts = attachScripts(node, underset);
|
|
4182
|
+
if (scripts) {
|
|
4183
|
+
return scripts;
|
|
4184
|
+
}
|
|
4185
|
+
return { editable: true, node: underset };
|
|
4186
|
+
}
|
|
4187
|
+
const accentId = accentCommandIdFromTex(node.name);
|
|
4188
|
+
if (accentId && node.mandatoryArgs.length >= 1) {
|
|
4189
|
+
const accent = createAccentNode(accentId);
|
|
4190
|
+
const baseExpr = chainToEditorChain(node.mandatoryArgs[0]);
|
|
4191
|
+
if (!baseExpr.editable) {
|
|
4192
|
+
return baseExpr;
|
|
4193
|
+
}
|
|
4194
|
+
accent.baseExpr = baseExpr.chain;
|
|
4195
|
+
const scripts = attachScripts(node, accent);
|
|
4196
|
+
if (scripts) {
|
|
4197
|
+
return scripts;
|
|
4198
|
+
}
|
|
4199
|
+
return { editable: true, node: accent };
|
|
4200
|
+
}
|
|
4201
|
+
const atomicId = commandIdForTex(node.name);
|
|
4202
|
+
if (atomicId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
|
|
4203
|
+
const atomic = createEditorNode("atomicCommand", atomicId);
|
|
4204
|
+
const scripts = attachScripts(node, atomic);
|
|
4205
|
+
if (scripts) {
|
|
4206
|
+
return scripts;
|
|
4207
|
+
}
|
|
4208
|
+
return { editable: true, node: atomic };
|
|
4209
|
+
}
|
|
4210
|
+
const operatorId = operatorCommandIdForTex(node.name);
|
|
4211
|
+
if (operatorId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
|
|
4212
|
+
const atomicOperator = createEditorNode("atomicOperatorCommand", operatorId);
|
|
4213
|
+
const scripts = attachScripts(node, atomicOperator);
|
|
4214
|
+
if (scripts) {
|
|
4215
|
+
return scripts;
|
|
4216
|
+
}
|
|
4217
|
+
return { editable: true, node: atomicOperator };
|
|
4218
|
+
}
|
|
4219
|
+
if (isStandardCommandTex(node.name) && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
|
|
4220
|
+
const standard = createEditorNode("standardCommand", node.name);
|
|
4221
|
+
const scripts = attachScripts(node, standard);
|
|
4222
|
+
if (scripts) {
|
|
4223
|
+
return scripts;
|
|
4224
|
+
}
|
|
4225
|
+
return { editable: true, node: standard };
|
|
4226
|
+
}
|
|
4227
|
+
const textLike = charFromTextLikeCommand(node);
|
|
4228
|
+
if (textLike) {
|
|
4229
|
+
return textLike;
|
|
4230
|
+
}
|
|
4231
|
+
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}` };
|
|
4232
|
+
}
|
|
4233
|
+
function astNodeToEditorNode(node) {
|
|
4234
|
+
if (node instanceof CharNode) {
|
|
4235
|
+
const normalized = normalizeCharImportExpr(node.expr);
|
|
4236
|
+
const editorNode = createEditorNode("char", normalized.expr);
|
|
4237
|
+
if (normalized.characterFont !== "default") {
|
|
4238
|
+
editorNode.characterFont = normalized.characterFont;
|
|
4239
|
+
}
|
|
4240
|
+
const scripts = attachScripts(node, editorNode);
|
|
4241
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
4242
|
+
}
|
|
4243
|
+
if (node instanceof NumberNode) {
|
|
4244
|
+
const editorNode = createEditorNode("number", node.expr);
|
|
4245
|
+
const scripts = attachScripts(node, editorNode);
|
|
4246
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
4247
|
+
}
|
|
4248
|
+
if (node instanceof OperatorNode) {
|
|
4249
|
+
return { editable: true, node: createEditorNode("operator", node.expr) };
|
|
4250
|
+
}
|
|
4251
|
+
if (node instanceof DelimiterNode) {
|
|
4252
|
+
const editorNode = createDelimiterNode(node.leftDelimExpr, node.rightDelimExpr);
|
|
4253
|
+
const inner = chainToEditorChain(node.innerExpr);
|
|
4254
|
+
if (!inner.editable) {
|
|
4255
|
+
return inner;
|
|
4256
|
+
}
|
|
4257
|
+
editorNode.innerExpr = inner.chain;
|
|
4258
|
+
const scripts = attachScripts(node, editorNode);
|
|
4259
|
+
return scripts ?? { editable: true, node: editorNode };
|
|
4260
|
+
}
|
|
4261
|
+
if (node instanceof CommandNode) {
|
|
4262
|
+
return commandToEditorNode(node);
|
|
4263
|
+
}
|
|
4264
|
+
if (node instanceof EnvNode) {
|
|
4265
|
+
return envToEditorNode(node);
|
|
4266
|
+
}
|
|
4267
|
+
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}` };
|
|
4268
|
+
}
|
|
4269
|
+
var VERTICAL_DELIMITER_COMMAND_PAIRS = {
|
|
4270
|
+
"\\vert": "\\vert",
|
|
4271
|
+
"\\lvert": "\\rvert",
|
|
4272
|
+
"\\Vert": "\\Vert",
|
|
4273
|
+
"\\lVert": "\\rVert",
|
|
4274
|
+
"\\|": "\\|"
|
|
4275
|
+
};
|
|
4276
|
+
function isBareCommand(node, name) {
|
|
4277
|
+
return node instanceof CommandNode && node.name === name && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0;
|
|
4278
|
+
}
|
|
4279
|
+
function normalizeVerticalDelimiterCommands(chain) {
|
|
4280
|
+
const normalized = [];
|
|
4281
|
+
for (let index = 0; index < chain.chain.length; index += 1) {
|
|
4282
|
+
const left = chain.chain[index];
|
|
4283
|
+
if (!(left instanceof CommandNode) || left.superscript || left.subscript) {
|
|
4284
|
+
normalized.push(left);
|
|
4285
|
+
continue;
|
|
4286
|
+
}
|
|
4287
|
+
const rightName = VERTICAL_DELIMITER_COMMAND_PAIRS[left.name];
|
|
4288
|
+
if (!rightName || left.optionalArgs.length > 0 || left.mandatoryArgs.length > 0) {
|
|
4289
|
+
normalized.push(left);
|
|
4290
|
+
continue;
|
|
4291
|
+
}
|
|
4292
|
+
let rightIndex = -1;
|
|
4293
|
+
for (let candidate = index + 1; candidate < chain.chain.length; candidate += 1) {
|
|
4294
|
+
if (isBareCommand(chain.chain[candidate], rightName)) {
|
|
4295
|
+
rightIndex = candidate;
|
|
4296
|
+
break;
|
|
4297
|
+
}
|
|
4298
|
+
}
|
|
4299
|
+
if (rightIndex < 0) {
|
|
4300
|
+
normalized.push(left);
|
|
4301
|
+
continue;
|
|
4302
|
+
}
|
|
4303
|
+
const right = chain.chain[rightIndex];
|
|
4304
|
+
const delimiter = new DelimiterNode(
|
|
4305
|
+
left.name,
|
|
4306
|
+
new ChainNode(chain.chain.slice(index + 1, rightIndex)),
|
|
4307
|
+
right.name
|
|
4308
|
+
);
|
|
4309
|
+
delimiter.superscript = right.superscript;
|
|
4310
|
+
delimiter.subscript = right.subscript;
|
|
4311
|
+
normalized.push(delimiter);
|
|
4312
|
+
index = rightIndex;
|
|
4313
|
+
}
|
|
4314
|
+
return new ChainNode(normalized);
|
|
4315
|
+
}
|
|
4316
|
+
function chainToEditorChain(chain) {
|
|
4317
|
+
const nodes = [];
|
|
4318
|
+
for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
|
|
4319
|
+
const converted = astNodeToEditorNode(astNode);
|
|
4320
|
+
if (!converted.editable) {
|
|
4321
|
+
return converted;
|
|
4322
|
+
}
|
|
4323
|
+
nodes.push(converted.node);
|
|
4324
|
+
}
|
|
4325
|
+
return { editable: true, chain: createEditorChain(nodes) };
|
|
4326
|
+
}
|
|
4327
|
+
function mathObjectToEditorSession(math) {
|
|
4328
|
+
if (math.lines.length !== 1) {
|
|
4329
|
+
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" };
|
|
4330
|
+
}
|
|
4331
|
+
const english = chainToEditorChain(math.lines[0]);
|
|
4332
|
+
if (!english.editable) {
|
|
4333
|
+
return english;
|
|
4334
|
+
}
|
|
4335
|
+
const arabic = cloneChainWithFreshIds(english.chain);
|
|
4336
|
+
const session = createEditorSession(english.chain, arabic, "english");
|
|
4337
|
+
session.sync = buildInitialSyncMap(session.englishTree, session.arabicTree);
|
|
4338
|
+
return { editable: true, session: cloneEditorSession(session) };
|
|
4339
|
+
}
|
|
4340
|
+
function attachAstScripts(editorNode, astNode) {
|
|
4341
|
+
if (editorNode.superscript) {
|
|
4342
|
+
const sup = editorChainToAstChain(editorNode.superscript);
|
|
4343
|
+
if (!sup.ok) {
|
|
4344
|
+
return sup;
|
|
4345
|
+
}
|
|
4346
|
+
astNode.superscript = sup.chain;
|
|
4347
|
+
}
|
|
4348
|
+
if (editorNode.subscript) {
|
|
4349
|
+
const sub = editorChainToAstChain(editorNode.subscript);
|
|
4350
|
+
if (!sub.ok) {
|
|
4351
|
+
return sub;
|
|
4352
|
+
}
|
|
4353
|
+
astNode.subscript = sub.chain;
|
|
4354
|
+
}
|
|
4355
|
+
return null;
|
|
4356
|
+
}
|
|
4357
|
+
function editorEnvOpening(node) {
|
|
4358
|
+
const envName = node.envName ?? node.matrixStyle;
|
|
4359
|
+
if (!envName) {
|
|
4360
|
+
return null;
|
|
4361
|
+
}
|
|
4362
|
+
if (envName === "array") {
|
|
4363
|
+
const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows?.[0]?.length ?? 0).join("") || "c";
|
|
4364
|
+
return { opening: `\\begin{array}{${spec}}`, closing: "\\end{array}" };
|
|
4365
|
+
}
|
|
4366
|
+
return { opening: `\\begin{${envName}}`, closing: `\\end{${envName}}` };
|
|
4367
|
+
}
|
|
4368
|
+
function editorEnvToAstNode(node) {
|
|
4369
|
+
const wrapper = editorEnvOpening(node);
|
|
4370
|
+
if (!wrapper || !node.matrixRows) {
|
|
4371
|
+
return { ok: 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" };
|
|
4372
|
+
}
|
|
4373
|
+
const lines = [];
|
|
4374
|
+
for (const row of node.matrixRows) {
|
|
4375
|
+
const lineNodes = [];
|
|
4376
|
+
for (let columnIndex = 0; columnIndex < row.length; columnIndex += 1) {
|
|
4377
|
+
if (columnIndex > 0) {
|
|
4378
|
+
lineNodes.push(new OperatorNode("&"));
|
|
4379
|
+
}
|
|
4380
|
+
const cell = editorChainToAstChain(row[columnIndex]);
|
|
4381
|
+
if (!cell.ok) {
|
|
4382
|
+
return cell;
|
|
4383
|
+
}
|
|
4384
|
+
lineNodes.push(...cell.chain.chain);
|
|
4385
|
+
}
|
|
4386
|
+
lines.push(new ChainNode(lineNodes));
|
|
4387
|
+
}
|
|
4388
|
+
const env = new EnvNode(wrapper.opening, lines, wrapper.closing);
|
|
4389
|
+
const scripts = attachAstScripts(node, env);
|
|
4390
|
+
return scripts ?? { ok: true, node: env };
|
|
4391
|
+
}
|
|
4392
|
+
function accentChainForExport(accent) {
|
|
4393
|
+
if (!accent) {
|
|
4394
|
+
return { ok: true, chain: new ChainNode([]) };
|
|
4395
|
+
}
|
|
4396
|
+
return editorChainToAstChain(accent);
|
|
4397
|
+
}
|
|
4398
|
+
function nodeFromAccentBase(command, accent, base) {
|
|
4399
|
+
if (accent.chain.length > 0) {
|
|
4400
|
+
return new CommandNode(command, [], [accent, base]);
|
|
4401
|
+
}
|
|
4402
|
+
if (base.chain.length === 1) {
|
|
4403
|
+
return base.chain[0];
|
|
4404
|
+
}
|
|
4405
|
+
return new DelimiterNode("", base, "");
|
|
4406
|
+
}
|
|
4407
|
+
function editorNodeToAstNode(node) {
|
|
4408
|
+
let astNode;
|
|
4409
|
+
if (node.kind === "char") {
|
|
4410
|
+
astNode = charEditorNodeToAstNode(node);
|
|
4411
|
+
} else if (node.kind === "number") {
|
|
4412
|
+
astNode = new NumberNode(node.expr);
|
|
4413
|
+
} else if (node.kind === "operator") {
|
|
4414
|
+
astNode = new OperatorNode(node.expr);
|
|
4415
|
+
} else if (node.kind === "delimiter" && node.innerExpr) {
|
|
4416
|
+
const inner = editorChainToAstChain(node.innerExpr);
|
|
4417
|
+
if (!inner.ok) {
|
|
4418
|
+
return inner;
|
|
4419
|
+
}
|
|
4420
|
+
astNode = new DelimiterNode(node.leftDelimExpr, inner.chain, node.rightDelimExpr);
|
|
4421
|
+
} else if (node.kind === "frac" && node.numerator && node.denominator) {
|
|
4422
|
+
const numerator = editorChainToAstChain(node.numerator);
|
|
4423
|
+
const denominator = editorChainToAstChain(node.denominator);
|
|
4424
|
+
if (!numerator.ok) {
|
|
4425
|
+
return numerator;
|
|
4426
|
+
}
|
|
4427
|
+
if (!denominator.ok) {
|
|
4428
|
+
return denominator;
|
|
4429
|
+
}
|
|
4430
|
+
astNode = new CommandNode("\\frac", [], [numerator.chain, denominator.chain]);
|
|
4431
|
+
} else if (node.kind === "sqrt" && node.radicand) {
|
|
4432
|
+
const radicand = editorChainToAstChain(node.radicand);
|
|
4433
|
+
if (!radicand.ok) {
|
|
4434
|
+
return radicand;
|
|
4435
|
+
}
|
|
4436
|
+
const optionalArgs = [];
|
|
4437
|
+
if (node.rootIndex && node.rootIndex.nodes.length > 0) {
|
|
4438
|
+
const rootIndex = editorChainToAstChain(node.rootIndex);
|
|
4439
|
+
if (!rootIndex.ok) {
|
|
4440
|
+
return rootIndex;
|
|
4441
|
+
}
|
|
4442
|
+
optionalArgs.push(rootIndex.chain);
|
|
4443
|
+
}
|
|
4444
|
+
astNode = new CommandNode("\\sqrt", optionalArgs, [radicand.chain]);
|
|
4445
|
+
} else if (node.kind === "overset" && node.baseExpr) {
|
|
4446
|
+
const accent = accentChainForExport(node.overExpr);
|
|
4447
|
+
if (!accent.ok) {
|
|
4448
|
+
return accent;
|
|
4449
|
+
}
|
|
4450
|
+
const baseExpr = editorChainToAstChain(node.baseExpr);
|
|
4451
|
+
if (!baseExpr.ok) {
|
|
4452
|
+
return baseExpr;
|
|
4453
|
+
}
|
|
4454
|
+
astNode = nodeFromAccentBase("\\overset", accent.chain, baseExpr.chain);
|
|
4455
|
+
} else if (node.kind === "underset" && node.baseExpr) {
|
|
4456
|
+
const accent = accentChainForExport(node.underExpr);
|
|
4457
|
+
if (!accent.ok) {
|
|
4458
|
+
return accent;
|
|
4459
|
+
}
|
|
4460
|
+
const baseExpr = editorChainToAstChain(node.baseExpr);
|
|
4461
|
+
if (!baseExpr.ok) {
|
|
4462
|
+
return baseExpr;
|
|
4463
|
+
}
|
|
4464
|
+
astNode = nodeFromAccentBase("\\underset", accent.chain, baseExpr.chain);
|
|
4465
|
+
} else if (node.kind === "accent" && node.baseExpr) {
|
|
4466
|
+
const tex = accentCommandSpec(node.expr)?.englishTex;
|
|
4467
|
+
if (!tex) {
|
|
4468
|
+
return { ok: false, reason: `\u0644\u0643\u0646\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
|
|
4469
|
+
}
|
|
4470
|
+
const baseExpr = editorChainToAstChain(node.baseExpr);
|
|
4471
|
+
if (!baseExpr.ok) {
|
|
4472
|
+
return baseExpr;
|
|
4473
|
+
}
|
|
4474
|
+
astNode = new CommandNode(tex, [], [baseExpr.chain]);
|
|
4475
|
+
} else if (node.kind === "atomicCommand") {
|
|
4476
|
+
const tex = atomicCommandSpec(node.expr)?.englishTex;
|
|
4477
|
+
if (!tex) {
|
|
4478
|
+
return { ok: false, reason: `\u0623\u0645\u0631 \u0631\u064A\u0627\u0636\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
|
|
4479
|
+
}
|
|
4480
|
+
astNode = new CommandNode(tex);
|
|
4481
|
+
} else if (node.kind === "atomicOperatorCommand") {
|
|
4482
|
+
const tex = atomicOperatorCommandSpec(node.expr)?.Tex;
|
|
4483
|
+
if (!tex) {
|
|
4484
|
+
return { ok: false, reason: `\u0631\u0645\u0632 \u0631\u064A\u0627\u0636\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
|
|
4485
|
+
}
|
|
4486
|
+
astNode = new CommandNode(tex);
|
|
4487
|
+
} else if (node.kind === "standardCommand") {
|
|
4488
|
+
if (!isStandardCommandTex(node.expr)) {
|
|
4489
|
+
return { ok: false, reason: `\u0623\u0645\u0631 \u0631\u064A\u0627\u0636\u064A \u0642\u064A\u0627\u0633\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
|
|
4490
|
+
}
|
|
4491
|
+
astNode = new CommandNode(node.expr);
|
|
4492
|
+
} else if (node.kind === "env") {
|
|
4493
|
+
return editorEnvToAstNode(node);
|
|
4494
|
+
} else {
|
|
4495
|
+
return { ok: 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.kind}` };
|
|
4496
|
+
}
|
|
4497
|
+
const scripts = attachAstScripts(node, astNode);
|
|
4498
|
+
return scripts ?? { ok: true, node: astNode };
|
|
4499
|
+
}
|
|
4500
|
+
function editorChainToAstChain(chain) {
|
|
4501
|
+
const nodes = [];
|
|
4502
|
+
for (const editorNode of chain.nodes) {
|
|
4503
|
+
const converted = editorNodeToAstNode(editorNode);
|
|
4504
|
+
if (!converted.ok) {
|
|
4505
|
+
return converted;
|
|
4506
|
+
}
|
|
4507
|
+
nodes.push(converted.node);
|
|
4508
|
+
}
|
|
4509
|
+
return { ok: true, chain: new ChainNode(nodes) };
|
|
4510
|
+
}
|
|
4511
|
+
function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
|
|
4512
|
+
const converted = editorChainToAstChain(session.englishTree);
|
|
4513
|
+
if (!converted.ok) {
|
|
4514
|
+
return converted;
|
|
4515
|
+
}
|
|
4516
|
+
return {
|
|
4517
|
+
ok: true,
|
|
4518
|
+
math: {
|
|
4519
|
+
nodeType: "MathObject",
|
|
4520
|
+
mathMode,
|
|
4521
|
+
lines: [converted.chain],
|
|
4522
|
+
closing
|
|
4523
|
+
}
|
|
4524
|
+
};
|
|
4525
|
+
}
|
|
2912
4526
|
|
|
2913
4527
|
// src/document2/jsonCommandTypes.ts
|
|
2914
4528
|
var Document2CommandError = class extends Error {
|
|
@@ -5591,6 +7205,76 @@ function document2Latex2(document2, options = {}) {
|
|
|
5591
7205
|
return document2Latex(document2, options);
|
|
5592
7206
|
}
|
|
5593
7207
|
|
|
7208
|
+
// src/document2-cli/mathDiagnostic.ts
|
|
7209
|
+
function compactError(error) {
|
|
7210
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
7211
|
+
return message.slice(0, 500);
|
|
7212
|
+
}
|
|
7213
|
+
function sourceMode(value) {
|
|
7214
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value) && value.source_side === "arabic") {
|
|
7215
|
+
return "arabic";
|
|
7216
|
+
}
|
|
7217
|
+
return "english";
|
|
7218
|
+
}
|
|
7219
|
+
function diagnoseMathObject(mathObject) {
|
|
7220
|
+
let math;
|
|
7221
|
+
try {
|
|
7222
|
+
math = fromMathObjectJson(mathObject, sourceMode(mathObject));
|
|
7223
|
+
} catch (error) {
|
|
7224
|
+
return {
|
|
7225
|
+
ok: false,
|
|
7226
|
+
stage: "fromMathObjectJson",
|
|
7227
|
+
editable: false,
|
|
7228
|
+
error: compactError(error)
|
|
7229
|
+
};
|
|
7230
|
+
}
|
|
7231
|
+
const result = mathObjectToEditorSession(math);
|
|
7232
|
+
if (!result.editable) {
|
|
7233
|
+
return {
|
|
7234
|
+
ok: false,
|
|
7235
|
+
stage: "mathObjectToEditorSession",
|
|
7236
|
+
editable: false,
|
|
7237
|
+
error: result.reason.slice(0, 500)
|
|
7238
|
+
};
|
|
7239
|
+
}
|
|
7240
|
+
return {
|
|
7241
|
+
ok: true,
|
|
7242
|
+
stage: "mathObjectToEditorSession",
|
|
7243
|
+
editable: true,
|
|
7244
|
+
english_latex: renderEnglishLatexFromSession(result.session),
|
|
7245
|
+
arabic_latex: renderArabicLatexFromSession(result.session)
|
|
7246
|
+
};
|
|
7247
|
+
}
|
|
7248
|
+
|
|
7249
|
+
// src/document2-cli/mathProjection.ts
|
|
7250
|
+
function sourceMode2(value) {
|
|
7251
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value) && value.source_side === "arabic") {
|
|
7252
|
+
return "arabic";
|
|
7253
|
+
}
|
|
7254
|
+
return "english";
|
|
7255
|
+
}
|
|
7256
|
+
function projectMathObjectToEnglish(mathObject) {
|
|
7257
|
+
let math;
|
|
7258
|
+
try {
|
|
7259
|
+
math = fromMathObjectJson(mathObject, sourceMode2(mathObject));
|
|
7260
|
+
} catch {
|
|
7261
|
+
throw new Document2CommandError("invalid_inline_token", "MathObject JSON is invalid");
|
|
7262
|
+
}
|
|
7263
|
+
const sessionResult = mathObjectToEditorSession(math);
|
|
7264
|
+
if (!sessionResult.editable) {
|
|
7265
|
+
throw new Document2CommandError("unsupported_inline_content", sessionResult.reason);
|
|
7266
|
+
}
|
|
7267
|
+
const projected = mathNodeFromEditorSession(
|
|
7268
|
+
sessionResult.session,
|
|
7269
|
+
math.mathMode,
|
|
7270
|
+
math.closing
|
|
7271
|
+
);
|
|
7272
|
+
if (!projected.ok) {
|
|
7273
|
+
throw new Document2CommandError("unsupported_inline_content", projected.reason);
|
|
7274
|
+
}
|
|
7275
|
+
return toMathObjectJson(projected.math);
|
|
7276
|
+
}
|
|
7277
|
+
|
|
5594
7278
|
// src/document2-cli/protocol.ts
|
|
5595
7279
|
var Document2WorkerProtocolError = class extends Error {
|
|
5596
7280
|
code;
|
|
@@ -5613,6 +7297,12 @@ function parseDocument2WorkerRequest(value) {
|
|
|
5613
7297
|
}
|
|
5614
7298
|
return { action: "diff", before: value.before, after: value.after };
|
|
5615
7299
|
}
|
|
7300
|
+
if (value.action === "diagnose_math_object" || value.action === "project_math_object_english") {
|
|
7301
|
+
if (!("math_object" in value)) {
|
|
7302
|
+
throw new Document2WorkerProtocolError("invalid_request", `${value.action} requires math_object`);
|
|
7303
|
+
}
|
|
7304
|
+
return { action: value.action, math_object: value.math_object };
|
|
7305
|
+
}
|
|
5616
7306
|
if (!("document" in value)) {
|
|
5617
7307
|
throw new Document2WorkerProtocolError("invalid_request", "Worker request requires a document");
|
|
5618
7308
|
}
|
|
@@ -5621,7 +7311,7 @@ function parseDocument2WorkerRequest(value) {
|
|
|
5621
7311
|
}
|
|
5622
7312
|
if (value.action === "apply_command") {
|
|
5623
7313
|
if (!("command" in value)) {
|
|
5624
|
-
throw new Document2WorkerProtocolError("invalid_request", "apply_command requires
|
|
7314
|
+
throw new Document2WorkerProtocolError("invalid_request", "apply_command requires command");
|
|
5625
7315
|
}
|
|
5626
7316
|
return { action: value.action, document: value.document, command: value.command };
|
|
5627
7317
|
}
|
|
@@ -5720,6 +7410,15 @@ function collectAssetIds(blocks) {
|
|
|
5720
7410
|
}
|
|
5721
7411
|
function executeDocument2WorkerRequest(input) {
|
|
5722
7412
|
const request = parseDocument2WorkerRequest(input);
|
|
7413
|
+
if (request.action === "diagnose_math_object") {
|
|
7414
|
+
return { ok: true, math_diagnostic: diagnoseMathObject(request.math_object) };
|
|
7415
|
+
}
|
|
7416
|
+
if (request.action === "project_math_object_english") {
|
|
7417
|
+
return {
|
|
7418
|
+
ok: true,
|
|
7419
|
+
english_math_object: projectMathObjectToEnglish(request.math_object)
|
|
7420
|
+
};
|
|
7421
|
+
}
|
|
5723
7422
|
if (request.action === "normalize") {
|
|
5724
7423
|
return { ok: true, document: normalizeDocument(request.document) };
|
|
5725
7424
|
}
|
|
@@ -5874,6 +7573,10 @@ function requestId(request) {
|
|
|
5874
7573
|
const value = request.headers["x-request-id"];
|
|
5875
7574
|
return typeof value === "string" ? value.slice(0, 200) : "-";
|
|
5876
7575
|
}
|
|
7576
|
+
function traceId(request) {
|
|
7577
|
+
const value = request.headers["x-trace-id"];
|
|
7578
|
+
return typeof value === "string" ? value.slice(0, 128) : void 0;
|
|
7579
|
+
}
|
|
5877
7580
|
function actionForPath(pathname) {
|
|
5878
7581
|
if (pathname === "/v1/document2/normalize") {
|
|
5879
7582
|
return "normalize";
|
|
@@ -5896,12 +7599,19 @@ function actionForPath(pathname) {
|
|
|
5896
7599
|
if (pathname === "/v1/document2/commands") {
|
|
5897
7600
|
return "apply_command";
|
|
5898
7601
|
}
|
|
7602
|
+
if (pathname === "/v1/document2/diagnostics/math-object") {
|
|
7603
|
+
return "diagnose_math_object";
|
|
7604
|
+
}
|
|
7605
|
+
if (pathname === "/v1/document2/math-object/english") {
|
|
7606
|
+
return "project_math_object_english";
|
|
7607
|
+
}
|
|
5899
7608
|
return null;
|
|
5900
7609
|
}
|
|
5901
7610
|
function defaultLogger(entry) {
|
|
5902
7611
|
const unexpected = entry.unexpected instanceof Error ? { name: entry.unexpected.name, message: entry.unexpected.message, stack: entry.unexpected.stack } : entry.unexpected;
|
|
5903
7612
|
console.error(JSON.stringify({
|
|
5904
7613
|
request_id: entry.requestId,
|
|
7614
|
+
...entry.traceId ? { trace_id: entry.traceId } : {},
|
|
5905
7615
|
operation: entry.operation,
|
|
5906
7616
|
status: entry.status,
|
|
5907
7617
|
duration_ms: entry.durationMs,
|
|
@@ -5955,6 +7665,7 @@ function createDocument2HttpServer(options) {
|
|
|
5955
7665
|
operation,
|
|
5956
7666
|
status: status ?? 500,
|
|
5957
7667
|
durationMs: Date.now() - startedAt,
|
|
7668
|
+
...traceId(request) ? { traceId: traceId(request) } : {},
|
|
5958
7669
|
...unexpected !== void 0 ? { unexpected } : {}
|
|
5959
7670
|
});
|
|
5960
7671
|
}
|