temml 0.10.4 → 0.10.5
Sign up to get free protection for your applications and to get access to all the features.
- 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.mjs
CHANGED
@@ -1759,125 +1759,102 @@ for (let i = 0; i < 10; i++) {
|
|
1759
1759
|
* much of this module.
|
1760
1760
|
*/
|
1761
1761
|
|
1762
|
-
function setLineBreaks(expression, wrapMode, isDisplayMode
|
1763
|
-
if (color === undefined && wrapMode !== "none") {
|
1764
|
-
// First, make one pass through the expression and split any color nodes.
|
1765
|
-
const upperLimit = expression.length - 1;
|
1766
|
-
for (let i = upperLimit; i >= 0; i--) {
|
1767
|
-
const node = expression[i];
|
1768
|
-
if (node.type === "mstyle" && node.attributes.mathcolor) {
|
1769
|
-
const color = node.attributes.mathcolor;
|
1770
|
-
const fragment = setLineBreaks(node.children, wrapMode, isDisplayMode, color);
|
1771
|
-
if (!(fragment.type && fragment.type !== "mtable")) {
|
1772
|
-
expression.splice(i, 1, ...fragment.children);
|
1773
|
-
}
|
1774
|
-
}
|
1775
|
-
}
|
1776
|
-
}
|
1777
|
-
|
1778
|
-
const tagName = color ? "mstyle" : "mrow";
|
1779
|
-
|
1762
|
+
function setLineBreaks(expression, wrapMode, isDisplayMode) {
|
1780
1763
|
const mtrs = [];
|
1781
1764
|
let mrows = [];
|
1782
1765
|
let block = [];
|
1783
1766
|
let numTopLevelEquals = 0;
|
1784
1767
|
let canBeBIN = false; // The first node cannot be an infix binary operator.
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
// Start a new block. (Insert a soft linebreak.)
|
1790
|
-
mrows.push(new mathMLTree.MathNode(tagName, block));
|
1791
|
-
}
|
1792
|
-
// Insert the mstyle
|
1793
|
-
mrows.push(node);
|
1794
|
-
block = [];
|
1795
|
-
continue
|
1768
|
+
let i = 0;
|
1769
|
+
while (i < expression.length) {
|
1770
|
+
while (expression[i] instanceof DocumentFragment) {
|
1771
|
+
expression.splice(i, 1, ...expression[i].children); // Expand the fragment.
|
1796
1772
|
}
|
1773
|
+
const node = expression[i];
|
1797
1774
|
if (node.attributes && node.attributes.linebreak &&
|
1798
1775
|
node.attributes.linebreak === "newline") {
|
1799
1776
|
// A hard line break. Create a <mtr> for the current block.
|
1800
1777
|
if (block.length > 0) {
|
1801
|
-
|
1802
|
-
if (color) { element.setAttribute("mathcolor", color); }
|
1803
|
-
mrows.push(new mathMLTree.MathNode(tagName, block));
|
1778
|
+
mrows.push(new mathMLTree.MathNode("mrow", block));
|
1804
1779
|
}
|
1805
1780
|
mrows.push(node);
|
1806
1781
|
block = [];
|
1807
1782
|
const mtd = new mathMLTree.MathNode("mtd", mrows);
|
1783
|
+
mtd.style.textAlign = "left";
|
1808
1784
|
mtrs.push(new mathMLTree.MathNode("mtr", [mtd]));
|
1809
1785
|
mrows = [];
|
1786
|
+
i += 1;
|
1810
1787
|
continue
|
1811
1788
|
}
|
1812
1789
|
block.push(node);
|
1813
|
-
if (node.type && node.type === "mo" &&
|
1814
|
-
if (
|
1790
|
+
if (node.type && node.type === "mo" && node.children.length === 1) {
|
1791
|
+
if (wrapMode === "=" && node.children[0].text === "=") {
|
1815
1792
|
numTopLevelEquals += 1;
|
1816
1793
|
if (numTopLevelEquals > 1) {
|
1817
1794
|
block.pop();
|
1818
1795
|
// Start a new block. (Insert a soft linebreak.)
|
1819
|
-
const element = new mathMLTree.MathNode(
|
1820
|
-
if (color) { element.setAttribute("mathcolor", color); }
|
1796
|
+
const element = new mathMLTree.MathNode("mrow", block);
|
1821
1797
|
mrows.push(element);
|
1822
1798
|
block = [node];
|
1823
1799
|
}
|
1824
|
-
}
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
)
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
const nd = expression[j];
|
1843
|
-
if (
|
1844
|
-
nd.type &&
|
1845
|
-
nd.type === "mspace" &&
|
1846
|
-
!(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
|
1847
|
-
) {
|
1848
|
-
block.push(nd);
|
1849
|
-
i += 1;
|
1800
|
+
} else if (wrapMode === "tex") {
|
1801
|
+
// This may be a place for a soft line break.
|
1802
|
+
if (canBeBIN && !node.attributes.form) {
|
1803
|
+
// Check if the following node is a \nobreak text node, e.g. "~""
|
1804
|
+
const next = i < expression.length - 1 ? expression[i + 1] : null;
|
1805
|
+
let glueIsFreeOfNobreak = true;
|
1806
|
+
if (
|
1807
|
+
!(
|
1808
|
+
next &&
|
1809
|
+
next.type === "mtext" &&
|
1810
|
+
next.attributes.linebreak &&
|
1811
|
+
next.attributes.linebreak === "nobreak"
|
1812
|
+
)
|
1813
|
+
) {
|
1814
|
+
// We may need to start a new block.
|
1815
|
+
// First, put any post-operator glue on same line as operator.
|
1816
|
+
for (let j = i + 1; j < expression.length; j++) {
|
1817
|
+
const nd = expression[j];
|
1850
1818
|
if (
|
1851
|
-
nd.
|
1852
|
-
nd.
|
1853
|
-
nd.attributes.linebreak === "
|
1819
|
+
nd.type &&
|
1820
|
+
nd.type === "mspace" &&
|
1821
|
+
!(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
|
1854
1822
|
) {
|
1855
|
-
|
1823
|
+
block.push(nd);
|
1824
|
+
i += 1;
|
1825
|
+
if (
|
1826
|
+
nd.attributes &&
|
1827
|
+
nd.attributes.linebreak &&
|
1828
|
+
nd.attributes.linebreak === "nobreak"
|
1829
|
+
) {
|
1830
|
+
glueIsFreeOfNobreak = false;
|
1831
|
+
}
|
1832
|
+
} else {
|
1833
|
+
break;
|
1856
1834
|
}
|
1857
|
-
} else {
|
1858
|
-
break;
|
1859
1835
|
}
|
1860
1836
|
}
|
1837
|
+
if (glueIsFreeOfNobreak) {
|
1838
|
+
// Start a new block. (Insert a soft linebreak.)
|
1839
|
+
const element = new mathMLTree.MathNode("mrow", block);
|
1840
|
+
mrows.push(element);
|
1841
|
+
block = [];
|
1842
|
+
}
|
1843
|
+
canBeBIN = false;
|
1861
1844
|
}
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
block = [];
|
1868
|
-
}
|
1869
|
-
canBeBIN = false;
|
1845
|
+
const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix";
|
1846
|
+
// Any operator that follows an open delimiter is unary.
|
1847
|
+
canBeBIN = !(node.attributes.separator || isOpenDelimiter);
|
1848
|
+
} else {
|
1849
|
+
canBeBIN = true;
|
1870
1850
|
}
|
1871
|
-
const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix";
|
1872
|
-
// Any operator that follows an open delimiter is unary.
|
1873
|
-
canBeBIN = !(node.attributes.separator || isOpenDelimiter);
|
1874
1851
|
} else {
|
1875
1852
|
canBeBIN = true;
|
1876
1853
|
}
|
1854
|
+
i += 1;
|
1877
1855
|
}
|
1878
1856
|
if (block.length > 0) {
|
1879
|
-
const element = new mathMLTree.MathNode(
|
1880
|
-
if (color) { element.setAttribute("mathcolor", color); }
|
1857
|
+
const element = new mathMLTree.MathNode("mrow", block);
|
1881
1858
|
mrows.push(element);
|
1882
1859
|
}
|
1883
1860
|
if (mtrs.length > 0) {
|
@@ -3080,11 +3057,15 @@ const validateColor = (color, macros, token) => {
|
|
3080
3057
|
};
|
3081
3058
|
|
3082
3059
|
const mathmlBuilder$9 = (group, style) => {
|
3083
|
-
|
3084
|
-
//
|
3085
|
-
|
3086
|
-
|
3087
|
-
|
3060
|
+
// In LaTeX, color is not supposed to change the spacing of any node.
|
3061
|
+
// So instead of wrapping the group in an <mstyle>, we apply
|
3062
|
+
// the color individually to each node and return a document fragment.
|
3063
|
+
let expr = buildExpression(group.body, style.withColor(group.color));
|
3064
|
+
expr = expr.map(e => {
|
3065
|
+
e.style.color = group.color;
|
3066
|
+
return e
|
3067
|
+
});
|
3068
|
+
return mathMLTree.newDocumentFragment(expr)
|
3088
3069
|
};
|
3089
3070
|
|
3090
3071
|
defineFunction({
|
@@ -12995,7 +12976,7 @@ class Style {
|
|
12995
12976
|
* https://mit-license.org/
|
12996
12977
|
*/
|
12997
12978
|
|
12998
|
-
const version = "0.10.
|
12979
|
+
const version = "0.10.5";
|
12999
12980
|
|
13000
12981
|
function postProcess(block) {
|
13001
12982
|
const labelMap = {};
|
package/dist/temmlPostProcess.js
CHANGED
package/package.json
CHANGED
package/src/functions/color.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import defineFunction, { ordargument } from "../defineFunction"
|
2
|
-
import
|
2
|
+
import mathMLTree from "../mathMLTree"
|
3
3
|
import { assertNodeType } from "../parseNode"
|
4
4
|
import ParseError from "../ParseError"
|
5
5
|
import * as mml from "../buildMathML"
|
@@ -152,11 +152,15 @@ export const validateColor = (color, macros, token) => {
|
|
152
152
|
}
|
153
153
|
|
154
154
|
const mathmlBuilder = (group, style) => {
|
155
|
-
|
156
|
-
//
|
157
|
-
|
158
|
-
|
159
|
-
|
155
|
+
// In LaTeX, color is not supposed to change the spacing of any node.
|
156
|
+
// So instead of wrapping the group in an <mstyle>, we apply
|
157
|
+
// the color individually to each node and return a document fragment.
|
158
|
+
let expr = mml.buildExpression(group.body, style.withColor(group.color))
|
159
|
+
expr = expr.map(e => {
|
160
|
+
e.style.color = group.color
|
161
|
+
return e
|
162
|
+
})
|
163
|
+
return mathMLTree.newDocumentFragment(expr)
|
160
164
|
}
|
161
165
|
|
162
166
|
defineFunction({
|
package/src/linebreaking.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import mathMLTree from "./mathMLTree"
|
2
|
+
import { DocumentFragment } from "./tree"
|
2
3
|
|
3
4
|
/*
|
4
5
|
* Neither Firefox nor Chrome support hard line breaks or soft line breaks.
|
@@ -25,125 +26,102 @@ import mathMLTree from "./mathMLTree"
|
|
25
26
|
* much of this module.
|
26
27
|
*/
|
27
28
|
|
28
|
-
export default function setLineBreaks(expression, wrapMode, isDisplayMode
|
29
|
-
if (color === undefined && wrapMode !== "none") {
|
30
|
-
// First, make one pass through the expression and split any color nodes.
|
31
|
-
const upperLimit = expression.length - 1
|
32
|
-
for (let i = upperLimit; i >= 0; i--) {
|
33
|
-
const node = expression[i];
|
34
|
-
if (node.type === "mstyle" && node.attributes.mathcolor) {
|
35
|
-
const color = node.attributes.mathcolor
|
36
|
-
const fragment = setLineBreaks(node.children, wrapMode, isDisplayMode, color)
|
37
|
-
if (!(fragment.type && fragment.type !== "mtable")) {
|
38
|
-
expression.splice(i, 1, ...fragment.children)
|
39
|
-
}
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
const tagName = color ? "mstyle" : "mrow"
|
45
|
-
|
29
|
+
export default function setLineBreaks(expression, wrapMode, isDisplayMode) {
|
46
30
|
const mtrs = [];
|
47
31
|
let mrows = [];
|
48
32
|
let block = [];
|
49
33
|
let numTopLevelEquals = 0
|
50
34
|
let canBeBIN = false // The first node cannot be an infix binary operator.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
// Start a new block. (Insert a soft linebreak.)
|
56
|
-
mrows.push(new mathMLTree.MathNode(tagName, block))
|
57
|
-
}
|
58
|
-
// Insert the mstyle
|
59
|
-
mrows.push(node)
|
60
|
-
block = [];
|
61
|
-
continue
|
35
|
+
let i = 0
|
36
|
+
while (i < expression.length) {
|
37
|
+
while (expression[i] instanceof DocumentFragment) {
|
38
|
+
expression.splice(i, 1, ...expression[i].children) // Expand the fragment.
|
62
39
|
}
|
40
|
+
const node = expression[i];
|
63
41
|
if (node.attributes && node.attributes.linebreak &&
|
64
42
|
node.attributes.linebreak === "newline") {
|
65
43
|
// A hard line break. Create a <mtr> for the current block.
|
66
44
|
if (block.length > 0) {
|
67
|
-
|
68
|
-
if (color) { element.setAttribute("mathcolor", color) }
|
69
|
-
mrows.push(new mathMLTree.MathNode(tagName, block))
|
45
|
+
mrows.push(new mathMLTree.MathNode("mrow", block))
|
70
46
|
}
|
71
47
|
mrows.push(node)
|
72
48
|
block = [];
|
73
49
|
const mtd = new mathMLTree.MathNode("mtd", mrows)
|
50
|
+
mtd.style.textAlign = "left"
|
74
51
|
mtrs.push(new mathMLTree.MathNode("mtr", [mtd]))
|
75
52
|
mrows = [];
|
53
|
+
i += 1
|
76
54
|
continue
|
77
55
|
}
|
78
56
|
block.push(node);
|
79
|
-
if (node.type && node.type === "mo" &&
|
80
|
-
if (
|
57
|
+
if (node.type && node.type === "mo" && node.children.length === 1) {
|
58
|
+
if (wrapMode === "=" && node.children[0].text === "=") {
|
81
59
|
numTopLevelEquals += 1
|
82
60
|
if (numTopLevelEquals > 1) {
|
83
61
|
block.pop()
|
84
62
|
// Start a new block. (Insert a soft linebreak.)
|
85
|
-
const element = new mathMLTree.MathNode(
|
86
|
-
if (color) { element.setAttribute("mathcolor", color) }
|
63
|
+
const element = new mathMLTree.MathNode("mrow", block)
|
87
64
|
mrows.push(element)
|
88
65
|
block = [node];
|
89
66
|
}
|
90
|
-
}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
const nd = expression[j];
|
109
|
-
if (
|
110
|
-
nd.type &&
|
111
|
-
nd.type === "mspace" &&
|
112
|
-
!(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
|
113
|
-
) {
|
114
|
-
block.push(nd);
|
115
|
-
i += 1;
|
67
|
+
} else if (wrapMode === "tex") {
|
68
|
+
// This may be a place for a soft line break.
|
69
|
+
if (canBeBIN && !node.attributes.form) {
|
70
|
+
// Check if the following node is a \nobreak text node, e.g. "~""
|
71
|
+
const next = i < expression.length - 1 ? expression[i + 1] : null;
|
72
|
+
let glueIsFreeOfNobreak = true;
|
73
|
+
if (
|
74
|
+
!(
|
75
|
+
next &&
|
76
|
+
next.type === "mtext" &&
|
77
|
+
next.attributes.linebreak &&
|
78
|
+
next.attributes.linebreak === "nobreak"
|
79
|
+
)
|
80
|
+
) {
|
81
|
+
// We may need to start a new block.
|
82
|
+
// First, put any post-operator glue on same line as operator.
|
83
|
+
for (let j = i + 1; j < expression.length; j++) {
|
84
|
+
const nd = expression[j];
|
116
85
|
if (
|
117
|
-
nd.
|
118
|
-
nd.
|
119
|
-
nd.attributes.linebreak === "
|
86
|
+
nd.type &&
|
87
|
+
nd.type === "mspace" &&
|
88
|
+
!(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
|
120
89
|
) {
|
121
|
-
|
90
|
+
block.push(nd);
|
91
|
+
i += 1;
|
92
|
+
if (
|
93
|
+
nd.attributes &&
|
94
|
+
nd.attributes.linebreak &&
|
95
|
+
nd.attributes.linebreak === "nobreak"
|
96
|
+
) {
|
97
|
+
glueIsFreeOfNobreak = false;
|
98
|
+
}
|
99
|
+
} else {
|
100
|
+
break;
|
122
101
|
}
|
123
|
-
} else {
|
124
|
-
break;
|
125
102
|
}
|
126
103
|
}
|
104
|
+
if (glueIsFreeOfNobreak) {
|
105
|
+
// Start a new block. (Insert a soft linebreak.)
|
106
|
+
const element = new mathMLTree.MathNode("mrow", block)
|
107
|
+
mrows.push(element)
|
108
|
+
block = [];
|
109
|
+
}
|
110
|
+
canBeBIN = false
|
127
111
|
}
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
block = [];
|
134
|
-
}
|
135
|
-
canBeBIN = false;
|
112
|
+
const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix"
|
113
|
+
// Any operator that follows an open delimiter is unary.
|
114
|
+
canBeBIN = !(node.attributes.separator || isOpenDelimiter);
|
115
|
+
} else {
|
116
|
+
canBeBIN = true
|
136
117
|
}
|
137
|
-
const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix";
|
138
|
-
// Any operator that follows an open delimiter is unary.
|
139
|
-
canBeBIN = !(node.attributes.separator || isOpenDelimiter);
|
140
118
|
} else {
|
141
|
-
canBeBIN = true
|
119
|
+
canBeBIN = true
|
142
120
|
}
|
121
|
+
i += 1
|
143
122
|
}
|
144
123
|
if (block.length > 0) {
|
145
|
-
const element = new mathMLTree.MathNode(
|
146
|
-
if (color) { element.setAttribute("mathcolor", color) }
|
124
|
+
const element = new mathMLTree.MathNode("mrow", block)
|
147
125
|
mrows.push(element)
|
148
126
|
}
|
149
127
|
if (mtrs.length > 0) {
|