temml 0.10.12 → 0.10.13

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.mjs CHANGED
@@ -968,6 +968,7 @@ defineSymbol(math, rel, "\u21c1", "\\rightharpoondown", true);
968
968
  defineSymbol(math, rel, "\u2196", "\\nwarrow", true);
969
969
  defineSymbol(math, rel, "\u21cc", "\\rightleftharpoons", true);
970
970
  defineSymbol(math, mathord, "\u21af", "\\lightning", true);
971
+ defineSymbol(math, mathord, "\u220E", "\\QED", true);
971
972
  defineSymbol(math, mathord, "\u2030", "\\permil", true);
972
973
  defineSymbol(text, textord, "\u2030", "\\permil");
973
974
 
@@ -2416,43 +2417,69 @@ const paddedNode = (group, lspace = 0.3, rspace = 0) => {
2416
2417
  return new mathMLTree.MathNode("mrow", row)
2417
2418
  };
2418
2419
 
2419
- const labelSize = (size, scriptLevel) => (size / emScale(scriptLevel)).toFixed(4);
2420
+ const labelSize = (size, scriptLevel) => Number(size) / emScale(scriptLevel);
2420
2421
 
2421
- const munderoverNode = (name, body, below, style) => {
2422
- const arrowNode = stretchy.mathMLnode(name);
2422
+ const munderoverNode = (fName, body, below, style) => {
2423
+ const arrowNode = stretchy.mathMLnode(fName);
2423
2424
  // Is this the short part of a mhchem equilibrium arrow?
2424
- const isEq = name.slice(1, 3) === "eq";
2425
- const minWidth = name.charAt(1) === "x"
2426
- ? "1.75" // mathtools extensible arrows are 1.75em long
2427
- : 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"
2428
2429
  ? "3.0" // cd package arrows
2429
2430
  : isEq
2430
2431
  ? "1.0" // The shorter harpoon of a mhchem equilibrium arrow
2431
2432
  : "2.0"; // other mhchem arrows
2432
- arrowNode.setAttribute("minsize", String(minWidth) + "em");
2433
+ // TODO: When Firefox supports minsize, use the next line.
2434
+ //arrowNode.setAttribute("minsize", String(minWidth) + "em")
2433
2435
  arrowNode.setAttribute("lspace", "0");
2434
2436
  arrowNode.setAttribute("rspace", (isEq ? "0.5em" : "0"));
2435
2437
 
2436
2438
  // <munderover> upper and lower labels are set to scriptlevel by MathML
2437
- // So we have to adjust our dimensions accordingly.
2439
+ // So we have to adjust our label dimensions accordingly.
2438
2440
  const labelStyle = style.withLevel(style.level < 2 ? 2 : 3);
2439
- const emptyLabelWidth = labelSize(minWidth, labelStyle.level);
2440
- const lspace = labelSize((isEq ? 0 : 0.3), labelStyle.level);
2441
- const rspace = labelSize((isEq ? 0 : 0.3), labelStyle.level);
2442
-
2443
- 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 &&
2444
2453
  // \hphantom visible content
2445
- (body.body.body || body.body.length > 0))
2446
- ? paddedNode(buildGroup$1(body, labelStyle), lspace, rspace)
2447
- // Since Firefox does not recognize minsize set on the arrow,
2448
- // create an upper node w/correct width.
2449
- : paddedNode(null, emptyLabelWidth, 0);
2450
- const lowerNode = (below && below.body &&
2451
- (below.body.body || below.body.length > 0))
2452
- ? paddedNode(buildGroup$1(below, labelStyle), lspace, rspace)
2453
- : paddedNode(null, emptyLabelWidth, 0);
2454
- const node = new mathMLTree.MathNode("munderover", [arrowNode, lowerNode, upperNode]);
2455
- 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
2456
2483
  return node
2457
2484
  };
2458
2485
 
@@ -2531,7 +2558,7 @@ defineFunction({
2531
2558
  "\\xleftrightharpoons", // mathtools
2532
2559
  "\\xrightleftharpoons", // mathtools
2533
2560
  "\\yieldsLeftRight", // mhchem
2534
- "\\equilibrium", // mhchem
2561
+ "\\equilibrium", // mhchem
2535
2562
  "\\equilibriumRight",
2536
2563
  "\\equilibriumLeft"
2537
2564
  ],
@@ -12875,7 +12902,7 @@ class Style {
12875
12902
  * https://mit-license.org/
12876
12903
  */
12877
12904
 
12878
- const version = "0.10.12";
12905
+ const version = "0.10.13";
12879
12906
 
12880
12907
  function postProcess(block) {
12881
12908
  const labelMap = {};
@@ -14,7 +14,7 @@
14
14
  * https://mit-license.org/
15
15
  */
16
16
 
17
- const version = "0.10.12";
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.12",
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"
@@ -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
  ],
@@ -8,7 +8,7 @@
8
8
  * https://mit-license.org/
9
9
  */
10
10
 
11
- export const version = "0.10.12";
11
+ export const version = "0.10.13";
12
12
 
13
13
  export function postProcess(block) {
14
14
  const labelMap = {}
package/src/symbols.js CHANGED
@@ -209,6 +209,7 @@ defineSymbol(math, rel, "\u21c1", "\\rightharpoondown", true);
209
209
  defineSymbol(math, rel, "\u2196", "\\nwarrow", true);
210
210
  defineSymbol(math, rel, "\u21cc", "\\rightleftharpoons", true);
211
211
  defineSymbol(math, mathord, "\u21af", "\\lightning", true);
212
+ defineSymbol(math, mathord, "\u220E", "\\QED", true);
212
213
  defineSymbol(math, mathord, "\u2030", "\\permil", true);
213
214
  defineSymbol(text, textord, "\u2030", "\\permil");
214
215