temml 0.10.13 → 0.10.14

Sign up to get free protection for your applications and to get access to all the features.
package/dist/temml.js CHANGED
@@ -1118,6 +1118,7 @@ var temml = (function () {
1118
1118
  defineSymbol(math, rel, "\u22b2", "\\vartriangleleft");
1119
1119
  defineSymbol(math, rel, "\u22b4", "\\trianglelefteq");
1120
1120
  defineSymbol(math, rel, "\u22a8", "\\vDash", true);
1121
+ defineSymbol(math, rel, "\u22ab", "\\VDash", true);
1121
1122
  defineSymbol(math, rel, "\u22aa", "\\Vvdash", true);
1122
1123
  defineSymbol(math, rel, "\u2323", "\\smallsmile");
1123
1124
  defineSymbol(math, rel, "\u2322", "\\smallfrown");
@@ -1767,13 +1768,16 @@ var temml = (function () {
1767
1768
  * much of this module.
1768
1769
  */
1769
1770
 
1771
+ const openDelims = "([{⌊⌈⟨⟮⎰⟦⦃";
1772
+ const closeDelims = ")]}⌋⌉⟩⟯⎱⟦⦄";
1773
+
1770
1774
  function setLineBreaks(expression, wrapMode, isDisplayMode) {
1771
1775
  const mtrs = [];
1772
1776
  let mrows = [];
1773
1777
  let block = [];
1774
1778
  let numTopLevelEquals = 0;
1775
- let canBeBIN = false; // The first node cannot be an infix binary operator.
1776
1779
  let i = 0;
1780
+ let level = 0;
1777
1781
  while (i < expression.length) {
1778
1782
  while (expression[i] instanceof DocumentFragment) {
1779
1783
  expression.splice(i, 1, ...expression[i].children); // Expand the fragment.
@@ -1796,7 +1800,12 @@ var temml = (function () {
1796
1800
  }
1797
1801
  block.push(node);
1798
1802
  if (node.type && node.type === "mo" && node.children.length === 1) {
1799
- 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 === "=") {
1800
1809
  numTopLevelEquals += 1;
1801
1810
  if (numTopLevelEquals > 1) {
1802
1811
  block.pop();
@@ -1805,59 +1814,48 @@ var temml = (function () {
1805
1814
  mrows.push(element);
1806
1815
  block = [node];
1807
1816
  }
1808
- } else if (wrapMode === "tex") {
1809
- // This may be a place for a soft line break.
1810
- if (canBeBIN && !node.attributes.form) {
1811
- // Check if the following node is a \nobreak text node, e.g. "~""
1812
- const next = i < expression.length - 1 ? expression[i + 1] : null;
1813
- let glueIsFreeOfNobreak = true;
1814
- if (
1815
- !(
1816
- next &&
1817
- next.type === "mtext" &&
1818
- next.attributes.linebreak &&
1819
- next.attributes.linebreak === "nobreak"
1820
- )
1821
- ) {
1822
- // We may need to start a new block.
1823
- // First, put any post-operator glue on same line as operator.
1824
- for (let j = i + 1; j < expression.length; j++) {
1825
- 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;
1826
1840
  if (
1827
- nd.type &&
1828
- nd.type === "mspace" &&
1829
- !(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
1841
+ nd.attributes &&
1842
+ nd.attributes.linebreak &&
1843
+ nd.attributes.linebreak === "nobreak"
1830
1844
  ) {
1831
- block.push(nd);
1832
- i += 1;
1833
- if (
1834
- nd.attributes &&
1835
- nd.attributes.linebreak &&
1836
- nd.attributes.linebreak === "nobreak"
1837
- ) {
1838
- glueIsFreeOfNobreak = false;
1839
- }
1840
- } else {
1841
- break;
1845
+ glueIsFreeOfNobreak = false;
1842
1846
  }
1847
+ } else {
1848
+ break;
1843
1849
  }
1844
1850
  }
1845
- if (glueIsFreeOfNobreak) {
1846
- // Start a new block. (Insert a soft linebreak.)
1847
- const element = new mathMLTree.MathNode("mrow", block);
1848
- mrows.push(element);
1849
- block = [];
1850
- }
1851
- canBeBIN = false;
1852
1851
  }
1853
- const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix";
1854
- // Any operator that follows an open delimiter is unary.
1855
- canBeBIN = !(node.attributes.separator || isOpenDelimiter);
1856
- } else {
1857
- 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
+ }
1858
1858
  }
1859
- } else {
1860
- canBeBIN = true;
1861
1859
  }
1862
1860
  i += 1;
1863
1861
  }
@@ -2136,7 +2134,10 @@ var temml = (function () {
2136
2134
  math.setAttribute("display", "block");
2137
2135
  math.style.display = math.children.length === 1 && math.children[0].type === "mtable"
2138
2136
  ? "inline"
2139
- : "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"];
2140
2141
  }
2141
2142
  return math;
2142
2143
  }
@@ -3665,10 +3666,9 @@ var temml = (function () {
3665
3666
  // so we have to explicitly set stretchy to true.
3666
3667
  node.setAttribute("stretchy", "true");
3667
3668
  }
3668
-
3669
3669
  node.setAttribute("symmetric", "true"); // Needed for tall arrows in Firefox.
3670
3670
  node.setAttribute("minsize", sizeToMaxHeight[group.size] + "em");
3671
- // Don't set the maxsize attribute. It's broken in Chromium.
3671
+ node.setAttribute("maxsize", sizeToMaxHeight[group.size] + "em");
3672
3672
  return node;
3673
3673
  }
3674
3674
  });
@@ -3803,33 +3803,31 @@ var temml = (function () {
3803
3803
 
3804
3804
  const mathmlBuilder$8 = (group, style) => {
3805
3805
  let node;
3806
- if (group.label.indexOf("colorbox") > -1) {
3807
- // Chrome mpadded +width attribute is broken. Insert <mspace>
3808
- 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", [
3809
3811
  padding$1(),
3810
3812
  buildGroup$1(group.body, style),
3811
3813
  padding$1()
3812
3814
  ]);
3813
3815
  } else {
3814
- node = new mathMLTree.MathNode("menclose", [buildGroup$1(group.body, style)]);
3816
+ node = new mathMLTree.MathNode("mrow", [buildGroup$1(group.body, style)]);
3815
3817
  }
3816
3818
  switch (group.label) {
3817
3819
  case "\\overline":
3818
- node.setAttribute("notation", "top");
3819
3820
  node.style.padding = "0.1em 0 0 0";
3820
3821
  node.style.borderTop = "0.065em solid";
3821
3822
  break
3822
3823
  case "\\underline":
3823
- node.setAttribute("notation", "bottom");
3824
3824
  node.style.padding = "0 0 0.1em 0";
3825
3825
  node.style.borderBottom = "0.065em solid";
3826
3826
  break
3827
3827
  case "\\cancel":
3828
- node.setAttribute("notation", "updiagonalstrike");
3829
3828
  node.classes.push("cancel");
3830
3829
  break
3831
3830
  case "\\bcancel":
3832
- node.setAttribute("notation", "downdiagonalstrike");
3833
3831
  node.classes.push("bcancel");
3834
3832
  break
3835
3833
  /*
@@ -3840,18 +3838,21 @@ var temml = (function () {
3840
3838
  node.setAttribute("notation", "phasorangle");
3841
3839
  break */
3842
3840
  case "\\angl":
3843
- node.setAttribute("notation", "actuarial");
3844
3841
  node.style.padding = "0.03889em 0.03889em 0 0.03889em";
3845
3842
  node.style.borderTop = "0.049em solid";
3846
3843
  node.style.borderRight = "0.049em solid";
3847
3844
  node.style.marginRight = "0.03889em";
3848
3845
  break
3849
3846
  case "\\sout":
3850
- node.setAttribute("notation", "horizontalstrike");
3851
3847
  node.style["text-decoration"] = "line-through 0.08em solid";
3852
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
3853
3855
  case "\\fbox":
3854
- node.setAttribute("notation", "box");
3855
3856
  node.style = { padding: "3pt", border: "1px solid" };
3856
3857
  break
3857
3858
  case "\\fcolorbox":
@@ -3871,7 +3872,6 @@ var temml = (function () {
3871
3872
  break
3872
3873
  }
3873
3874
  case "\\xcancel":
3874
- node.setAttribute("notation", "updiagonalstrike downdiagonalstrike");
3875
3875
  node.classes.push("xcancel");
3876
3876
  break
3877
3877
  }
@@ -3966,7 +3966,7 @@ var temml = (function () {
3966
3966
 
3967
3967
  defineFunction({
3968
3968
  type: "enclose",
3969
- names: ["\\angl", "\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\overline"],
3969
+ names: ["\\angl", "\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\overline", "\\boxed"],
3970
3970
  // , "\\phase", "\\longdiv"
3971
3971
  props: {
3972
3972
  numArgs: 1
@@ -6832,8 +6832,6 @@ var temml = (function () {
6832
6832
  }
6833
6833
  });
6834
6834
 
6835
- const sign = num => num >= 0 ? "+" : "-";
6836
-
6837
6835
  // \raise, \lower, and \raisebox
6838
6836
 
6839
6837
  const mathmlBuilder = (group, style) => {
@@ -6841,11 +6839,13 @@ var temml = (function () {
6841
6839
  const node = new mathMLTree.MathNode("mpadded", [buildGroup$1(group.body, newStyle)]);
6842
6840
  const dy = calculateSize(group.dy, style);
6843
6841
  node.setAttribute("voffset", dy.number + dy.unit);
6844
- const dyAbs = Math.abs(dy.number);
6845
- // The next two lines do not work in Chromium.
6846
- // TODO: Find some other way to adjust height and depth.
6847
- node.setAttribute("height", sign(dy.number) + dyAbs + dy.unit);
6848
- 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
+ }
6849
6849
  return node
6850
6850
  };
6851
6851
 
@@ -8474,9 +8474,6 @@ var temml = (function () {
8474
8474
  //\newcommand{\substack}[1]{\subarray{c}#1\endsubarray}
8475
8475
  defineMacro("\\substack", "\\begin{subarray}{c}#1\\end{subarray}");
8476
8476
 
8477
- // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
8478
- defineMacro("\\boxed", "\\fbox{$\\displaystyle{#1}$}");
8479
-
8480
8477
  // \def\iff{\DOTSB\;\Longleftrightarrow\;}
8481
8478
  // \def\implies{\DOTSB\;\Longrightarrow\;}
8482
8479
  // \def\impliedby{\DOTSB\;\Longleftarrow\;}
@@ -8725,7 +8722,7 @@ var temml = (function () {
8725
8722
  defineMacro(
8726
8723
  "\\Temml",
8727
8724
  // eslint-disable-next-line max-len
8728
- "\\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}}"
8729
8726
  );
8730
8727
 
8731
8728
  // \DeclareRobustCommand\hspace{\@ifstar\@hspacer\@hspace}
@@ -11005,7 +11002,7 @@ var temml = (function () {
11005
11002
  * https://mit-license.org/
11006
11003
  */
11007
11004
 
11008
- const version = "0.10.13";
11005
+ const version = "0.10.14";
11009
11006
 
11010
11007
  function postProcess(block) {
11011
11008
  const labelMap = {};