temml 0.10.10 → 0.10.13

Sign up to get free protection for your applications and to get access to all the features.
package/dist/temml.mjs CHANGED
@@ -186,6 +186,7 @@ class Settings {
186
186
  this.displayMode = utils.deflt(options.displayMode, false); // boolean
187
187
  this.annotate = utils.deflt(options.annotate, false); // boolean
188
188
  this.leqno = utils.deflt(options.leqno, false); // boolean
189
+ this.throwOnError = utils.deflt(options.throwOnError, false); // boolean
189
190
  this.errorColor = utils.deflt(options.errorColor, "#b22222"); // string
190
191
  this.macros = options.macros || {};
191
192
  this.wrap = utils.deflt(options.wrap, "tex"); // "tex" | "="
@@ -863,6 +864,9 @@ defineSymbol(math, rel, "\u225e", "\\measeq", true);
863
864
  defineSymbol(math, rel, "\u225f", "\\questeq", true);
864
865
  defineSymbol(math, rel, "\u2260", "\\ne", true);
865
866
  defineSymbol(math, rel, "\u2260", "\\neq");
867
+ // unicodemath
868
+ defineSymbol(math, rel, "\u2a75", "\\eqeq", true);
869
+ defineSymbol(math, rel, "\u2a76", "\\eqeqeq", true);
866
870
  // mathtools.sty
867
871
  defineSymbol(math, rel, "\u2237", "\\dblcolon", true);
868
872
  defineSymbol(math, rel, "\u2254", "\\coloneqq", true);
@@ -964,6 +968,7 @@ defineSymbol(math, rel, "\u21c1", "\\rightharpoondown", true);
964
968
  defineSymbol(math, rel, "\u2196", "\\nwarrow", true);
965
969
  defineSymbol(math, rel, "\u21cc", "\\rightleftharpoons", true);
966
970
  defineSymbol(math, mathord, "\u21af", "\\lightning", true);
971
+ defineSymbol(math, mathord, "\u220E", "\\QED", true);
967
972
  defineSymbol(math, mathord, "\u2030", "\\permil", true);
968
973
  defineSymbol(text, textord, "\u2030", "\\permil");
969
974
 
@@ -2128,7 +2133,7 @@ function buildMathML(tree, texExpression, style, settings) {
2128
2133
  math.setAttribute("display", "block");
2129
2134
  math.style.display = math.children.length === 1 && math.children[0].type === "mtable"
2130
2135
  ? "inline"
2131
- : "inline-block";
2136
+ : "block math";
2132
2137
  }
2133
2138
  return math;
2134
2139
  }
@@ -2412,43 +2417,69 @@ const paddedNode = (group, lspace = 0.3, rspace = 0) => {
2412
2417
  return new mathMLTree.MathNode("mrow", row)
2413
2418
  };
2414
2419
 
2415
- const labelSize = (size, scriptLevel) => (size / emScale(scriptLevel)).toFixed(4);
2420
+ const labelSize = (size, scriptLevel) => Number(size) / emScale(scriptLevel);
2416
2421
 
2417
- const munderoverNode = (name, body, below, style) => {
2418
- const arrowNode = stretchy.mathMLnode(name);
2422
+ const munderoverNode = (fName, body, below, style) => {
2423
+ const arrowNode = stretchy.mathMLnode(fName);
2419
2424
  // Is this the short part of a mhchem equilibrium arrow?
2420
- const isEq = name.slice(1, 3) === "eq";
2421
- const minWidth = name.charAt(1) === "x"
2422
- ? "1.75" // mathtools extensible arrows are 1.75em long
2423
- : name.slice(2, 4) === "cd"
2425
+ const isEq = fName.slice(1, 3) === "eq";
2426
+ const minWidth = fName.charAt(1) === "x"
2427
+ ? "1.75" // mathtools extensible arrows are 1.75em long
2428
+ : fName.slice(2, 4) === "cd"
2424
2429
  ? "3.0" // cd package arrows
2425
2430
  : isEq
2426
2431
  ? "1.0" // The shorter harpoon of a mhchem equilibrium arrow
2427
2432
  : "2.0"; // other mhchem arrows
2428
- arrowNode.setAttribute("minsize", String(minWidth) + "em");
2433
+ // TODO: When Firefox supports minsize, use the next line.
2434
+ //arrowNode.setAttribute("minsize", String(minWidth) + "em")
2429
2435
  arrowNode.setAttribute("lspace", "0");
2430
2436
  arrowNode.setAttribute("rspace", (isEq ? "0.5em" : "0"));
2431
2437
 
2432
2438
  // <munderover> upper and lower labels are set to scriptlevel by MathML
2433
- // So we have to adjust our dimensions accordingly.
2439
+ // So we have to adjust our label dimensions accordingly.
2434
2440
  const labelStyle = style.withLevel(style.level < 2 ? 2 : 3);
2435
- const emptyLabelWidth = labelSize(minWidth, labelStyle.level);
2436
- const lspace = labelSize((isEq ? 0 : 0.3), labelStyle.level);
2437
- const rspace = labelSize((isEq ? 0 : 0.3), labelStyle.level);
2438
-
2439
- const upperNode = (body && body.body &&
2441
+ const minArrowWidth = labelSize(minWidth, labelStyle.level);
2442
+ // The dummyNode will be inside a <mover> inside a <mover>
2443
+ // So it will be at scriptlevel 3
2444
+ const dummyWidth = labelSize(minWidth, 3);
2445
+ const emptyLabel = paddedNode(null, minArrowWidth.toFixed(4), 0);
2446
+ const dummyNode = paddedNode(null, dummyWidth.toFixed(4), 0);
2447
+ // The arrow is a little longer than the label. Set a spacer length.
2448
+ const space = labelSize((isEq ? 0 : 0.3), labelStyle.level).toFixed(4);
2449
+ let upperNode;
2450
+ let lowerNode;
2451
+
2452
+ const gotUpper = (body && body.body &&
2440
2453
  // \hphantom visible content
2441
- (body.body.body || body.body.length > 0))
2442
- ? paddedNode(buildGroup$1(body, labelStyle), lspace, rspace)
2443
- // Since Firefox does not recognize minsize set on the arrow,
2444
- // create an upper node w/correct width.
2445
- : paddedNode(null, emptyLabelWidth, 0);
2446
- const lowerNode = (below && below.body &&
2447
- (below.body.body || below.body.length > 0))
2448
- ? paddedNode(buildGroup$1(below, labelStyle), lspace, rspace)
2449
- : paddedNode(null, emptyLabelWidth, 0);
2450
- const node = new mathMLTree.MathNode("munderover", [arrowNode, lowerNode, upperNode]);
2451
- if (minWidth === "3.0") { node.style.height = "1em"; }
2454
+ (body.body.body || body.body.length > 0));
2455
+ if (gotUpper) {
2456
+ let label = buildGroup$1(body, labelStyle);
2457
+ label = paddedNode(label, space, space);
2458
+ // Since Firefox does not support minsize, stack a invisible node
2459
+ // on top of the label. Its width will serve as a min-width.
2460
+ // TODO: Refactor this after Firefox supports minsize.
2461
+ upperNode = new mathMLTree.MathNode("mover", [label, dummyNode]);
2462
+ }
2463
+ const gotLower = (below && below.body &&
2464
+ (below.body.body || below.body.length > 0));
2465
+ if (gotLower) {
2466
+ let label = buildGroup$1(below, labelStyle);
2467
+ label = paddedNode(label, space, space);
2468
+ lowerNode = new mathMLTree.MathNode("munder", [label, dummyNode]);
2469
+ }
2470
+
2471
+ let node;
2472
+ if (!gotUpper && !gotLower) {
2473
+ node = new mathMLTree.MathNode("mover", [arrowNode, emptyLabel]);
2474
+ } else if (gotUpper && gotLower) {
2475
+ node = new mathMLTree.MathNode("munderover", [arrowNode, lowerNode, upperNode]);
2476
+ } else if (gotUpper) {
2477
+ node = new mathMLTree.MathNode("mover", [arrowNode, upperNode]);
2478
+ } else {
2479
+ node = new mathMLTree.MathNode("munder", [arrowNode, lowerNode]);
2480
+ }
2481
+ if (minWidth === "3.0") { node.style.height = "1em"; } // CD environment
2482
+ node.setAttribute("accent", "false"); // Necessary for MS Word
2452
2483
  return node
2453
2484
  };
2454
2485
 
@@ -2527,7 +2558,7 @@ defineFunction({
2527
2558
  "\\xleftrightharpoons", // mathtools
2528
2559
  "\\xrightleftharpoons", // mathtools
2529
2560
  "\\yieldsLeftRight", // mhchem
2530
- "\\equilibrium", // mhchem
2561
+ "\\equilibrium", // mhchem
2531
2562
  "\\equilibriumRight",
2532
2563
  "\\equilibriumLeft"
2533
2564
  ],
@@ -5999,7 +6030,9 @@ defineFunction({
5999
6030
  const arr = (body.body) ? body.body : [body];
6000
6031
  for (const arg of arr) {
6001
6032
  if (textAtomTypes.includes(arg.type)) {
6002
- if (arg.text) {
6033
+ if (symbols[parser.mode][arg.text]) {
6034
+ mord.text += symbols[parser.mode][arg.text].replace;
6035
+ } else if (arg.text) {
6003
6036
  mord.text += arg.text;
6004
6037
  } else if (arg.body) {
6005
6038
  arg.body.map(e => { mord.text += e.text; });
@@ -7746,6 +7779,8 @@ defineFunctionBuilders({
7746
7779
  node = new mathMLTree.MathNode("mi", [text]);
7747
7780
  if (text.text === origText && latinRegEx.test(origText)) {
7748
7781
  node.setAttribute("mathvariant", "italic");
7782
+ } else if (text.text === "∇" && variant === "normal") {
7783
+ node.setAttribute("mathvariant", "normal");
7749
7784
  }
7750
7785
  }
7751
7786
  return node
@@ -12867,7 +12902,7 @@ class Style {
12867
12902
  * https://mit-license.org/
12868
12903
  */
12869
12904
 
12870
- const version = "0.10.10";
12905
+ const version = "0.10.13";
12871
12906
 
12872
12907
  function postProcess(block) {
12873
12908
  const labelMap = {};
@@ -14,7 +14,7 @@
14
14
  * https://mit-license.org/
15
15
  */
16
16
 
17
- const version = "0.10.10";
17
+ const version = "0.10.13";
18
18
 
19
19
  function postProcess(block) {
20
20
  const labelMap = {};
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "temml",
3
- "version": "0.10.10",
3
+ "version": "0.10.13",
4
4
  "description": "TeX to MathML conversion in JavaScript.",
5
5
  "main": "dist/temml.js",
6
+ "engines": {
7
+ "node": ">=18.13.0"
8
+ },
6
9
  "exports": {
7
10
  ".": {
8
11
  "require": "./dist/temml.cjs"
@@ -23,7 +26,7 @@
23
26
  ],
24
27
  "license": "MIT",
25
28
  "devDependencies": {
26
- "eslint": "^8.7.0",
29
+ "eslint": "^8.39.0",
27
30
  "esm": "^3.2.25",
28
31
  "rollup": "^2.66.1",
29
32
  "terser": "^5.14.2"
package/src/Settings.js CHANGED
@@ -15,6 +15,7 @@ export default class Settings {
15
15
  this.displayMode = utils.deflt(options.displayMode, false); // boolean
16
16
  this.annotate = utils.deflt(options.annotate, false) // boolean
17
17
  this.leqno = utils.deflt(options.leqno, false); // boolean
18
+ this.throwOnError = utils.deflt(options.throwOnError, false); // boolean
18
19
  this.errorColor = utils.deflt(options.errorColor, "#b22222"); // string
19
20
  this.macros = options.macros || {};
20
21
  this.wrap = utils.deflt(options.wrap, "tex") // "tex" | "="
@@ -262,7 +262,7 @@ export default function buildMathML(tree, texExpression, style, settings) {
262
262
  math.setAttribute("display", "block");
263
263
  math.style.display = math.children.length === 1 && math.children[0].type === "mtable"
264
264
  ? "inline"
265
- : "inline-block"
265
+ : "block math"
266
266
  }
267
267
  return math;
268
268
  }
@@ -18,45 +18,71 @@ const paddedNode = (group, lspace = 0.3, rspace = 0) => {
18
18
  if (lspace !== 0) { row.unshift(padding(lspace)) }
19
19
  if (rspace > 0) { row.push(padding(rspace)) }
20
20
  return new mathMLTree.MathNode("mrow", row)
21
- };
21
+ }
22
22
 
23
- const labelSize = (size, scriptLevel) => (size / emScale(scriptLevel)).toFixed(4)
23
+ const labelSize = (size, scriptLevel) => Number(size) / emScale(scriptLevel);
24
24
 
25
- const munderoverNode = (name, body, below, style) => {
26
- const arrowNode = stretchy.mathMLnode(name);
25
+ const munderoverNode = (fName, body, below, style) => {
26
+ const arrowNode = stretchy.mathMLnode(fName);
27
27
  // Is this the short part of a mhchem equilibrium arrow?
28
- const isEq = name.slice(1, 3) === "eq"
29
- const minWidth = name.charAt(1) === "x"
30
- ? "1.75" // mathtools extensible arrows are 1.75em long
31
- : name.slice(2, 4) === "cd"
28
+ const isEq = fName.slice(1, 3) === "eq"
29
+ const minWidth = fName.charAt(1) === "x"
30
+ ? "1.75" // mathtools extensible arrows are 1.75em long
31
+ : fName.slice(2, 4) === "cd"
32
32
  ? "3.0" // cd package arrows
33
33
  : isEq
34
34
  ? "1.0" // The shorter harpoon of a mhchem equilibrium arrow
35
35
  : "2.0"; // other mhchem arrows
36
- arrowNode.setAttribute("minsize", String(minWidth) + "em");
36
+ // TODO: When Firefox supports minsize, use the next line.
37
+ //arrowNode.setAttribute("minsize", String(minWidth) + "em")
37
38
  arrowNode.setAttribute("lspace", "0")
38
39
  arrowNode.setAttribute("rspace", (isEq ? "0.5em" : "0"))
39
40
 
40
41
  // <munderover> upper and lower labels are set to scriptlevel by MathML
41
- // So we have to adjust our dimensions accordingly.
42
+ // So we have to adjust our label dimensions accordingly.
42
43
  const labelStyle = style.withLevel(style.level < 2 ? 2 : 3)
43
- const emptyLabelWidth = labelSize(minWidth, labelStyle.level)
44
- const lspace = labelSize((isEq ? 0 : 0.3), labelStyle.level)
45
- const rspace = labelSize((isEq ? 0 : 0.3), labelStyle.level)
44
+ const minArrowWidth = labelSize(minWidth, labelStyle.level)
45
+ // The dummyNode will be inside a <mover> inside a <mover>
46
+ // So it will be at scriptlevel 3
47
+ const dummyWidth = labelSize(minWidth, 3)
48
+ const emptyLabel = paddedNode(null, minArrowWidth.toFixed(4), 0)
49
+ const dummyNode = paddedNode(null, dummyWidth.toFixed(4), 0)
50
+ // The arrow is a little longer than the label. Set a spacer length.
51
+ const space = labelSize((isEq ? 0 : 0.3), labelStyle.level).toFixed(4)
52
+ let upperNode
53
+ let lowerNode
46
54
 
47
- const upperNode = (body && body.body &&
55
+ const gotUpper = (body && body.body &&
48
56
  // \hphantom visible content
49
57
  (body.body.body || body.body.length > 0))
50
- ? paddedNode(mml.buildGroup(body, labelStyle), lspace, rspace)
51
- // Since Firefox does not recognize minsize set on the arrow,
52
- // create an upper node w/correct width.
53
- : paddedNode(null, emptyLabelWidth, 0)
54
- const lowerNode = (below && below.body &&
58
+ if (gotUpper) {
59
+ let label = mml.buildGroup(body, labelStyle)
60
+ label = paddedNode(label, space, space)
61
+ // Since Firefox does not support minsize, stack a invisible node
62
+ // on top of the label. Its width will serve as a min-width.
63
+ // TODO: Refactor this after Firefox supports minsize.
64
+ upperNode = new mathMLTree.MathNode("mover", [label, dummyNode])
65
+ }
66
+ const gotLower = (below && below.body &&
55
67
  (below.body.body || below.body.length > 0))
56
- ? paddedNode(mml.buildGroup(below, labelStyle), lspace, rspace)
57
- : paddedNode(null, emptyLabelWidth, 0)
58
- const node = new mathMLTree.MathNode("munderover", [arrowNode, lowerNode, upperNode]);
59
- if (minWidth === "3.0") { node.style.height = "1em" }
68
+ if (gotLower) {
69
+ let label = mml.buildGroup(below, labelStyle)
70
+ label = paddedNode(label, space, space)
71
+ lowerNode = new mathMLTree.MathNode("munder", [label, dummyNode])
72
+ }
73
+
74
+ let node
75
+ if (!gotUpper && !gotLower) {
76
+ node = new mathMLTree.MathNode("mover", [arrowNode, emptyLabel])
77
+ } else if (gotUpper && gotLower) {
78
+ node = new mathMLTree.MathNode("munderover", [arrowNode, lowerNode, upperNode])
79
+ } else if (gotUpper) {
80
+ node = new mathMLTree.MathNode("mover", [arrowNode, upperNode])
81
+ } else {
82
+ node = new mathMLTree.MathNode("munder", [arrowNode, lowerNode])
83
+ }
84
+ if (minWidth === "3.0") { node.style.height = "1em" } // CD environment
85
+ node.setAttribute("accent", "false") // Necessary for MS Word
60
86
  return node
61
87
  }
62
88
 
@@ -135,7 +161,7 @@ defineFunction({
135
161
  "\\xleftrightharpoons", // mathtools
136
162
  "\\xrightleftharpoons", // mathtools
137
163
  "\\yieldsLeftRight", // mhchem
138
- "\\equilibrium", // mhchem
164
+ "\\equilibrium", // mhchem
139
165
  "\\equilibriumRight",
140
166
  "\\equilibriumLeft"
141
167
  ],
@@ -1,4 +1,5 @@
1
1
  import defineFunction, { ordargument } from "../defineFunction";
2
+ import symbols from "../symbols";
2
3
  import mathMLTree from "../mathMLTree";
3
4
  import utils from "../utils";
4
5
 
@@ -112,7 +113,9 @@ defineFunction({
112
113
  const arr = (body.body) ? body.body : [body];
113
114
  for (const arg of arr) {
114
115
  if (textAtomTypes.includes(arg.type)) {
115
- if (arg.text) {
116
+ if (symbols[parser.mode][arg.text]) {
117
+ mord.text += symbols[parser.mode][arg.text].replace
118
+ } else if (arg.text) {
116
119
  mord.text += arg.text
117
120
  } else if (arg.body) {
118
121
  arg.body.map(e => { mord.text += e.text })
@@ -88,6 +88,8 @@ defineFunctionBuilders({
88
88
  node = new mathMLTree.MathNode("mi", [text])
89
89
  if (text.text === origText && latinRegEx.test(origText)) {
90
90
  node.setAttribute("mathvariant", "italic")
91
+ } else if (text.text === "∇" && variant === "normal") {
92
+ node.setAttribute("mathvariant", "normal")
91
93
  }
92
94
  }
93
95
  return node
@@ -8,7 +8,7 @@
8
8
  * https://mit-license.org/
9
9
  */
10
10
 
11
- export const version = "0.10.10";
11
+ export const version = "0.10.13";
12
12
 
13
13
  export function postProcess(block) {
14
14
  const labelMap = {}
package/src/symbols.js CHANGED
@@ -105,6 +105,9 @@ defineSymbol(math, rel, "\u225e", "\\measeq", true);
105
105
  defineSymbol(math, rel, "\u225f", "\\questeq", true);
106
106
  defineSymbol(math, rel, "\u2260", "\\ne", true);
107
107
  defineSymbol(math, rel, "\u2260", "\\neq");
108
+ // unicodemath
109
+ defineSymbol(math, rel, "\u2a75", "\\eqeq", true);
110
+ defineSymbol(math, rel, "\u2a76", "\\eqeqeq", true);
108
111
  // mathtools.sty
109
112
  defineSymbol(math, rel, "\u2237", "\\dblcolon", true);
110
113
  defineSymbol(math, rel, "\u2254", "\\coloneqq", true);
@@ -206,6 +209,7 @@ defineSymbol(math, rel, "\u21c1", "\\rightharpoondown", true);
206
209
  defineSymbol(math, rel, "\u2196", "\\nwarrow", true);
207
210
  defineSymbol(math, rel, "\u21cc", "\\rightleftharpoons", true);
208
211
  defineSymbol(math, mathord, "\u21af", "\\lightning", true);
212
+ defineSymbol(math, mathord, "\u220E", "\\QED", true);
209
213
  defineSymbol(math, mathord, "\u2030", "\\permil", true);
210
214
  defineSymbol(text, textord, "\u2030", "\\permil");
211
215