temml 0.11.9 → 0.11.11

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
@@ -2406,13 +2406,12 @@ var temml = (function () {
2406
2406
 
2407
2407
  const taggedExpression = (expression, tag, style, leqno) => {
2408
2408
  tag = buildExpressionRow(tag[0].body, style);
2409
- tag = consolidateText(tag);
2410
- tag.classes.push("tml-tag");
2409
+ tag = consolidateText(tag); // tag is now an <mtext> element
2410
+ tag.classes.push("tml-tag"); // to be available for \ref
2411
2411
 
2412
2412
  const label = getLabel(expression); // from a \label{} function.
2413
2413
  expression = new mathMLTree.MathNode("mtd", [expression]);
2414
2414
  const rowArray = [glue$1(), expression, glue$1()];
2415
- rowArray[leqno ? 0 : 2].classes.push(leqno ? "tml-left" : "tml-right");
2416
2415
  rowArray[leqno ? 0 : 2].children.push(tag);
2417
2416
  const mtr = new mathMLTree.MathNode("mtr", rowArray, ["tml-tageqn"]);
2418
2417
  if (label) { mtr.setAttribute("id", label); }
@@ -2809,21 +2808,21 @@ var temml = (function () {
2809
2808
 
2810
2809
  // Helper functions
2811
2810
 
2812
- const padding$1 = width => {
2811
+ const padding = width => {
2813
2812
  const node = new mathMLTree.MathNode("mspace");
2814
2813
  node.setAttribute("width", width + "em");
2815
2814
  return node
2816
2815
  };
2817
2816
 
2818
2817
  const paddedNode = (group, lspace = 0.3, rspace = 0, mustSmash = false) => {
2819
- if (group == null && rspace === 0) { return padding$1(lspace) }
2818
+ if (group == null && rspace === 0) { return padding(lspace) }
2820
2819
  const row = group ? [group] : [];
2821
- if (lspace !== 0) { row.unshift(padding$1(lspace)); }
2822
- if (rspace > 0) { row.push(padding$1(rspace)); }
2820
+ if (lspace !== 0) { row.unshift(padding(lspace)); }
2821
+ if (rspace > 0) { row.push(padding(rspace)); }
2823
2822
  if (mustSmash) {
2824
2823
  // Used for the bottom arrow in a {CD} environment
2825
2824
  const mpadded = new mathMLTree.MathNode("mpadded", row);
2826
- mpadded.setAttribute("height", "0");
2825
+ mpadded.setAttribute("height", "0.1px"); // Don't use 0. WebKit would hide it.
2827
2826
  return mpadded
2828
2827
  } else {
2829
2828
  return new mathMLTree.MathNode("mrow", row)
@@ -2951,8 +2950,8 @@ var temml = (function () {
2951
2950
  const node = munderoverNode(group.name, group.body, group.below, style);
2952
2951
  // Create operator spacing for a relation.
2953
2952
  const row = [node];
2954
- row.unshift(padding$1(0.2778));
2955
- row.push(padding$1(0.2778));
2953
+ row.unshift(padding(0.2778));
2954
+ row.push(padding(0.2778));
2956
2955
  return new mathMLTree.MathNode("mrow", row)
2957
2956
  }
2958
2957
  });
@@ -3016,13 +3015,13 @@ var temml = (function () {
3016
3015
  botNode.setAttribute("width", "0.5em");
3017
3016
  wrapper = new mathMLTree.MathNode(
3018
3017
  "mpadded",
3019
- [padding$1(0.2778), botNode, raiseNode, padding$1(0.2778)]
3018
+ [padding(0.2778), botNode, raiseNode, padding(0.2778)]
3020
3019
  );
3021
3020
  } else {
3022
3021
  raiseNode.setAttribute("width", (group.name === "\\equilibriumRight" ? "0.5em" : "0"));
3023
3022
  wrapper = new mathMLTree.MathNode(
3024
3023
  "mpadded",
3025
- [padding$1(0.2778), raiseNode, botArrow, padding$1(0.2778)]
3024
+ [padding(0.2778), raiseNode, botArrow, padding(0.2778)]
3026
3025
  );
3027
3026
  }
3028
3027
 
@@ -3315,19 +3314,19 @@ var temml = (function () {
3315
3314
  return new mathMLTree.MathNode("mrow", style) // empty label
3316
3315
  }
3317
3316
  // Abuse an <mtable> to create vertically centered content.
3318
- const mtd = new mathMLTree.MathNode("mtd", [buildGroup$1(group.label, style)]);
3317
+ const mrow = buildGroup$1(group.label, style);
3318
+ if (group.side === "left") {
3319
+ mrow.classes.push("tml-shift-left");
3320
+ }
3321
+ const mtd = new mathMLTree.MathNode("mtd", [mrow]);
3319
3322
  mtd.style.padding = "0";
3320
3323
  const mtr = new mathMLTree.MathNode("mtr", [mtd]);
3321
3324
  const mtable = new mathMLTree.MathNode("mtable", [mtr]);
3322
3325
  const label = new mathMLTree.MathNode("mpadded", [mtable]);
3323
3326
  // Set the label width to zero so that the arrow will be centered under the corner cell.
3324
- label.setAttribute("width", "0");
3327
+ label.setAttribute("width", "0.1px"); // Don't use 0. WebKit would hide it.
3325
3328
  label.setAttribute("displaystyle", "false");
3326
3329
  label.setAttribute("scriptlevel", "1");
3327
- if (group.side === "left") {
3328
- label.style.display = "flex";
3329
- label.style.justifyContent = "flex-end";
3330
- }
3331
3330
  return label;
3332
3331
  }
3333
3332
  });
@@ -4561,7 +4560,6 @@ var temml = (function () {
4561
4560
 
4562
4561
  if (group.envClasses.includes("multline")) {
4563
4562
  const align = i === 0 ? "left" : i === numRows - 1 ? "right" : "center";
4564
- mtd.setAttribute("columnalign", align);
4565
4563
  if (align !== "center") {
4566
4564
  mtd.classes.push("tml-" + align);
4567
4565
  }
@@ -4591,10 +4589,8 @@ var temml = (function () {
4591
4589
  row.push(glue(group));
4592
4590
  if (group.leqno) {
4593
4591
  row[0].children.push(tagElement);
4594
- row[0].classes.push("tml-left");
4595
4592
  } else {
4596
4593
  row[row.length - 1].children.push(tagElement);
4597
- row[row.length - 1].classes.push("tml-right");
4598
4594
  }
4599
4595
  }
4600
4596
  }
@@ -4635,8 +4631,10 @@ var temml = (function () {
4635
4631
  }
4636
4632
  }
4637
4633
  if (mustSquashRow) {
4638
- // All the cell contents are \hphantom. Squash the padding.
4634
+ // All the cell contents are \hphantom. Squash the cell.
4639
4635
  for (let j = 0; j < mtr.children.length; j++) {
4636
+ mtr.children[j].style.display = "block"; // necessary in Firefox only
4637
+ mtr.children[j].style.height = "0"; // necessary in Firefox only
4640
4638
  mtr.children[j].style.paddingTop = "0";
4641
4639
  mtr.children[j].style.paddingBottom = "0";
4642
4640
  }
@@ -4723,7 +4721,7 @@ var temml = (function () {
4723
4721
  }
4724
4722
  if (group.autoTag) {
4725
4723
  const k = group.leqno ? 0 : row.children.length - 1;
4726
- row.children[k].classes = ["tml-" + (group.leqno ? "left" : "right")];
4724
+ row.children[k].classes = []; // Default is center.
4727
4725
  }
4728
4726
  }
4729
4727
  if (row.children.length > 1 && group.envClasses.includes("cases")) {
@@ -4754,7 +4752,6 @@ var temml = (function () {
4754
4752
  }
4755
4753
 
4756
4754
  // Column separator lines and column alignment
4757
- let align = "";
4758
4755
 
4759
4756
  if (group.cols && group.cols.length > 0) {
4760
4757
  const cols = group.cols;
@@ -4783,7 +4780,6 @@ var temml = (function () {
4783
4780
  for (let i = iStart; i < iEnd; i++) {
4784
4781
  if (cols[i].type === "align") {
4785
4782
  const colAlign = alignMap[cols[i].align];
4786
- align += colAlign;
4787
4783
  iCol += 1;
4788
4784
  for (const row of table.children) {
4789
4785
  if (colAlign.trim() !== "center" && iCol < row.children.length) {
@@ -4821,15 +4817,6 @@ var temml = (function () {
4821
4817
  }
4822
4818
  }
4823
4819
  }
4824
- if (group.autoTag) {
4825
- // allow for glue cells on each side
4826
- align = "left " + (align.length > 0 ? align : "center ") + "right ";
4827
- }
4828
- if (align) {
4829
- // Firefox reads this attribute, not the -webkit-left|right written above.
4830
- // TODO: When Chrome no longer needs "-webkit-", use CSS and delete the next line.
4831
- table.setAttribute("columnalign", align.trim());
4832
- }
4833
4820
 
4834
4821
  if (group.envClasses.includes("small")) {
4835
4822
  // A small array. Wrap in scriptstyle.
@@ -6008,6 +5995,9 @@ var temml = (function () {
6008
5995
 
6009
5996
  // Delimiter functions
6010
5997
  function checkDelimiter(delim, context) {
5998
+ if (delim.type === "ordgroup" && delim.body.length === 1) {
5999
+ delim = delim.body[0]; // Unwrap the braces
6000
+ }
6011
6001
  const symDelim = checkSymbolNodeType(delim);
6012
6002
  if (symDelim && delimiters.includes(symDelim.text)) {
6013
6003
  // If a character is not in the MathML operator dictionary, it will not stretch.
@@ -6239,26 +6229,8 @@ var temml = (function () {
6239
6229
  }
6240
6230
  });
6241
6231
 
6242
- const padding = _ => {
6243
- const node = new mathMLTree.MathNode("mspace");
6244
- node.setAttribute("width", "3pt");
6245
- return node
6246
- };
6247
-
6248
6232
  const mathmlBuilder$7 = (group, style) => {
6249
- let node;
6250
- if (group.label.indexOf("colorbox") > -1 || group.label === "\\boxed") {
6251
- // MathML core does not support +width attribute in <mpadded>.
6252
- // Firefox does not reliably add side padding.
6253
- // Insert <mspace>
6254
- node = new mathMLTree.MathNode("mrow", [
6255
- padding(),
6256
- buildGroup$1(group.body, style),
6257
- padding()
6258
- ]);
6259
- } else {
6260
- node = new mathMLTree.MathNode("menclose", [buildGroup$1(group.body, style)]);
6261
- }
6233
+ const node = new mathMLTree.MathNode("menclose", [buildGroup$1(group.body, style)]);
6262
6234
  switch (group.label) {
6263
6235
  case "\\overline":
6264
6236
  node.setAttribute("notation", "top"); // for Firefox & WebKit
@@ -6306,7 +6278,7 @@ var temml = (function () {
6306
6278
  case "\\boxed":
6307
6279
  // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}} from amsmath.sty
6308
6280
  node.setAttribute("notation", "box");
6309
- node.style.padding = "padding: 3pt 0 3pt 0";
6281
+ node.style.padding = "3pt";
6310
6282
  node.style.border = "1px solid";
6311
6283
  node.setAttribute("scriptlevel", "0");
6312
6284
  node.setAttribute("displaystyle", "true");
@@ -6323,12 +6295,10 @@ var temml = (function () {
6323
6295
  //const fboxsep = 3; // 3 pt from LaTeX source2e
6324
6296
  //node.setAttribute("height", `+${2 * fboxsep}pt`)
6325
6297
  //node.setAttribute("voffset", `${fboxsep}pt`)
6326
- const style = { padding: "3pt 0 3pt 0" };
6327
-
6298
+ node.style.padding = "3pt";
6328
6299
  if (group.label === "\\fcolorbox") {
6329
- style.border = "0.0667em solid " + String(group.borderColor);
6300
+ node.style.border = "0.0667em solid " + String(group.borderColor);
6330
6301
  }
6331
- node.style = style;
6332
6302
  break
6333
6303
  }
6334
6304
  }
@@ -7471,7 +7441,7 @@ var temml = (function () {
7471
7441
  const phantomInner = buildExpression(ordargument(group.body), style);
7472
7442
  const phantom = new mathMLTree.MathNode("mphantom", phantomInner);
7473
7443
  strut = new mathMLTree.MathNode("mpadded", [phantom]);
7474
- strut.setAttribute("width", "0px");
7444
+ strut.setAttribute("width", "0.1px"); // Don't use 0. WebKit would hide it.
7475
7445
  }
7476
7446
 
7477
7447
  const inner = buildGroup$1(group.body, style);
@@ -7500,7 +7470,7 @@ var temml = (function () {
7500
7470
  node.style.justifyContent = "center";
7501
7471
  }
7502
7472
  }
7503
- node.setAttribute("width", "0px");
7473
+ node.setAttribute("width", "0.1px"); // Don't use 0. WebKit would hide it.
7504
7474
  return node
7505
7475
  }
7506
7476
  });
@@ -7618,17 +7588,17 @@ var temml = (function () {
7618
7588
  if (doSpacing ) {
7619
7589
  if (group.mclass === "mbin") {
7620
7590
  // medium space
7621
- node.children.unshift(padding$1(0.2222));
7622
- node.children.push(padding$1(0.2222));
7591
+ node.children.unshift(padding(0.2222));
7592
+ node.children.push(padding(0.2222));
7623
7593
  } else if (group.mclass === "mrel") {
7624
7594
  // thickspace
7625
- node.children.unshift(padding$1(0.2778));
7626
- node.children.push(padding$1(0.2778));
7595
+ node.children.unshift(padding(0.2778));
7596
+ node.children.push(padding(0.2778));
7627
7597
  } else if (group.mclass === "mpunct") {
7628
- node.children.push(padding$1(0.1667));
7598
+ node.children.push(padding(0.1667));
7629
7599
  } else if (group.mclass === "minner") {
7630
- node.children.unshift(padding$1(0.0556)); // 1 mu is the most likely option
7631
- node.children.push(padding$1(0.0556));
7600
+ node.children.unshift(padding(0.0556)); // 1 mu is the most likely option
7601
+ node.children.push(padding(0.0556));
7632
7602
  }
7633
7603
  }
7634
7604
  } else {
@@ -8876,6 +8846,11 @@ var temml = (function () {
8876
8846
  }
8877
8847
  });
8878
8848
 
8849
+ // Letters that are x-height w/o a descender.
8850
+ const xHeights = ['a', 'c', 'e', 'ı', 'm', 'n', 'o', 'r', 's', 'u', 'v', 'w', 'x', 'z', 'α',
8851
+ 'ε', 'ι', 'κ', 'ν', 'ο', 'π', 'σ', 'τ', 'υ', 'ω', '\\alpha', '\\epsilon', "\\iota",
8852
+ '\\kappa', '\\nu', '\\omega', '\\pi', '\\tau', '\\omega'];
8853
+
8879
8854
  defineFunction({
8880
8855
  type: "sqrt",
8881
8856
  names: ["\\sqrt"],
@@ -8886,6 +8861,20 @@ var temml = (function () {
8886
8861
  handler({ parser }, args, optArgs) {
8887
8862
  const index = optArgs[0];
8888
8863
  const body = args[0];
8864
+ // Check if the body consists entirely of an x-height letter.
8865
+ // TODO: Remove this check after Chromium is fixed.
8866
+ if (body.body && body.body.length === 1 && body.body[0].text &&
8867
+ xHeights.includes(body.body[0].text)) {
8868
+ // Chromium does not put enough space above an x-height letter.
8869
+ // Insert a strut.
8870
+ body.body.push({
8871
+ "type": "rule",
8872
+ "mode": "math",
8873
+ "shift": null,
8874
+ "width": { "number": 0, "unit": "pt" },
8875
+ "height": { "number": 0.5, "unit": "em" }
8876
+ });
8877
+ }
8889
8878
  return {
8890
8879
  type: "sqrt",
8891
8880
  mode: parser.mode,
@@ -9173,10 +9162,10 @@ var temml = (function () {
9173
9162
  } else if (group.needsSpacing) {
9174
9163
  // Fix a MathML bug that occurs when a <mo> is between two <mtext> elements.
9175
9164
  if (group.family === "bin") {
9176
- return new mathMLTree.MathNode("mrow", [padding$1(0.222), node, padding$1(0.222)])
9165
+ return new mathMLTree.MathNode("mrow", [padding(0.222), node, padding(0.222)])
9177
9166
  } else {
9178
9167
  // REL spacing
9179
- return new mathMLTree.MathNode("mrow", [padding$1(0.2778), node, padding$1(0.2778)])
9168
+ return new mathMLTree.MathNode("mrow", [padding(0.2778), node, padding(0.2778)])
9180
9169
  }
9181
9170
  }
9182
9171
  return node;
@@ -12109,7 +12098,7 @@ var temml = (function () {
12109
12098
  * https://mit-license.org/
12110
12099
  */
12111
12100
 
12112
- const version = "0.11.09";
12101
+ const version = "0.11.11";
12113
12102
 
12114
12103
  function postProcess(block) {
12115
12104
  const labelMap = {};