temml 0.11.3 → 0.11.5

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
@@ -2454,9 +2454,6 @@ function buildMathML(tree, texExpression, style, settings) {
2454
2454
  if (settings.xml) {
2455
2455
  math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
2456
2456
  }
2457
- if (wrapper.style.width) {
2458
- math.style.width = "100%";
2459
- }
2460
2457
  if (settings.displayMode) {
2461
2458
  math.setAttribute("display", "block");
2462
2459
  math.style.display = "block math"; // necessary in Chromium.
@@ -6464,7 +6461,7 @@ const mathmlBuilder$9 = function(group, style) {
6464
6461
  const numColumns = group.body[0].length;
6465
6462
  // Fill out a short row with empty <mtd> elements.
6466
6463
  for (let k = 0; k < numColumns - rw.length; k++) {
6467
- row.push(new mathMLTree.MathNode("mtd", [], style));
6464
+ row.push(new mathMLTree.MathNode("mtd", [], [], style));
6468
6465
  }
6469
6466
  if (group.autoTag) {
6470
6467
  const tag = group.tags[i];
@@ -6924,7 +6921,9 @@ defineEnvironment({
6924
6921
  }
6925
6922
  }
6926
6923
  const res = parseArray(context.parser, payload, "text");
6927
- res.cols = new Array(res.body[0].length).fill({ type: "align", align: colAlign });
6924
+ res.cols = res.body.length > 0
6925
+ ? new Array(res.body[0].length).fill({ type: "align", align: colAlign })
6926
+ : [];
6928
6927
  const [arraystretch, arraycolsep] = arrayGaps(context.parser.gullet.macros);
6929
6928
  res.arraystretch = arraystretch;
6930
6929
  if (arraycolsep && !(arraycolsep === 6 && arraycolsep === "pt")) {
@@ -6953,7 +6952,9 @@ defineEnvironment({
6953
6952
  handler(context) {
6954
6953
  const payload = { cols: [], envClasses: ["bordermatrix"] };
6955
6954
  const res = parseArray(context.parser, payload, "text");
6956
- res.cols = new Array(res.body[0].length).fill({ type: "align", align: "c" });
6955
+ res.cols = res.body.length > 0
6956
+ ? new Array(res.body[0].length).fill({ type: "align", align: "c" })
6957
+ : [];
6957
6958
  res.envClasses = [];
6958
6959
  res.arraystretch = 1;
6959
6960
  if (context.envName === "matrix") { return res}
@@ -7387,6 +7388,9 @@ const mathmlBuilder$8 = (group, style) => {
7387
7388
  // So instead of wrapping the group in an <mstyle>, we apply
7388
7389
  // the color individually to each node and return a document fragment.
7389
7390
  let expr = buildExpression(group.body, style.withColor(group.color));
7391
+ if (expr.length === 0) {
7392
+ expr.push(new mathMLTree.MathNode("mrow"));
7393
+ }
7390
7394
  expr = expr.map(e => {
7391
7395
  e.style.color = group.color;
7392
7396
  return e
@@ -8473,17 +8477,20 @@ const mathmlBuilder$6 = (group, style) => {
8473
8477
  // Check if it is possible to consolidate elements into a single <mi> element.
8474
8478
  if (isLongVariableName(group, font)) {
8475
8479
  // This is a \mathrm{…} group. It gets special treatment because symbolsOrd.js
8476
- // wraps <mi> elements with <mrow>s to work around a Firefox bug.
8477
- const mi = mathGroup.children[0].children[0];
8480
+ // wraps <mi> elements with <mpadded>s to work around a Firefox bug.
8481
+ const mi = mathGroup.children[0].children[0].children
8482
+ ? mathGroup.children[0].children[0]
8483
+ : mathGroup.children[0];
8478
8484
  delete mi.attributes.mathvariant;
8479
8485
  for (let i = 1; i < mathGroup.children.length; i++) {
8480
8486
  mi.children[0].text += mathGroup.children[i].children[0].children
8481
8487
  ? mathGroup.children[i].children[0].children[0].text
8482
8488
  : mathGroup.children[i].children[0].text;
8483
8489
  }
8484
- // Wrap in a <mrow> to prevent the same Firefox bug.
8485
- const bogus = new mathMLTree.MathNode("mtext", new mathMLTree.TextNode("\u200b"));
8486
- return new mathMLTree.MathNode("mrow", [bogus, mi])
8490
+ // Wrap in a <mpadded> to prevent the same Firefox bug.
8491
+ const mpadded = new mathMLTree.MathNode("mpadded", [mi]);
8492
+ mpadded.setAttribute("lspace", "0");
8493
+ return mpadded
8487
8494
  }
8488
8495
  let canConsolidate = mathGroup.children[0].type === "mo";
8489
8496
  for (let i = 1; i < mathGroup.children.length; i++) {
@@ -10558,7 +10565,8 @@ defineFunction({
10558
10565
  names: ["\\relax"],
10559
10566
  props: {
10560
10567
  numArgs: 0,
10561
- allowedInText: true
10568
+ allowedInText: true,
10569
+ allowedInArgument: true
10562
10570
  },
10563
10571
  handler({ parser }) {
10564
10572
  return {
@@ -12974,6 +12982,7 @@ class Parser {
12974
12982
  if (!atom) {
12975
12983
  break;
12976
12984
  } else if (atom.type === "internal") {
12985
+ // Internal nodes do not appear in parse tree
12977
12986
  continue;
12978
12987
  }
12979
12988
  body.push(atom);
@@ -13048,7 +13057,11 @@ class Parser {
13048
13057
  const symbol = symbolToken.text;
13049
13058
  this.consume();
13050
13059
  this.consumeSpaces(); // ignore spaces before sup/subscript argument
13051
- const group = this.parseGroup(name);
13060
+ // Skip over allowed internal nodes such as \relax
13061
+ let group;
13062
+ do {
13063
+ group = this.parseGroup(name);
13064
+ } while (group.type && group.type === "internal")
13052
13065
 
13053
13066
  if (!group) {
13054
13067
  throw new ParseError("Expected group after '" + symbol + "'", symbolToken);
@@ -13092,9 +13105,15 @@ class Parser {
13092
13105
  // \left(x\right)^2 work correctly.
13093
13106
  const base = this.parseGroup("atom", breakOnTokenText);
13094
13107
 
13108
+ // Internal nodes (e.g. \relax) cannot support super/subscripts.
13109
+ // Instead we will pick up super/subscripts with blank base next round.
13110
+ if (base && base.type === "internal") {
13111
+ return base
13112
+ }
13113
+
13095
13114
  // In text mode, we don't have superscripts or subscripts
13096
13115
  if (this.mode === "text") {
13097
- return base;
13116
+ return base
13098
13117
  }
13099
13118
 
13100
13119
  // Note that base may be empty (i.e. null) at this point.
@@ -13951,7 +13970,7 @@ class Style {
13951
13970
  * https://mit-license.org/
13952
13971
  */
13953
13972
 
13954
- const version = "0.11.03";
13973
+ const version = "0.11.05";
13955
13974
 
13956
13975
  function postProcess(block) {
13957
13976
  const labelMap = {};
@@ -11,7 +11,7 @@
11
11
  * https://mit-license.org/
12
12
  */
13
13
 
14
- const version = "0.11.03";
14
+ const version = "0.11.05";
15
15
 
16
16
  function postProcess(block) {
17
17
  const labelMap = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "temml",
3
- "version": "0.11.03",
3
+ "version": "0.11.05",
4
4
  "description": "TeX to MathML conversion in JavaScript.",
5
5
  "main": "dist/temml.js",
6
6
  "engines": {
package/src/Parser.js CHANGED
@@ -213,6 +213,7 @@ export default class Parser {
213
213
  if (!atom) {
214
214
  break;
215
215
  } else if (atom.type === "internal") {
216
+ // Internal nodes do not appear in parse tree
216
217
  continue;
217
218
  }
218
219
  body.push(atom);
@@ -287,7 +288,11 @@ export default class Parser {
287
288
  const symbol = symbolToken.text;
288
289
  this.consume();
289
290
  this.consumeSpaces(); // ignore spaces before sup/subscript argument
290
- const group = this.parseGroup(name);
291
+ // Skip over allowed internal nodes such as \relax
292
+ let group
293
+ do {
294
+ group = this.parseGroup(name);
295
+ } while (group.type && group.type === "internal")
291
296
 
292
297
  if (!group) {
293
298
  throw new ParseError("Expected group after '" + symbol + "'", symbolToken);
@@ -329,11 +334,17 @@ export default class Parser {
329
334
  parseAtom(breakOnTokenText) {
330
335
  // The body of an atom is an implicit group, so that things like
331
336
  // \left(x\right)^2 work correctly.
332
- const base = this.parseGroup("atom", breakOnTokenText);
337
+ const base = this.parseGroup("atom", breakOnTokenText)
338
+
339
+ // Internal nodes (e.g. \relax) cannot support super/subscripts.
340
+ // Instead we will pick up super/subscripts with blank base next round.
341
+ if (base && base.type === "internal") {
342
+ return base
343
+ }
333
344
 
334
345
  // In text mode, we don't have superscripts or subscripts
335
346
  if (this.mode === "text") {
336
- return base;
347
+ return base
337
348
  }
338
349
 
339
350
  // Note that base may be empty (i.e. null) at this point.
@@ -341,9 +341,6 @@ export default function buildMathML(tree, texExpression, style, settings) {
341
341
  if (settings.xml) {
342
342
  math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML")
343
343
  }
344
- if (wrapper.style.width) {
345
- math.style.width = "100%"
346
- }
347
344
  if (settings.displayMode) {
348
345
  math.setAttribute("display", "block");
349
346
  math.style.display = "block math" // necessary in Chromium.
@@ -295,7 +295,7 @@ const mathmlBuilder = function(group, style) {
295
295
  const numColumns = group.body[0].length
296
296
  // Fill out a short row with empty <mtd> elements.
297
297
  for (let k = 0; k < numColumns - rw.length; k++) {
298
- row.push(new mathMLTree.MathNode("mtd", [], style))
298
+ row.push(new mathMLTree.MathNode("mtd", [], [], style))
299
299
  }
300
300
  if (group.autoTag) {
301
301
  const tag = group.tags[i];
@@ -757,7 +757,9 @@ defineEnvironment({
757
757
  }
758
758
  }
759
759
  const res = parseArray(context.parser, payload, "text")
760
- res.cols = new Array(res.body[0].length).fill({ type: "align", align: colAlign })
760
+ res.cols = res.body.length > 0
761
+ ? new Array(res.body[0].length).fill({ type: "align", align: colAlign })
762
+ : [];
761
763
  const [arraystretch, arraycolsep] = arrayGaps(context.parser.gullet.macros)
762
764
  res.arraystretch = arraystretch
763
765
  if (arraycolsep && !(arraycolsep === 6 && arraycolsep === "pt")) {
@@ -786,7 +788,9 @@ defineEnvironment({
786
788
  handler(context) {
787
789
  const payload = { cols: [], envClasses: ["bordermatrix"] }
788
790
  const res = parseArray(context.parser, payload, "text")
789
- res.cols = new Array(res.body[0].length).fill({ type: "align", align: "c" })
791
+ res.cols = res.body.length > 0
792
+ ? new Array(res.body[0].length).fill({ type: "align", align: "c" })
793
+ : [];
790
794
  res.envClasses = [];
791
795
  res.arraystretch = 1
792
796
  if (context.envName === "matrix") { return res}
@@ -156,6 +156,9 @@ const mathmlBuilder = (group, style) => {
156
156
  // So instead of wrapping the group in an <mstyle>, we apply
157
157
  // the color individually to each node and return a document fragment.
158
158
  let expr = mml.buildExpression(group.body, style.withColor(group.color))
159
+ if (expr.length === 0) {
160
+ expr.push(new mathMLTree.MathNode("mrow"))
161
+ }
159
162
  expr = expr.map(e => {
160
163
  e.style.color = group.color
161
164
  return e
@@ -30,17 +30,20 @@ const mathmlBuilder = (group, style) => {
30
30
  // Check if it is possible to consolidate elements into a single <mi> element.
31
31
  if (isLongVariableName(group, font)) {
32
32
  // This is a \mathrm{…} group. It gets special treatment because symbolsOrd.js
33
- // wraps <mi> elements with <mrow>s to work around a Firefox bug.
34
- const mi = mathGroup.children[0].children[0];
33
+ // wraps <mi> elements with <mpadded>s to work around a Firefox bug.
34
+ const mi = mathGroup.children[0].children[0].children
35
+ ? mathGroup.children[0].children[0]
36
+ : mathGroup.children[0];
35
37
  delete mi.attributes.mathvariant
36
38
  for (let i = 1; i < mathGroup.children.length; i++) {
37
39
  mi.children[0].text += mathGroup.children[i].children[0].children
38
40
  ? mathGroup.children[i].children[0].children[0].text
39
41
  : mathGroup.children[i].children[0].text
40
42
  }
41
- // Wrap in a <mrow> to prevent the same Firefox bug.
42
- const bogus = new mathMLTree.MathNode("mtext", new mathMLTree.TextNode("\u200b"))
43
- return new mathMLTree.MathNode("mrow", [bogus, mi])
43
+ // Wrap in a <mpadded> to prevent the same Firefox bug.
44
+ const mpadded = new mathMLTree.MathNode("mpadded", [mi])
45
+ mpadded.setAttribute("lspace", "0")
46
+ return mpadded
44
47
  }
45
48
  let canConsolidate = mathGroup.children[0].type === "mo"
46
49
  for (let i = 1; i < mathGroup.children.length; i++) {
@@ -5,7 +5,8 @@ defineFunction({
5
5
  names: ["\\relax"],
6
6
  props: {
7
7
  numArgs: 0,
8
- allowedInText: true
8
+ allowedInText: true,
9
+ allowedInArgument: true
9
10
  },
10
11
  handler({ parser }) {
11
12
  return {
@@ -5,7 +5,7 @@
5
5
  * https://mit-license.org/
6
6
  */
7
7
 
8
- export const version = "0.11.03";
8
+ export const version = "0.11.05";
9
9
 
10
10
  export function postProcess(block) {
11
11
  const labelMap = {}