temml 0.10.4 → 0.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/temml.cjs +68 -87
- package/dist/temml.js +68 -87
- package/dist/temml.min.js +1 -1
- package/dist/temml.mjs +68 -87
- package/dist/temmlPostProcess.js +1 -1
- package/package.json +1 -1
- package/src/functions/color.js +10 -6
- package/src/linebreaking.js +60 -82
- package/src/postProcess.js +1 -1
package/dist/temml.cjs
CHANGED
@@ -1761,125 +1761,102 @@ for (let i = 0; i < 10; i++) {
|
|
1761
1761
|
* much of this module.
|
1762
1762
|
*/
|
1763
1763
|
|
1764
|
-
function setLineBreaks(expression, wrapMode, isDisplayMode
|
1765
|
-
if (color === undefined && wrapMode !== "none") {
|
1766
|
-
// First, make one pass through the expression and split any color nodes.
|
1767
|
-
const upperLimit = expression.length - 1;
|
1768
|
-
for (let i = upperLimit; i >= 0; i--) {
|
1769
|
-
const node = expression[i];
|
1770
|
-
if (node.type === "mstyle" && node.attributes.mathcolor) {
|
1771
|
-
const color = node.attributes.mathcolor;
|
1772
|
-
const fragment = setLineBreaks(node.children, wrapMode, isDisplayMode, color);
|
1773
|
-
if (!(fragment.type && fragment.type !== "mtable")) {
|
1774
|
-
expression.splice(i, 1, ...fragment.children);
|
1775
|
-
}
|
1776
|
-
}
|
1777
|
-
}
|
1778
|
-
}
|
1779
|
-
|
1780
|
-
const tagName = color ? "mstyle" : "mrow";
|
1781
|
-
|
1764
|
+
function setLineBreaks(expression, wrapMode, isDisplayMode) {
|
1782
1765
|
const mtrs = [];
|
1783
1766
|
let mrows = [];
|
1784
1767
|
let block = [];
|
1785
1768
|
let numTopLevelEquals = 0;
|
1786
1769
|
let canBeBIN = false; // The first node cannot be an infix binary operator.
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
// Start a new block. (Insert a soft linebreak.)
|
1792
|
-
mrows.push(new mathMLTree.MathNode(tagName, block));
|
1793
|
-
}
|
1794
|
-
// Insert the mstyle
|
1795
|
-
mrows.push(node);
|
1796
|
-
block = [];
|
1797
|
-
continue
|
1770
|
+
let i = 0;
|
1771
|
+
while (i < expression.length) {
|
1772
|
+
while (expression[i] instanceof DocumentFragment) {
|
1773
|
+
expression.splice(i, 1, ...expression[i].children); // Expand the fragment.
|
1798
1774
|
}
|
1775
|
+
const node = expression[i];
|
1799
1776
|
if (node.attributes && node.attributes.linebreak &&
|
1800
1777
|
node.attributes.linebreak === "newline") {
|
1801
1778
|
// A hard line break. Create a <mtr> for the current block.
|
1802
1779
|
if (block.length > 0) {
|
1803
|
-
|
1804
|
-
if (color) { element.setAttribute("mathcolor", color); }
|
1805
|
-
mrows.push(new mathMLTree.MathNode(tagName, block));
|
1780
|
+
mrows.push(new mathMLTree.MathNode("mrow", block));
|
1806
1781
|
}
|
1807
1782
|
mrows.push(node);
|
1808
1783
|
block = [];
|
1809
1784
|
const mtd = new mathMLTree.MathNode("mtd", mrows);
|
1785
|
+
mtd.style.textAlign = "left";
|
1810
1786
|
mtrs.push(new mathMLTree.MathNode("mtr", [mtd]));
|
1811
1787
|
mrows = [];
|
1788
|
+
i += 1;
|
1812
1789
|
continue
|
1813
1790
|
}
|
1814
1791
|
block.push(node);
|
1815
|
-
if (node.type && node.type === "mo" &&
|
1816
|
-
if (
|
1792
|
+
if (node.type && node.type === "mo" && node.children.length === 1) {
|
1793
|
+
if (wrapMode === "=" && node.children[0].text === "=") {
|
1817
1794
|
numTopLevelEquals += 1;
|
1818
1795
|
if (numTopLevelEquals > 1) {
|
1819
1796
|
block.pop();
|
1820
1797
|
// Start a new block. (Insert a soft linebreak.)
|
1821
|
-
const element = new mathMLTree.MathNode(
|
1822
|
-
if (color) { element.setAttribute("mathcolor", color); }
|
1798
|
+
const element = new mathMLTree.MathNode("mrow", block);
|
1823
1799
|
mrows.push(element);
|
1824
1800
|
block = [node];
|
1825
1801
|
}
|
1826
|
-
}
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
)
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
const nd = expression[j];
|
1845
|
-
if (
|
1846
|
-
nd.type &&
|
1847
|
-
nd.type === "mspace" &&
|
1848
|
-
!(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
|
1849
|
-
) {
|
1850
|
-
block.push(nd);
|
1851
|
-
i += 1;
|
1802
|
+
} else if (wrapMode === "tex") {
|
1803
|
+
// This may be a place for a soft line break.
|
1804
|
+
if (canBeBIN && !node.attributes.form) {
|
1805
|
+
// Check if the following node is a \nobreak text node, e.g. "~""
|
1806
|
+
const next = i < expression.length - 1 ? expression[i + 1] : null;
|
1807
|
+
let glueIsFreeOfNobreak = true;
|
1808
|
+
if (
|
1809
|
+
!(
|
1810
|
+
next &&
|
1811
|
+
next.type === "mtext" &&
|
1812
|
+
next.attributes.linebreak &&
|
1813
|
+
next.attributes.linebreak === "nobreak"
|
1814
|
+
)
|
1815
|
+
) {
|
1816
|
+
// We may need to start a new block.
|
1817
|
+
// First, put any post-operator glue on same line as operator.
|
1818
|
+
for (let j = i + 1; j < expression.length; j++) {
|
1819
|
+
const nd = expression[j];
|
1852
1820
|
if (
|
1853
|
-
nd.
|
1854
|
-
nd.
|
1855
|
-
nd.attributes.linebreak === "
|
1821
|
+
nd.type &&
|
1822
|
+
nd.type === "mspace" &&
|
1823
|
+
!(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
|
1856
1824
|
) {
|
1857
|
-
|
1825
|
+
block.push(nd);
|
1826
|
+
i += 1;
|
1827
|
+
if (
|
1828
|
+
nd.attributes &&
|
1829
|
+
nd.attributes.linebreak &&
|
1830
|
+
nd.attributes.linebreak === "nobreak"
|
1831
|
+
) {
|
1832
|
+
glueIsFreeOfNobreak = false;
|
1833
|
+
}
|
1834
|
+
} else {
|
1835
|
+
break;
|
1858
1836
|
}
|
1859
|
-
} else {
|
1860
|
-
break;
|
1861
1837
|
}
|
1862
1838
|
}
|
1839
|
+
if (glueIsFreeOfNobreak) {
|
1840
|
+
// Start a new block. (Insert a soft linebreak.)
|
1841
|
+
const element = new mathMLTree.MathNode("mrow", block);
|
1842
|
+
mrows.push(element);
|
1843
|
+
block = [];
|
1844
|
+
}
|
1845
|
+
canBeBIN = false;
|
1863
1846
|
}
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
block = [];
|
1870
|
-
}
|
1871
|
-
canBeBIN = false;
|
1847
|
+
const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix";
|
1848
|
+
// Any operator that follows an open delimiter is unary.
|
1849
|
+
canBeBIN = !(node.attributes.separator || isOpenDelimiter);
|
1850
|
+
} else {
|
1851
|
+
canBeBIN = true;
|
1872
1852
|
}
|
1873
|
-
const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix";
|
1874
|
-
// Any operator that follows an open delimiter is unary.
|
1875
|
-
canBeBIN = !(node.attributes.separator || isOpenDelimiter);
|
1876
1853
|
} else {
|
1877
1854
|
canBeBIN = true;
|
1878
1855
|
}
|
1856
|
+
i += 1;
|
1879
1857
|
}
|
1880
1858
|
if (block.length > 0) {
|
1881
|
-
const element = new mathMLTree.MathNode(
|
1882
|
-
if (color) { element.setAttribute("mathcolor", color); }
|
1859
|
+
const element = new mathMLTree.MathNode("mrow", block);
|
1883
1860
|
mrows.push(element);
|
1884
1861
|
}
|
1885
1862
|
if (mtrs.length > 0) {
|
@@ -3082,11 +3059,15 @@ const validateColor = (color, macros, token) => {
|
|
3082
3059
|
};
|
3083
3060
|
|
3084
3061
|
const mathmlBuilder$9 = (group, style) => {
|
3085
|
-
|
3086
|
-
//
|
3087
|
-
|
3088
|
-
|
3089
|
-
|
3062
|
+
// In LaTeX, color is not supposed to change the spacing of any node.
|
3063
|
+
// So instead of wrapping the group in an <mstyle>, we apply
|
3064
|
+
// the color individually to each node and return a document fragment.
|
3065
|
+
let expr = buildExpression(group.body, style.withColor(group.color));
|
3066
|
+
expr = expr.map(e => {
|
3067
|
+
e.style.color = group.color;
|
3068
|
+
return e
|
3069
|
+
});
|
3070
|
+
return mathMLTree.newDocumentFragment(expr)
|
3090
3071
|
};
|
3091
3072
|
|
3092
3073
|
defineFunction({
|
@@ -12997,7 +12978,7 @@ class Style {
|
|
12997
12978
|
* https://mit-license.org/
|
12998
12979
|
*/
|
12999
12980
|
|
13000
|
-
const version = "0.10.
|
12981
|
+
const version = "0.10.5";
|
13001
12982
|
|
13002
12983
|
function postProcess(block) {
|
13003
12984
|
const labelMap = {};
|
package/dist/temml.js
CHANGED
@@ -1762,125 +1762,102 @@ var temml = (function () {
|
|
1762
1762
|
* much of this module.
|
1763
1763
|
*/
|
1764
1764
|
|
1765
|
-
function setLineBreaks(expression, wrapMode, isDisplayMode
|
1766
|
-
if (color === undefined && wrapMode !== "none") {
|
1767
|
-
// First, make one pass through the expression and split any color nodes.
|
1768
|
-
const upperLimit = expression.length - 1;
|
1769
|
-
for (let i = upperLimit; i >= 0; i--) {
|
1770
|
-
const node = expression[i];
|
1771
|
-
if (node.type === "mstyle" && node.attributes.mathcolor) {
|
1772
|
-
const color = node.attributes.mathcolor;
|
1773
|
-
const fragment = setLineBreaks(node.children, wrapMode, isDisplayMode, color);
|
1774
|
-
if (!(fragment.type && fragment.type !== "mtable")) {
|
1775
|
-
expression.splice(i, 1, ...fragment.children);
|
1776
|
-
}
|
1777
|
-
}
|
1778
|
-
}
|
1779
|
-
}
|
1780
|
-
|
1781
|
-
const tagName = color ? "mstyle" : "mrow";
|
1782
|
-
|
1765
|
+
function setLineBreaks(expression, wrapMode, isDisplayMode) {
|
1783
1766
|
const mtrs = [];
|
1784
1767
|
let mrows = [];
|
1785
1768
|
let block = [];
|
1786
1769
|
let numTopLevelEquals = 0;
|
1787
1770
|
let canBeBIN = false; // The first node cannot be an infix binary operator.
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
// Start a new block. (Insert a soft linebreak.)
|
1793
|
-
mrows.push(new mathMLTree.MathNode(tagName, block));
|
1794
|
-
}
|
1795
|
-
// Insert the mstyle
|
1796
|
-
mrows.push(node);
|
1797
|
-
block = [];
|
1798
|
-
continue
|
1771
|
+
let i = 0;
|
1772
|
+
while (i < expression.length) {
|
1773
|
+
while (expression[i] instanceof DocumentFragment) {
|
1774
|
+
expression.splice(i, 1, ...expression[i].children); // Expand the fragment.
|
1799
1775
|
}
|
1776
|
+
const node = expression[i];
|
1800
1777
|
if (node.attributes && node.attributes.linebreak &&
|
1801
1778
|
node.attributes.linebreak === "newline") {
|
1802
1779
|
// A hard line break. Create a <mtr> for the current block.
|
1803
1780
|
if (block.length > 0) {
|
1804
|
-
|
1805
|
-
if (color) { element.setAttribute("mathcolor", color); }
|
1806
|
-
mrows.push(new mathMLTree.MathNode(tagName, block));
|
1781
|
+
mrows.push(new mathMLTree.MathNode("mrow", block));
|
1807
1782
|
}
|
1808
1783
|
mrows.push(node);
|
1809
1784
|
block = [];
|
1810
1785
|
const mtd = new mathMLTree.MathNode("mtd", mrows);
|
1786
|
+
mtd.style.textAlign = "left";
|
1811
1787
|
mtrs.push(new mathMLTree.MathNode("mtr", [mtd]));
|
1812
1788
|
mrows = [];
|
1789
|
+
i += 1;
|
1813
1790
|
continue
|
1814
1791
|
}
|
1815
1792
|
block.push(node);
|
1816
|
-
if (node.type && node.type === "mo" &&
|
1817
|
-
if (
|
1793
|
+
if (node.type && node.type === "mo" && node.children.length === 1) {
|
1794
|
+
if (wrapMode === "=" && node.children[0].text === "=") {
|
1818
1795
|
numTopLevelEquals += 1;
|
1819
1796
|
if (numTopLevelEquals > 1) {
|
1820
1797
|
block.pop();
|
1821
1798
|
// Start a new block. (Insert a soft linebreak.)
|
1822
|
-
const element = new mathMLTree.MathNode(
|
1823
|
-
if (color) { element.setAttribute("mathcolor", color); }
|
1799
|
+
const element = new mathMLTree.MathNode("mrow", block);
|
1824
1800
|
mrows.push(element);
|
1825
1801
|
block = [node];
|
1826
1802
|
}
|
1827
|
-
}
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
)
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
const nd = expression[j];
|
1846
|
-
if (
|
1847
|
-
nd.type &&
|
1848
|
-
nd.type === "mspace" &&
|
1849
|
-
!(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
|
1850
|
-
) {
|
1851
|
-
block.push(nd);
|
1852
|
-
i += 1;
|
1803
|
+
} else if (wrapMode === "tex") {
|
1804
|
+
// This may be a place for a soft line break.
|
1805
|
+
if (canBeBIN && !node.attributes.form) {
|
1806
|
+
// Check if the following node is a \nobreak text node, e.g. "~""
|
1807
|
+
const next = i < expression.length - 1 ? expression[i + 1] : null;
|
1808
|
+
let glueIsFreeOfNobreak = true;
|
1809
|
+
if (
|
1810
|
+
!(
|
1811
|
+
next &&
|
1812
|
+
next.type === "mtext" &&
|
1813
|
+
next.attributes.linebreak &&
|
1814
|
+
next.attributes.linebreak === "nobreak"
|
1815
|
+
)
|
1816
|
+
) {
|
1817
|
+
// We may need to start a new block.
|
1818
|
+
// First, put any post-operator glue on same line as operator.
|
1819
|
+
for (let j = i + 1; j < expression.length; j++) {
|
1820
|
+
const nd = expression[j];
|
1853
1821
|
if (
|
1854
|
-
nd.
|
1855
|
-
nd.
|
1856
|
-
nd.attributes.linebreak === "
|
1822
|
+
nd.type &&
|
1823
|
+
nd.type === "mspace" &&
|
1824
|
+
!(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
|
1857
1825
|
) {
|
1858
|
-
|
1826
|
+
block.push(nd);
|
1827
|
+
i += 1;
|
1828
|
+
if (
|
1829
|
+
nd.attributes &&
|
1830
|
+
nd.attributes.linebreak &&
|
1831
|
+
nd.attributes.linebreak === "nobreak"
|
1832
|
+
) {
|
1833
|
+
glueIsFreeOfNobreak = false;
|
1834
|
+
}
|
1835
|
+
} else {
|
1836
|
+
break;
|
1859
1837
|
}
|
1860
|
-
} else {
|
1861
|
-
break;
|
1862
1838
|
}
|
1863
1839
|
}
|
1840
|
+
if (glueIsFreeOfNobreak) {
|
1841
|
+
// Start a new block. (Insert a soft linebreak.)
|
1842
|
+
const element = new mathMLTree.MathNode("mrow", block);
|
1843
|
+
mrows.push(element);
|
1844
|
+
block = [];
|
1845
|
+
}
|
1846
|
+
canBeBIN = false;
|
1864
1847
|
}
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
block = [];
|
1871
|
-
}
|
1872
|
-
canBeBIN = false;
|
1848
|
+
const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix";
|
1849
|
+
// Any operator that follows an open delimiter is unary.
|
1850
|
+
canBeBIN = !(node.attributes.separator || isOpenDelimiter);
|
1851
|
+
} else {
|
1852
|
+
canBeBIN = true;
|
1873
1853
|
}
|
1874
|
-
const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix";
|
1875
|
-
// Any operator that follows an open delimiter is unary.
|
1876
|
-
canBeBIN = !(node.attributes.separator || isOpenDelimiter);
|
1877
1854
|
} else {
|
1878
1855
|
canBeBIN = true;
|
1879
1856
|
}
|
1857
|
+
i += 1;
|
1880
1858
|
}
|
1881
1859
|
if (block.length > 0) {
|
1882
|
-
const element = new mathMLTree.MathNode(
|
1883
|
-
if (color) { element.setAttribute("mathcolor", color); }
|
1860
|
+
const element = new mathMLTree.MathNode("mrow", block);
|
1884
1861
|
mrows.push(element);
|
1885
1862
|
}
|
1886
1863
|
if (mtrs.length > 0) {
|
@@ -3083,11 +3060,15 @@ var temml = (function () {
|
|
3083
3060
|
};
|
3084
3061
|
|
3085
3062
|
const mathmlBuilder$9 = (group, style) => {
|
3086
|
-
|
3087
|
-
//
|
3088
|
-
|
3089
|
-
|
3090
|
-
|
3063
|
+
// In LaTeX, color is not supposed to change the spacing of any node.
|
3064
|
+
// So instead of wrapping the group in an <mstyle>, we apply
|
3065
|
+
// the color individually to each node and return a document fragment.
|
3066
|
+
let expr = buildExpression(group.body, style.withColor(group.color));
|
3067
|
+
expr = expr.map(e => {
|
3068
|
+
e.style.color = group.color;
|
3069
|
+
return e
|
3070
|
+
});
|
3071
|
+
return mathMLTree.newDocumentFragment(expr)
|
3091
3072
|
};
|
3092
3073
|
|
3093
3074
|
defineFunction({
|
@@ -11098,7 +11079,7 @@ var temml = (function () {
|
|
11098
11079
|
* https://mit-license.org/
|
11099
11080
|
*/
|
11100
11081
|
|
11101
|
-
const version = "0.10.
|
11082
|
+
const version = "0.10.5";
|
11102
11083
|
|
11103
11084
|
function postProcess(block) {
|
11104
11085
|
const labelMap = {};
|