temml 0.10.12 → 0.10.14

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.js CHANGED
@@ -971,6 +971,7 @@ var temml = (function () {
971
971
  defineSymbol(math, rel, "\u2196", "\\nwarrow", true);
972
972
  defineSymbol(math, rel, "\u21cc", "\\rightleftharpoons", true);
973
973
  defineSymbol(math, mathord, "\u21af", "\\lightning", true);
974
+ defineSymbol(math, mathord, "\u220E", "\\QED", true);
974
975
  defineSymbol(math, mathord, "\u2030", "\\permil", true);
975
976
  defineSymbol(text, textord, "\u2030", "\\permil");
976
977
 
@@ -1117,6 +1118,7 @@ var temml = (function () {
1117
1118
  defineSymbol(math, rel, "\u22b2", "\\vartriangleleft");
1118
1119
  defineSymbol(math, rel, "\u22b4", "\\trianglelefteq");
1119
1120
  defineSymbol(math, rel, "\u22a8", "\\vDash", true);
1121
+ defineSymbol(math, rel, "\u22ab", "\\VDash", true);
1120
1122
  defineSymbol(math, rel, "\u22aa", "\\Vvdash", true);
1121
1123
  defineSymbol(math, rel, "\u2323", "\\smallsmile");
1122
1124
  defineSymbol(math, rel, "\u2322", "\\smallfrown");
@@ -1766,13 +1768,16 @@ var temml = (function () {
1766
1768
  * much of this module.
1767
1769
  */
1768
1770
 
1771
+ const openDelims = "([{⌊⌈⟨⟮⎰⟦⦃";
1772
+ const closeDelims = ")]}⌋⌉⟩⟯⎱⟦⦄";
1773
+
1769
1774
  function setLineBreaks(expression, wrapMode, isDisplayMode) {
1770
1775
  const mtrs = [];
1771
1776
  let mrows = [];
1772
1777
  let block = [];
1773
1778
  let numTopLevelEquals = 0;
1774
- let canBeBIN = false; // The first node cannot be an infix binary operator.
1775
1779
  let i = 0;
1780
+ let level = 0;
1776
1781
  while (i < expression.length) {
1777
1782
  while (expression[i] instanceof DocumentFragment) {
1778
1783
  expression.splice(i, 1, ...expression[i].children); // Expand the fragment.
@@ -1795,7 +1800,12 @@ var temml = (function () {
1795
1800
  }
1796
1801
  block.push(node);
1797
1802
  if (node.type && node.type === "mo" && node.children.length === 1) {
1798
- if (wrapMode === "=" && node.children[0].text === "=") {
1803
+ const ch = node.children[0].text;
1804
+ if (openDelims.indexOf(ch) > -1) {
1805
+ level += 1;
1806
+ } else if (closeDelims.indexOf(ch) > -1) {
1807
+ level -= 1;
1808
+ } else if (level === 0 && wrapMode === "=" && ch === "=") {
1799
1809
  numTopLevelEquals += 1;
1800
1810
  if (numTopLevelEquals > 1) {
1801
1811
  block.pop();
@@ -1804,59 +1814,48 @@ var temml = (function () {
1804
1814
  mrows.push(element);
1805
1815
  block = [node];
1806
1816
  }
1807
- } else if (wrapMode === "tex") {
1808
- // This may be a place for a soft line break.
1809
- if (canBeBIN && !node.attributes.form) {
1810
- // Check if the following node is a \nobreak text node, e.g. "~""
1811
- const next = i < expression.length - 1 ? expression[i + 1] : null;
1812
- let glueIsFreeOfNobreak = true;
1813
- if (
1814
- !(
1815
- next &&
1816
- next.type === "mtext" &&
1817
- next.attributes.linebreak &&
1818
- next.attributes.linebreak === "nobreak"
1819
- )
1820
- ) {
1821
- // We may need to start a new block.
1822
- // First, put any post-operator glue on same line as operator.
1823
- for (let j = i + 1; j < expression.length; j++) {
1824
- const nd = expression[j];
1817
+ } else if (level === 0 && wrapMode === "tex") {
1818
+ // Check if the following node is a \nobreak text node, e.g. "~""
1819
+ const next = i < expression.length - 1 ? expression[i + 1] : null;
1820
+ let glueIsFreeOfNobreak = true;
1821
+ if (
1822
+ !(
1823
+ next &&
1824
+ next.type === "mtext" &&
1825
+ next.attributes.linebreak &&
1826
+ next.attributes.linebreak === "nobreak"
1827
+ )
1828
+ ) {
1829
+ // We may need to start a new block.
1830
+ // First, put any post-operator glue on same line as operator.
1831
+ for (let j = i + 1; j < expression.length; j++) {
1832
+ const nd = expression[j];
1833
+ if (
1834
+ nd.type &&
1835
+ nd.type === "mspace" &&
1836
+ !(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
1837
+ ) {
1838
+ block.push(nd);
1839
+ i += 1;
1825
1840
  if (
1826
- nd.type &&
1827
- nd.type === "mspace" &&
1828
- !(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
1841
+ nd.attributes &&
1842
+ nd.attributes.linebreak &&
1843
+ nd.attributes.linebreak === "nobreak"
1829
1844
  ) {
1830
- block.push(nd);
1831
- i += 1;
1832
- if (
1833
- nd.attributes &&
1834
- nd.attributes.linebreak &&
1835
- nd.attributes.linebreak === "nobreak"
1836
- ) {
1837
- glueIsFreeOfNobreak = false;
1838
- }
1839
- } else {
1840
- break;
1845
+ glueIsFreeOfNobreak = false;
1841
1846
  }
1847
+ } else {
1848
+ break;
1842
1849
  }
1843
1850
  }
1844
- if (glueIsFreeOfNobreak) {
1845
- // Start a new block. (Insert a soft linebreak.)
1846
- const element = new mathMLTree.MathNode("mrow", block);
1847
- mrows.push(element);
1848
- block = [];
1849
- }
1850
- canBeBIN = false;
1851
1851
  }
1852
- const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix";
1853
- // Any operator that follows an open delimiter is unary.
1854
- canBeBIN = !(node.attributes.separator || isOpenDelimiter);
1855
- } else {
1856
- canBeBIN = true;
1852
+ if (glueIsFreeOfNobreak) {
1853
+ // Start a new block. (Insert a soft linebreak.)
1854
+ const element = new mathMLTree.MathNode("mrow", block);
1855
+ mrows.push(element);
1856
+ block = [];
1857
+ }
1857
1858
  }
1858
- } else {
1859
- canBeBIN = true;
1860
1859
  }
1861
1860
  i += 1;
1862
1861
  }
@@ -2135,7 +2134,10 @@ var temml = (function () {
2135
2134
  math.setAttribute("display", "block");
2136
2135
  math.style.display = math.children.length === 1 && math.children[0].type === "mtable"
2137
2136
  ? "inline"
2138
- : "block math";
2137
+ : "block math"; // necessary in Chromium.
2138
+ // Firefox and Safari do not recognize display: "block math".
2139
+ // Set a class so that the CSS file can set display: block.
2140
+ math.classes = ["tml-display"];
2139
2141
  }
2140
2142
  return math;
2141
2143
  }
@@ -2419,43 +2421,69 @@ var temml = (function () {
2419
2421
  return new mathMLTree.MathNode("mrow", row)
2420
2422
  };
2421
2423
 
2422
- const labelSize = (size, scriptLevel) => (size / emScale(scriptLevel)).toFixed(4);
2424
+ const labelSize = (size, scriptLevel) => Number(size) / emScale(scriptLevel);
2423
2425
 
2424
- const munderoverNode = (name, body, below, style) => {
2425
- const arrowNode = stretchy.mathMLnode(name);
2426
+ const munderoverNode = (fName, body, below, style) => {
2427
+ const arrowNode = stretchy.mathMLnode(fName);
2426
2428
  // Is this the short part of a mhchem equilibrium arrow?
2427
- const isEq = name.slice(1, 3) === "eq";
2428
- const minWidth = name.charAt(1) === "x"
2429
- ? "1.75" // mathtools extensible arrows are 1.75em long
2430
- : name.slice(2, 4) === "cd"
2429
+ const isEq = fName.slice(1, 3) === "eq";
2430
+ const minWidth = fName.charAt(1) === "x"
2431
+ ? "1.75" // mathtools extensible arrows are 1.75em long
2432
+ : fName.slice(2, 4) === "cd"
2431
2433
  ? "3.0" // cd package arrows
2432
2434
  : isEq
2433
2435
  ? "1.0" // The shorter harpoon of a mhchem equilibrium arrow
2434
2436
  : "2.0"; // other mhchem arrows
2435
- arrowNode.setAttribute("minsize", String(minWidth) + "em");
2437
+ // TODO: When Firefox supports minsize, use the next line.
2438
+ //arrowNode.setAttribute("minsize", String(minWidth) + "em")
2436
2439
  arrowNode.setAttribute("lspace", "0");
2437
2440
  arrowNode.setAttribute("rspace", (isEq ? "0.5em" : "0"));
2438
2441
 
2439
2442
  // <munderover> upper and lower labels are set to scriptlevel by MathML
2440
- // So we have to adjust our dimensions accordingly.
2443
+ // So we have to adjust our label dimensions accordingly.
2441
2444
  const labelStyle = style.withLevel(style.level < 2 ? 2 : 3);
2442
- const emptyLabelWidth = labelSize(minWidth, labelStyle.level);
2443
- const lspace = labelSize((isEq ? 0 : 0.3), labelStyle.level);
2444
- const rspace = labelSize((isEq ? 0 : 0.3), labelStyle.level);
2445
-
2446
- const upperNode = (body && body.body &&
2445
+ const minArrowWidth = labelSize(minWidth, labelStyle.level);
2446
+ // The dummyNode will be inside a <mover> inside a <mover>
2447
+ // So it will be at scriptlevel 3
2448
+ const dummyWidth = labelSize(minWidth, 3);
2449
+ const emptyLabel = paddedNode(null, minArrowWidth.toFixed(4), 0);
2450
+ const dummyNode = paddedNode(null, dummyWidth.toFixed(4), 0);
2451
+ // The arrow is a little longer than the label. Set a spacer length.
2452
+ const space = labelSize((isEq ? 0 : 0.3), labelStyle.level).toFixed(4);
2453
+ let upperNode;
2454
+ let lowerNode;
2455
+
2456
+ const gotUpper = (body && body.body &&
2447
2457
  // \hphantom visible content
2448
- (body.body.body || body.body.length > 0))
2449
- ? paddedNode(buildGroup$1(body, labelStyle), lspace, rspace)
2450
- // Since Firefox does not recognize minsize set on the arrow,
2451
- // create an upper node w/correct width.
2452
- : paddedNode(null, emptyLabelWidth, 0);
2453
- const lowerNode = (below && below.body &&
2454
- (below.body.body || below.body.length > 0))
2455
- ? paddedNode(buildGroup$1(below, labelStyle), lspace, rspace)
2456
- : paddedNode(null, emptyLabelWidth, 0);
2457
- const node = new mathMLTree.MathNode("munderover", [arrowNode, lowerNode, upperNode]);
2458
- if (minWidth === "3.0") { node.style.height = "1em"; }
2458
+ (body.body.body || body.body.length > 0));
2459
+ if (gotUpper) {
2460
+ let label = buildGroup$1(body, labelStyle);
2461
+ label = paddedNode(label, space, space);
2462
+ // Since Firefox does not support minsize, stack a invisible node
2463
+ // on top of the label. Its width will serve as a min-width.
2464
+ // TODO: Refactor this after Firefox supports minsize.
2465
+ upperNode = new mathMLTree.MathNode("mover", [label, dummyNode]);
2466
+ }
2467
+ const gotLower = (below && below.body &&
2468
+ (below.body.body || below.body.length > 0));
2469
+ if (gotLower) {
2470
+ let label = buildGroup$1(below, labelStyle);
2471
+ label = paddedNode(label, space, space);
2472
+ lowerNode = new mathMLTree.MathNode("munder", [label, dummyNode]);
2473
+ }
2474
+
2475
+ let node;
2476
+ if (!gotUpper && !gotLower) {
2477
+ node = new mathMLTree.MathNode("mover", [arrowNode, emptyLabel]);
2478
+ } else if (gotUpper && gotLower) {
2479
+ node = new mathMLTree.MathNode("munderover", [arrowNode, lowerNode, upperNode]);
2480
+ } else if (gotUpper) {
2481
+ node = new mathMLTree.MathNode("mover", [arrowNode, upperNode]);
2482
+ } else {
2483
+ node = new mathMLTree.MathNode("munder", [arrowNode, lowerNode]);
2484
+ }
2485
+ if (minWidth === "3.0") { node.style.height = "1em"; } // CD environment
2486
+ node.setAttribute("accent", "false"); // Necessary for MS Word
2459
2487
  return node
2460
2488
  };
2461
2489
 
@@ -2534,7 +2562,7 @@ var temml = (function () {
2534
2562
  "\\xleftrightharpoons", // mathtools
2535
2563
  "\\xrightleftharpoons", // mathtools
2536
2564
  "\\yieldsLeftRight", // mhchem
2537
- "\\equilibrium", // mhchem
2565
+ "\\equilibrium", // mhchem
2538
2566
  "\\equilibriumRight",
2539
2567
  "\\equilibriumLeft"
2540
2568
  ],
@@ -3638,10 +3666,9 @@ var temml = (function () {
3638
3666
  // so we have to explicitly set stretchy to true.
3639
3667
  node.setAttribute("stretchy", "true");
3640
3668
  }
3641
-
3642
3669
  node.setAttribute("symmetric", "true"); // Needed for tall arrows in Firefox.
3643
3670
  node.setAttribute("minsize", sizeToMaxHeight[group.size] + "em");
3644
- // Don't set the maxsize attribute. It's broken in Chromium.
3671
+ node.setAttribute("maxsize", sizeToMaxHeight[group.size] + "em");
3645
3672
  return node;
3646
3673
  }
3647
3674
  });
@@ -3776,33 +3803,31 @@ var temml = (function () {
3776
3803
 
3777
3804
  const mathmlBuilder$8 = (group, style) => {
3778
3805
  let node;
3779
- if (group.label.indexOf("colorbox") > -1) {
3780
- // Chrome mpadded +width attribute is broken. Insert <mspace>
3781
- node = new mathMLTree.MathNode("mpadded", [
3806
+ if (group.label.indexOf("colorbox") > -1 || group.label === "\\boxed") {
3807
+ // MathML core does not support +width attribute in <mpadded>.
3808
+ // Firefox does not reliably add side padding.
3809
+ // Insert <mspace>
3810
+ node = new mathMLTree.MathNode("mrow", [
3782
3811
  padding$1(),
3783
3812
  buildGroup$1(group.body, style),
3784
3813
  padding$1()
3785
3814
  ]);
3786
3815
  } else {
3787
- node = new mathMLTree.MathNode("menclose", [buildGroup$1(group.body, style)]);
3816
+ node = new mathMLTree.MathNode("mrow", [buildGroup$1(group.body, style)]);
3788
3817
  }
3789
3818
  switch (group.label) {
3790
3819
  case "\\overline":
3791
- node.setAttribute("notation", "top");
3792
3820
  node.style.padding = "0.1em 0 0 0";
3793
3821
  node.style.borderTop = "0.065em solid";
3794
3822
  break
3795
3823
  case "\\underline":
3796
- node.setAttribute("notation", "bottom");
3797
3824
  node.style.padding = "0 0 0.1em 0";
3798
3825
  node.style.borderBottom = "0.065em solid";
3799
3826
  break
3800
3827
  case "\\cancel":
3801
- node.setAttribute("notation", "updiagonalstrike");
3802
3828
  node.classes.push("cancel");
3803
3829
  break
3804
3830
  case "\\bcancel":
3805
- node.setAttribute("notation", "downdiagonalstrike");
3806
3831
  node.classes.push("bcancel");
3807
3832
  break
3808
3833
  /*
@@ -3813,18 +3838,21 @@ var temml = (function () {
3813
3838
  node.setAttribute("notation", "phasorangle");
3814
3839
  break */
3815
3840
  case "\\angl":
3816
- node.setAttribute("notation", "actuarial");
3817
3841
  node.style.padding = "0.03889em 0.03889em 0 0.03889em";
3818
3842
  node.style.borderTop = "0.049em solid";
3819
3843
  node.style.borderRight = "0.049em solid";
3820
3844
  node.style.marginRight = "0.03889em";
3821
3845
  break
3822
3846
  case "\\sout":
3823
- node.setAttribute("notation", "horizontalstrike");
3824
3847
  node.style["text-decoration"] = "line-through 0.08em solid";
3825
3848
  break
3849
+ case "\\boxed":
3850
+ // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}} from amsmath.sty
3851
+ node.style = { padding: "3pt 0 3pt 0", border: "1px solid" };
3852
+ node.setAttribute("scriptlevel", "0");
3853
+ node.setAttribute("displaystyle", "true");
3854
+ break
3826
3855
  case "\\fbox":
3827
- node.setAttribute("notation", "box");
3828
3856
  node.style = { padding: "3pt", border: "1px solid" };
3829
3857
  break
3830
3858
  case "\\fcolorbox":
@@ -3844,7 +3872,6 @@ var temml = (function () {
3844
3872
  break
3845
3873
  }
3846
3874
  case "\\xcancel":
3847
- node.setAttribute("notation", "updiagonalstrike downdiagonalstrike");
3848
3875
  node.classes.push("xcancel");
3849
3876
  break
3850
3877
  }
@@ -3939,7 +3966,7 @@ var temml = (function () {
3939
3966
 
3940
3967
  defineFunction({
3941
3968
  type: "enclose",
3942
- names: ["\\angl", "\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\overline"],
3969
+ names: ["\\angl", "\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\overline", "\\boxed"],
3943
3970
  // , "\\phase", "\\longdiv"
3944
3971
  props: {
3945
3972
  numArgs: 1
@@ -6805,8 +6832,6 @@ var temml = (function () {
6805
6832
  }
6806
6833
  });
6807
6834
 
6808
- const sign = num => num >= 0 ? "+" : "-";
6809
-
6810
6835
  // \raise, \lower, and \raisebox
6811
6836
 
6812
6837
  const mathmlBuilder = (group, style) => {
@@ -6814,11 +6839,13 @@ var temml = (function () {
6814
6839
  const node = new mathMLTree.MathNode("mpadded", [buildGroup$1(group.body, newStyle)]);
6815
6840
  const dy = calculateSize(group.dy, style);
6816
6841
  node.setAttribute("voffset", dy.number + dy.unit);
6817
- const dyAbs = Math.abs(dy.number);
6818
- // The next two lines do not work in Chromium.
6819
- // TODO: Find some other way to adjust height and depth.
6820
- node.setAttribute("height", sign(dy.number) + dyAbs + dy.unit);
6821
- node.setAttribute("depth", sign(-dy.number) + dyAbs + dy.unit);
6842
+ // Add padding, which acts to increase height in Chromium.
6843
+ // TODO: Figure out some way to change height in Firefox w/o breaking Chromium.
6844
+ if (dy.number > 0) {
6845
+ node.style.padding = dy.number + dy.unit + " 0 0 0";
6846
+ } else {
6847
+ node.style.padding = "0 0 " + Math.abs(dy.number) + dy.unit + " 0";
6848
+ }
6822
6849
  return node
6823
6850
  };
6824
6851
 
@@ -8447,9 +8474,6 @@ var temml = (function () {
8447
8474
  //\newcommand{\substack}[1]{\subarray{c}#1\endsubarray}
8448
8475
  defineMacro("\\substack", "\\begin{subarray}{c}#1\\end{subarray}");
8449
8476
 
8450
- // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
8451
- defineMacro("\\boxed", "\\fbox{$\\displaystyle{#1}$}");
8452
-
8453
8477
  // \def\iff{\DOTSB\;\Longleftrightarrow\;}
8454
8478
  // \def\implies{\DOTSB\;\Longrightarrow\;}
8455
8479
  // \def\impliedby{\DOTSB\;\Longleftarrow\;}
@@ -8698,7 +8722,7 @@ var temml = (function () {
8698
8722
  defineMacro(
8699
8723
  "\\Temml",
8700
8724
  // eslint-disable-next-line max-len
8701
- "\\textrm{T}\\kern-0.2em\\lower{0.2em}\\textrm{E}\\kern-0.08em{\\textrm{M}\\kern-0.08em\\raise{0.2em}\\textrm{M}\\kern-0.08em\\textrm{L}}"
8725
+ "\\textrm{T}\\kern-0.2em\\lower{0.2em}{\\textrm{E}}\\kern-0.08em{\\textrm{M}\\kern-0.08em\\raise{0.2em}\\textrm{M}\\kern-0.08em\\textrm{L}}"
8702
8726
  );
8703
8727
 
8704
8728
  // \DeclareRobustCommand\hspace{\@ifstar\@hspacer\@hspace}
@@ -10978,7 +11002,7 @@ var temml = (function () {
10978
11002
  * https://mit-license.org/
10979
11003
  */
10980
11004
 
10981
- const version = "0.10.12";
11005
+ const version = "0.10.14";
10982
11006
 
10983
11007
  function postProcess(block) {
10984
11008
  const labelMap = {};