temml 0.10.29 → 0.10.31
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -2
- package/dist/temml.cjs +18 -6
- package/dist/temml.js +18 -6
- package/dist/temml.min.js +1 -1
- package/dist/temml.mjs +18 -6
- package/dist/temmlPostProcess.js +1 -1
- package/package.json +5 -5
- package/src/Parser.js +1 -0
- package/src/functions/color.js +2 -0
- package/src/functions/delimsizing.js +14 -5
- package/src/postProcess.js +1 -1
package/dist/temml.mjs
CHANGED
@@ -3389,6 +3389,7 @@ defineFunction({
|
|
3389
3389
|
type: "color",
|
3390
3390
|
mode: parser.mode,
|
3391
3391
|
color,
|
3392
|
+
isTextColor: true,
|
3392
3393
|
body: ordargument(body)
|
3393
3394
|
}
|
3394
3395
|
},
|
@@ -3421,6 +3422,7 @@ defineFunction({
|
|
3421
3422
|
type: "color",
|
3422
3423
|
mode: parser.mode,
|
3423
3424
|
color,
|
3425
|
+
isTextColor: false,
|
3424
3426
|
body
|
3425
3427
|
}
|
3426
3428
|
},
|
@@ -3864,10 +3866,8 @@ function checkDelimiter(delim, context) {
|
|
3864
3866
|
if (symDelim && delimiters.includes(symDelim.text)) {
|
3865
3867
|
// If a character is not in the MathML operator dictionary, it will not stretch.
|
3866
3868
|
// Replace such characters w/characters that will stretch.
|
3867
|
-
if (["/", "\u2044"].includes(symDelim.text)) { symDelim.text = "\u2215"; }
|
3868
3869
|
if (["<", "\\lt"].includes(symDelim.text)) { symDelim.text = "⟨"; }
|
3869
3870
|
if ([">", "\\gt"].includes(symDelim.text)) { symDelim.text = "⟩"; }
|
3870
|
-
if (symDelim.text === "\\backslash") { symDelim.text = "\u2216"; }
|
3871
3871
|
return symDelim;
|
3872
3872
|
} else if (symDelim) {
|
3873
3873
|
throw new ParseError(`Invalid delimiter '${symDelim.text}' after '${context.funcName}'`, delim);
|
@@ -3876,6 +3876,9 @@ function checkDelimiter(delim, context) {
|
|
3876
3876
|
}
|
3877
3877
|
}
|
3878
3878
|
|
3879
|
+
// / \
|
3880
|
+
const needExplicitStretch = ["\u002F", "\u005C", "\\backslash", "\\vert", "|"];
|
3881
|
+
|
3879
3882
|
defineFunction({
|
3880
3883
|
type: "delimsizing",
|
3881
3884
|
names: [
|
@@ -3928,8 +3931,7 @@ defineFunction({
|
|
3928
3931
|
// defaults.
|
3929
3932
|
node.setAttribute("fence", "false");
|
3930
3933
|
}
|
3931
|
-
if (group.delim
|
3932
|
-
group.delim === "|" || group.delim.indexOf("arrow") > -1) {
|
3934
|
+
if (needExplicitStretch.includes(group.delim) || group.delim.indexOf("arrow") > -1) {
|
3933
3935
|
// We have to explicitly set stretchy to true.
|
3934
3936
|
node.setAttribute("stretchy", "true");
|
3935
3937
|
}
|
@@ -4015,7 +4017,7 @@ defineFunction({
|
|
4015
4017
|
const leftNode = new mathMLTree.MathNode("mo", [makeText(group.left, group.mode)]);
|
4016
4018
|
leftNode.setAttribute("fence", "true");
|
4017
4019
|
leftNode.setAttribute("form", "prefix");
|
4018
|
-
if (group.left === "\
|
4020
|
+
if (group.left === "/" || group.left === "\u005C" || group.left.indexOf("arrow") > -1) {
|
4019
4021
|
leftNode.setAttribute("stretchy", "true");
|
4020
4022
|
}
|
4021
4023
|
inner.unshift(leftNode);
|
@@ -4027,6 +4029,15 @@ defineFunction({
|
|
4027
4029
|
if (group.right === "\u2216" || group.right.indexOf("arrow") > -1) {
|
4028
4030
|
rightNode.setAttribute("stretchy", "true");
|
4029
4031
|
}
|
4032
|
+
if (group.body.length > 0) {
|
4033
|
+
const lastElement = group.body[group.body.length - 1];
|
4034
|
+
if (lastElement.type === "color" && !lastElement.isTextColor) {
|
4035
|
+
// \color is a switch. If the last element is of type "color" then
|
4036
|
+
// the user set the \color switch and left it on.
|
4037
|
+
// A \right delimiter turns the switch off, but the delimiter itself gets the color.
|
4038
|
+
rightNode.setAttribute("mathcolor", lastElement.color);
|
4039
|
+
}
|
4040
|
+
}
|
4030
4041
|
inner.push(rightNode);
|
4031
4042
|
|
4032
4043
|
return makeRow(inner);
|
@@ -12492,6 +12503,7 @@ class Parser {
|
|
12492
12503
|
*/
|
12493
12504
|
parseExpression(breakOnInfix, breakOnTokenText, breakOnMiddle) {
|
12494
12505
|
const body = [];
|
12506
|
+
this.prevAtomType = "";
|
12495
12507
|
// Keep adding atoms to the body until we can't parse any more atoms (either
|
12496
12508
|
// we reached the end, a }, or a \right)
|
12497
12509
|
while (true) {
|
@@ -13489,7 +13501,7 @@ class Style {
|
|
13489
13501
|
* https://mit-license.org/
|
13490
13502
|
*/
|
13491
13503
|
|
13492
|
-
const version = "0.10.
|
13504
|
+
const version = "0.10.31";
|
13493
13505
|
|
13494
13506
|
function postProcess(block) {
|
13495
13507
|
const labelMap = {};
|
package/dist/temmlPostProcess.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "temml",
|
3
|
-
"version": "0.10.
|
3
|
+
"version": "0.10.31",
|
4
4
|
"description": "TeX to MathML conversion in JavaScript.",
|
5
5
|
"main": "dist/temml.js",
|
6
6
|
"engines": {
|
@@ -29,12 +29,12 @@
|
|
29
29
|
"license": "MIT",
|
30
30
|
"devDependencies": {
|
31
31
|
"@eslint/eslintrc": "^3.1.0",
|
32
|
-
"@eslint/js": "^9.
|
33
|
-
"eslint": "^9.
|
32
|
+
"@eslint/js": "^9.11.1",
|
33
|
+
"eslint": "^9.11.1",
|
34
34
|
"esm": "^3.2.25",
|
35
35
|
"globals": "^15.9.0",
|
36
|
-
"rollup": "^4.
|
37
|
-
"terser": "^5.
|
36
|
+
"rollup": "^4.22.4",
|
37
|
+
"terser": "^5.34.0"
|
38
38
|
},
|
39
39
|
"scripts": {
|
40
40
|
"lint": "eslint temml.js src",
|
package/src/Parser.js
CHANGED
@@ -187,6 +187,7 @@ export default class Parser {
|
|
187
187
|
*/
|
188
188
|
parseExpression(breakOnInfix, breakOnTokenText, breakOnMiddle) {
|
189
189
|
const body = [];
|
190
|
+
this.prevAtomType = ""
|
190
191
|
// Keep adding atoms to the body until we can't parse any more atoms (either
|
191
192
|
// we reached the end, a }, or a \right)
|
192
193
|
while (true) {
|
package/src/functions/color.js
CHANGED
@@ -186,6 +186,7 @@ defineFunction({
|
|
186
186
|
type: "color",
|
187
187
|
mode: parser.mode,
|
188
188
|
color,
|
189
|
+
isTextColor: true,
|
189
190
|
body: ordargument(body)
|
190
191
|
}
|
191
192
|
},
|
@@ -218,6 +219,7 @@ defineFunction({
|
|
218
219
|
type: "color",
|
219
220
|
mode: parser.mode,
|
220
221
|
color,
|
222
|
+
isTextColor: false,
|
221
223
|
body
|
222
224
|
}
|
223
225
|
},
|
@@ -118,10 +118,8 @@ function checkDelimiter(delim, context) {
|
|
118
118
|
if (symDelim && delimiters.includes(symDelim.text)) {
|
119
119
|
// If a character is not in the MathML operator dictionary, it will not stretch.
|
120
120
|
// Replace such characters w/characters that will stretch.
|
121
|
-
if (["/", "\u2044"].includes(symDelim.text)) { symDelim.text = "\u2215" }
|
122
121
|
if (["<", "\\lt"].includes(symDelim.text)) { symDelim.text = "⟨" }
|
123
122
|
if ([">", "\\gt"].includes(symDelim.text)) { symDelim.text = "⟩" }
|
124
|
-
if (symDelim.text === "\\backslash") { symDelim.text = "\u2216" }
|
125
123
|
return symDelim;
|
126
124
|
} else if (symDelim) {
|
127
125
|
throw new ParseError(`Invalid delimiter '${symDelim.text}' after '${context.funcName}'`, delim);
|
@@ -130,6 +128,9 @@ function checkDelimiter(delim, context) {
|
|
130
128
|
}
|
131
129
|
}
|
132
130
|
|
131
|
+
// / \
|
132
|
+
const needExplicitStretch = ["\u002F", "\u005C", "\\backslash", "\\vert", "|"];
|
133
|
+
|
133
134
|
defineFunction({
|
134
135
|
type: "delimsizing",
|
135
136
|
names: [
|
@@ -182,8 +183,7 @@ defineFunction({
|
|
182
183
|
// defaults.
|
183
184
|
node.setAttribute("fence", "false");
|
184
185
|
}
|
185
|
-
if (group.delim
|
186
|
-
group.delim === "|" || group.delim.indexOf("arrow") > -1) {
|
186
|
+
if (needExplicitStretch.includes(group.delim) || group.delim.indexOf("arrow") > -1) {
|
187
187
|
// We have to explicitly set stretchy to true.
|
188
188
|
node.setAttribute("stretchy", "true")
|
189
189
|
}
|
@@ -269,7 +269,7 @@ defineFunction({
|
|
269
269
|
const leftNode = new mathMLTree.MathNode("mo", [mml.makeText(group.left, group.mode)]);
|
270
270
|
leftNode.setAttribute("fence", "true")
|
271
271
|
leftNode.setAttribute("form", "prefix")
|
272
|
-
if (group.left === "\
|
272
|
+
if (group.left === "/" || group.left === "\u005C" || group.left.indexOf("arrow") > -1) {
|
273
273
|
leftNode.setAttribute("stretchy", "true")
|
274
274
|
}
|
275
275
|
inner.unshift(leftNode)
|
@@ -281,6 +281,15 @@ defineFunction({
|
|
281
281
|
if (group.right === "\u2216" || group.right.indexOf("arrow") > -1) {
|
282
282
|
rightNode.setAttribute("stretchy", "true")
|
283
283
|
}
|
284
|
+
if (group.body.length > 0) {
|
285
|
+
const lastElement = group.body[group.body.length - 1];
|
286
|
+
if (lastElement.type === "color" && !lastElement.isTextColor) {
|
287
|
+
// \color is a switch. If the last element is of type "color" then
|
288
|
+
// the user set the \color switch and left it on.
|
289
|
+
// A \right delimiter turns the switch off, but the delimiter itself gets the color.
|
290
|
+
rightNode.setAttribute("mathcolor", lastElement.color);
|
291
|
+
}
|
292
|
+
}
|
284
293
|
inner.push(rightNode)
|
285
294
|
|
286
295
|
return mml.makeRow(inner);
|