temml 0.10.32 → 0.10.33

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
@@ -502,6 +502,40 @@ var temml = (function () {
502
502
  }
503
503
  };
504
504
 
505
+ // Create an <a href="…"> node.
506
+ class AnchorNode {
507
+ constructor(href, classes, children) {
508
+ this.href = href;
509
+ this.classes = classes;
510
+ this.children = children || [];
511
+ }
512
+
513
+ toNode() {
514
+ const node = document.createElement("a");
515
+ node.setAttribute("href", this.href);
516
+ if (this.classes.length > 0) {
517
+ node.className = createClass(this.classes);
518
+ }
519
+ for (let i = 0; i < this.children.length; i++) {
520
+ node.appendChild(this.children[i].toNode());
521
+ }
522
+ return node
523
+ }
524
+
525
+ toMarkup() {
526
+ let markup = `<a href='${utils.escape(this.href)}'`;
527
+ if (this.classes.length > 0) {
528
+ markup += ` class="${utils.escape(createClass(this.classes))}"`;
529
+ }
530
+ markup += ">";
531
+ for (let i = 0; i < this.children.length; i++) {
532
+ markup += this.children[i].toMarkup();
533
+ }
534
+ markup += "</a>";
535
+ return markup
536
+ }
537
+ }
538
+
505
539
  /*
506
540
  * This node represents an image embed (<img>) element.
507
541
  */
@@ -1531,7 +1565,7 @@ var temml = (function () {
1531
1565
  defineSymbol(math, open, "\u27ea", "\\lAngle", true);
1532
1566
  defineSymbol(math, open, "\u2989", "\\llangle", true);
1533
1567
  defineSymbol(math, open, "|", "\\lvert");
1534
- defineSymbol(math, open, "\u2016", "\\lVert");
1568
+ defineSymbol(math, open, "\u2016", "\\lVert", true);
1535
1569
  defineSymbol(math, textord, "!", "\\oc"); // cmll package
1536
1570
  defineSymbol(math, textord, "?", "\\wn");
1537
1571
  defineSymbol(math, textord, "\u2193", "\\shpos");
@@ -1695,7 +1729,7 @@ var temml = (function () {
1695
1729
  defineSymbol(math, inner, "\u22ef", "\\@cdots", true);
1696
1730
  defineSymbol(math, inner, "\u22f1", "\\ddots", true);
1697
1731
  defineSymbol(math, textord, "\u22ee", "\\varvdots"); // \vdots is a macro
1698
- defineSymbol(text, textord, "\u22ee", "\\textvdots");
1732
+ defineSymbol(text, textord, "\u22ee", "\\varvdots");
1699
1733
  defineSymbol(math, accent, "\u02ca", "\\acute");
1700
1734
  defineSymbol(math, accent, "\u0060", "\\grave");
1701
1735
  defineSymbol(math, accent, "\u00a8", "\\ddot");
@@ -2148,61 +2182,6 @@ var temml = (function () {
2148
2182
  }
2149
2183
  };
2150
2184
 
2151
- const numberRegEx$1 = /^[0-9]$/;
2152
- const isDotOrComma = (node, followingNode) => {
2153
- return ((node.type === "textord" && node.text === ".") ||
2154
- (node.type === "atom" && node.text === ",")) &&
2155
- // Don't consolidate if there is a space after the comma.
2156
- node.loc && followingNode.loc && node.loc.end === followingNode.loc.start
2157
- };
2158
- const consolidateNumbers = expression => {
2159
- // Consolidate adjacent numbers. We want to return <mn>1,506.3</mn>,
2160
- // not <mn>1</mn><mo>,</mo><mn>5</mn><mn>0</mn><mn>6</mn><mi>.</mi><mn>3</mn>
2161
- if (expression.length < 2) { return }
2162
- const nums = [];
2163
- let inNum = false;
2164
- // Find adjacent numerals
2165
- for (let i = 0; i < expression.length; i++) {
2166
- const node = expression[i];
2167
- if (node.type === "textord" && numberRegEx$1.test(node.text)) {
2168
- if (!inNum) { nums.push({ start: i }); }
2169
- inNum = true;
2170
- } else {
2171
- if (inNum) { nums[nums.length - 1].end = i - 1; }
2172
- inNum = false;
2173
- }
2174
- }
2175
- if (inNum) { nums[nums.length - 1].end = expression.length - 1; }
2176
-
2177
- // Determine if numeral groups are separated by a comma or dot.
2178
- for (let i = nums.length - 1; i > 0; i--) {
2179
- if (nums[i - 1].end === nums[i].start - 2 &&
2180
- isDotOrComma(expression[nums[i].start - 1], expression[nums[i].start])) {
2181
- // Merge the two groups.
2182
- nums[i - 1].end = nums[i].end;
2183
- nums.splice(i, 1);
2184
- }
2185
- }
2186
-
2187
- // Consolidate the number nodes
2188
- for (let i = nums.length - 1; i >= 0; i--) {
2189
- for (let j = nums[i].start + 1; j <= nums[i].end; j++) {
2190
- expression[nums[i].start].text += expression[j].text;
2191
- }
2192
- expression.splice(nums[i].start + 1, nums[i].end - nums[i].start);
2193
- // Check if the <mn> is followed by a numeric base in a supsub, e.g. the "3" in 123^4
2194
- // If so, merge the first <mn> into the base.
2195
- if (expression.length > nums[i].start + 1) {
2196
- const nextTerm = expression[nums[i].start + 1];
2197
- if (nextTerm.type === "supsub" && nextTerm.base && nextTerm.base.type === "textord" &&
2198
- numberRegEx$1.test(nextTerm.base.text)) {
2199
- nextTerm.base.text = expression[nums[i].start].text + nextTerm.base.text;
2200
- expression.splice(nums[i].start, 1);
2201
- }
2202
- }
2203
- }
2204
- };
2205
-
2206
2185
  /**
2207
2186
  * Wrap the given array of nodes in an <mrow> node if needed, i.e.,
2208
2187
  * unless the array has length 1. Always returns a single node.
@@ -2225,6 +2204,39 @@ var temml = (function () {
2225
2204
  return new mathMLTree.MathNode("mrow", body);
2226
2205
  };
2227
2206
 
2207
+ /**
2208
+ * Check for <mi>.</mi> which is how a dot renders in MathML,
2209
+ * or <mo separator="true" lspace="0em" rspace="0em">,</mo>
2210
+ * which is how a braced comma {,} renders in MathML
2211
+ */
2212
+ function isNumberPunctuation(group) {
2213
+ if (!group) {
2214
+ return false
2215
+ }
2216
+ if (group.type === 'mi' && group.children.length === 1) {
2217
+ const child = group.children[0];
2218
+ return child instanceof TextNode && child.text === '.'
2219
+ } else if (group.type === "mtext" && group.children.length === 1) {
2220
+ const child = group.children[0];
2221
+ return child instanceof TextNode && child.text === '\u2008' // punctuation space
2222
+ } else if (group.type === 'mo' && group.children.length === 1 &&
2223
+ group.getAttribute('separator') === 'true' &&
2224
+ group.getAttribute('lspace') === '0em' &&
2225
+ group.getAttribute('rspace') === '0em') {
2226
+ const child = group.children[0];
2227
+ return child instanceof TextNode && child.text === ','
2228
+ } else {
2229
+ return false
2230
+ }
2231
+ }
2232
+ const isComma = (expression, i) => {
2233
+ const node = expression[i];
2234
+ const followingNode = expression[i + 1];
2235
+ return (node.type === "atom" && node.text === ",") &&
2236
+ // Don't consolidate if there is a space after the comma.
2237
+ node.loc && followingNode.loc && node.loc.end === followingNode.loc.start
2238
+ };
2239
+
2228
2240
  const isRel = item => {
2229
2241
  return (item.type === "atom" && item.family === "rel") ||
2230
2242
  (item.type === "mclass" && item.mclass === "mrel")
@@ -2248,11 +2260,16 @@ var temml = (function () {
2248
2260
  return [group];
2249
2261
  }
2250
2262
 
2251
- consolidateNumbers(expression);
2252
-
2253
2263
  const groups = [];
2264
+ const groupArray = [];
2265
+ let lastGroup;
2254
2266
  for (let i = 0; i < expression.length; i++) {
2255
- const group = buildGroup$1(expression[i], style);
2267
+ groupArray.push(buildGroup$1(expression[i], style));
2268
+ }
2269
+
2270
+ for (let i = 0; i < groupArray.length; i++) {
2271
+ const group = groupArray[i];
2272
+
2256
2273
  // Suppress spacing between adjacent relations
2257
2274
  if (i < expression.length - 1 && isRel(expression[i]) && isRel(expression[i + 1])) {
2258
2275
  group.setAttribute("rspace", "0em");
@@ -2260,9 +2277,39 @@ var temml = (function () {
2260
2277
  if (i > 0 && isRel(expression[i]) && isRel(expression[i - 1])) {
2261
2278
  group.setAttribute("lspace", "0em");
2262
2279
  }
2280
+
2281
+ // Concatenate numbers
2282
+ if (group.type === 'mn' && lastGroup && lastGroup.type === 'mn') {
2283
+ // Concatenate <mn>...</mn> followed by <mi>.</mi>
2284
+ lastGroup.children.push(...group.children);
2285
+ continue
2286
+ } else if (isNumberPunctuation(group) && lastGroup && lastGroup.type === 'mn') {
2287
+ // Concatenate <mn>...</mn> followed by <mi>.</mi>
2288
+ lastGroup.children.push(...group.children);
2289
+ continue
2290
+ } else if (lastGroup && lastGroup.type === "mn" && i < groupArray.length - 1 &&
2291
+ groupArray[i + 1].type === "mn" && isComma(expression, i)) {
2292
+ lastGroup.children.push(...group.children);
2293
+ continue
2294
+ } else if (group.type === 'mn' && isNumberPunctuation(lastGroup)) {
2295
+ // Concatenate <mi>.</mi> followed by <mn>...</mn>
2296
+ group.children = [...lastGroup.children, ...group.children];
2297
+ groups.pop();
2298
+ } else if ((group.type === 'msup' || group.type === 'msub') &&
2299
+ group.children.length >= 1 && lastGroup &&
2300
+ (lastGroup.type === 'mn' || isNumberPunctuation(lastGroup))) {
2301
+ // Put preceding <mn>...</mn> or <mi>.</mi> inside base of
2302
+ // <msup><mn>...base...</mn>...exponent...</msup> (or <msub>)
2303
+ const base = group.children[0];
2304
+ if (base instanceof MathNode && base.type === 'mn' && lastGroup) {
2305
+ base.children = [...lastGroup.children, ...base.children];
2306
+ groups.pop();
2307
+ }
2308
+ }
2263
2309
  groups.push(group);
2310
+ lastGroup = group;
2264
2311
  }
2265
- return groups;
2312
+ return groups
2266
2313
  };
2267
2314
 
2268
2315
  /**
@@ -2324,6 +2371,11 @@ var temml = (function () {
2324
2371
  }
2325
2372
 
2326
2373
  const expression = buildExpression(tree, style);
2374
+
2375
+ if (expression.length === 1 && expression[0] instanceof AnchorNode) {
2376
+ return expression[0]
2377
+ }
2378
+
2327
2379
  const wrap = (settings.displayMode || settings.annotate) ? "none" : settings.wrap;
2328
2380
 
2329
2381
  const n1 = expression.length === 0 ? null : expression[0];
@@ -2348,6 +2400,9 @@ var temml = (function () {
2348
2400
  if (settings.xml) {
2349
2401
  math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
2350
2402
  }
2403
+ if (wrapper.style.width) {
2404
+ math.style.width = "100%";
2405
+ }
2351
2406
  if (settings.displayMode) {
2352
2407
  math.setAttribute("display", "block");
2353
2408
  math.style.display = "block math"; // necessary in Chromium.
@@ -2679,12 +2734,19 @@ var temml = (function () {
2679
2734
  return node
2680
2735
  };
2681
2736
 
2682
- const paddedNode = (group, lspace = 0.3, rspace = 0) => {
2737
+ const paddedNode = (group, lspace = 0.3, rspace = 0, mustSmash = false) => {
2683
2738
  if (group == null && rspace === 0) { return padding$2(lspace) }
2684
2739
  const row = group ? [group] : [];
2685
2740
  if (lspace !== 0) { row.unshift(padding$2(lspace)); }
2686
2741
  if (rspace > 0) { row.push(padding$2(rspace)); }
2687
- return new mathMLTree.MathNode("mrow", row)
2742
+ if (mustSmash) {
2743
+ // Used for the bottom arrow in a {CD} environment
2744
+ const mpadded = new mathMLTree.MathNode("mpadded", row);
2745
+ mpadded.setAttribute("height", "0");
2746
+ return mpadded
2747
+ } else {
2748
+ return new mathMLTree.MathNode("mrow", row)
2749
+ }
2688
2750
  };
2689
2751
 
2690
2752
  const labelSize = (size, scriptLevel) => Number(size) / emScale(scriptLevel);
@@ -2724,7 +2786,8 @@ var temml = (function () {
2724
2786
  (body.body.body || body.body.length > 0));
2725
2787
  if (gotUpper) {
2726
2788
  let label = buildGroup$1(body, labelStyle);
2727
- label = paddedNode(label, space, space);
2789
+ const mustSmash = (fName === "\\\\cdrightarrow" || fName === "\\\\cdleftarrow");
2790
+ label = paddedNode(label, space, space, mustSmash);
2728
2791
  // Since Firefox does not support minsize, stack a invisible node
2729
2792
  // on top of the label. Its width will serve as a min-width.
2730
2793
  // TODO: Refactor this after Firefox supports minsize.
@@ -3147,18 +3210,23 @@ var temml = (function () {
3147
3210
  };
3148
3211
  },
3149
3212
  mathmlBuilder(group, style) {
3150
- let label = new mathMLTree.MathNode("mrow", [buildGroup$1(group.label, style)]);
3151
- label = new mathMLTree.MathNode("mpadded", [label]);
3152
- label.setAttribute("width", "0");
3153
- if (group.side === "left") {
3154
- label.setAttribute("lspace", "-1width");
3213
+ if (group.label.body.length === 0) {
3214
+ return new mathMLTree.MathNode("mrow", style) // empty label
3155
3215
  }
3156
- // We have to guess at vertical alignment. We know the arrow is 1.8em tall,
3157
- // But we don't know the height or depth of the label.
3158
- label.setAttribute("voffset", "0.7em");
3159
- label = new mathMLTree.MathNode("mstyle", [label]);
3216
+ // Abuse an <mtable> to create vertically centered content.
3217
+ const mtd = new mathMLTree.MathNode("mtd", [buildGroup$1(group.label, style)]);
3218
+ mtd.style.padding = "0";
3219
+ const mtr = new mathMLTree.MathNode("mtr", [mtd]);
3220
+ const mtable = new mathMLTree.MathNode("mtable", [mtr]);
3221
+ const label = new mathMLTree.MathNode("mpadded", [mtable]);
3222
+ // Set the label width to zero so that the arrow will be centered under the corner cell.
3223
+ label.setAttribute("width", "0");
3160
3224
  label.setAttribute("displaystyle", "false");
3161
3225
  label.setAttribute("scriptlevel", "1");
3226
+ if (group.side === "left") {
3227
+ label.style.display = "flex";
3228
+ label.style.justifyContent = "flex-end";
3229
+ }
3162
3230
  return label;
3163
3231
  }
3164
3232
  });
@@ -3748,10 +3816,13 @@ var temml = (function () {
3748
3816
  // replacement text, enclosed in '{' and '}' and properly nested
3749
3817
  const { tokens } = parser.gullet.consumeArg();
3750
3818
 
3751
- parser.gullet.macros.set(
3752
- name,
3753
- { tokens, numArgs }
3754
- );
3819
+ if (!(funcName === "\\providecommand" && parser.gullet.macros.has(name))) {
3820
+ // Ignore \providecommand
3821
+ parser.gullet.macros.set(
3822
+ name,
3823
+ { tokens, numArgs }
3824
+ );
3825
+ }
3755
3826
 
3756
3827
  return { type: "internal", mode: parser.mode };
3757
3828
 
@@ -3845,6 +3916,7 @@ var temml = (function () {
3845
3916
  "\\vert",
3846
3917
  "\\|",
3847
3918
  "\\Vert",
3919
+ "\u2016",
3848
3920
  "\\uparrow",
3849
3921
  "\\Uparrow",
3850
3922
  "\\downarrow",
@@ -4614,7 +4686,7 @@ var temml = (function () {
4614
4686
  // \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
4615
4687
  // We'll call \varvdots, which gets a glyph from symbols.js.
4616
4688
  // The zero-width rule gets us an equivalent to the vertical 6pt kern.
4617
- defineMacro("\\vdots", "\\TextOrMath{\\textvdots}{{\\varvdots\\rule{0pt}{15pt}}}\\relax");
4689
+ defineMacro("\\vdots", "{\\varvdots\\rule{0pt}{15pt}}");
4618
4690
  defineMacro("\u22ee", "\\vdots");
4619
4691
 
4620
4692
  // {array} environment gaps
@@ -6163,6 +6235,7 @@ var temml = (function () {
6163
6235
  "\\mathfrak",
6164
6236
  "\\mathscr",
6165
6237
  "\\mathsf",
6238
+ "\\mathsfit",
6166
6239
  "\\mathtt",
6167
6240
 
6168
6241
  // aliases
@@ -6232,10 +6305,19 @@ var temml = (function () {
6232
6305
  ? style.withLevel(StyleLevel.SCRIPT)
6233
6306
  : style.withLevel(StyleLevel.SCRIPTSCRIPT);
6234
6307
 
6235
- let node = new mathMLTree.MathNode("mfrac", [
6236
- buildGroup$1(group.numer, childOptions),
6237
- buildGroup$1(group.denom, childOptions)
6238
- ]);
6308
+ // Chromium (wrongly) continues to shrink fractions beyond scriptscriptlevel.
6309
+ // So we check for levels that Chromium shrinks too small.
6310
+ // If necessary, set an explicit fraction depth.
6311
+ const numer = buildGroup$1(group.numer, childOptions);
6312
+ const denom = buildGroup$1(group.denom, childOptions);
6313
+ if (style.level === 3) {
6314
+ numer.style.mathDepth = "2";
6315
+ numer.setAttribute("scriptlevel", "2");
6316
+ denom.style.mathDepth = "2";
6317
+ denom.setAttribute("scriptlevel", "2");
6318
+ }
6319
+
6320
+ let node = new mathMLTree.MathNode("mfrac", [numer, denom]);
6239
6321
 
6240
6322
  if (!group.hasBarLine) {
6241
6323
  node.setAttribute("linethickness", "0px");
@@ -6628,12 +6710,9 @@ var temml = (function () {
6628
6710
  };
6629
6711
  },
6630
6712
  mathmlBuilder: (group, style) => {
6631
- let math = buildExpressionRow(group.body, style);
6632
- if (!(math instanceof MathNode)) {
6633
- math = new MathNode("mrow", [math]);
6634
- }
6635
- math.setAttribute("href", group.href);
6636
- return math;
6713
+ const math = new MathNode("math", [buildExpressionRow(group.body, style)]);
6714
+ const anchorNode = new AnchorNode(group.href, [], [math]);
6715
+ return anchorNode
6637
6716
  }
6638
6717
  });
6639
6718
 
@@ -7505,13 +7584,6 @@ var temml = (function () {
7505
7584
  node = new MathNode("mo", [makeText(group.name, group.mode)]);
7506
7585
  if (noSuccessor.includes(group.name)) {
7507
7586
  node.setAttribute("largeop", "false");
7508
- } else if (group.limits) {
7509
- // This is a workaround for a MathML/Chromium bug.
7510
- // This is being applied to singleCharBigOps, which are not really stretchy.
7511
- // But by setting the stretchy attribute, Chromium will vertically center
7512
- // big ops around the math axis. This is needed since STIX TWO does not do so.
7513
- // TODO: Remove this hack when MathML & Chromium fix their problem.
7514
- node.setAttribute("stretchy", "true");
7515
7587
  } else {
7516
7588
  node.setAttribute("movablelimits", "false");
7517
7589
  }
@@ -8146,12 +8218,10 @@ var temml = (function () {
8146
8218
  };
8147
8219
  },
8148
8220
  mathmlBuilder(group, style) {
8149
- // Create an empty text node. Set a class and an href.
8221
+ // Create an empty <a> node. Set a class and an href attribute.
8150
8222
  // The post-processor will populate with the target's tag or equation number.
8151
8223
  const classes = group.funcName === "\\ref" ? ["tml-ref"] : ["tml-ref", "tml-eqref"];
8152
- const node = new mathMLTree.MathNode("mtext", [new mathMLTree.TextNode("")], classes);
8153
- node.setAttribute("href", "#" + group.string);
8154
- return node
8224
+ return new AnchorNode("#" + group.string, classes, null)
8155
8225
  }
8156
8226
  });
8157
8227
 
@@ -8198,6 +8268,8 @@ var temml = (function () {
8198
8268
  props: {
8199
8269
  numArgs: 2,
8200
8270
  numOptionalArgs: 1,
8271
+ allowedInText: true,
8272
+ allowedInMath: true,
8201
8273
  argTypes: ["size", "size", "size"]
8202
8274
  },
8203
8275
  handler({ parser }, args, optArgs) {
@@ -8490,16 +8562,25 @@ var temml = (function () {
8490
8562
  ? [buildGroup$1(group.base.body[0], style)]
8491
8563
  : [buildGroup$1(group.base, style)];
8492
8564
 
8565
+ // Note regarding scriptstyle level.
8566
+ // (Sub|super)scripts should not shrink beyond MathML scriptlevel 2 aka \scriptscriptstyle
8567
+ // Ref: https://w3c.github.io/mathml-core/#the-displaystyle-and-scriptlevel-attributes
8568
+ // (BTW, MathML scriptlevel 2 is equal to Temml level 3.)
8569
+ // But Chromium continues to shrink the (sub|super)scripts. So we explicitly set scriptlevel 2.
8570
+
8493
8571
  const childStyle = style.inSubOrSup();
8494
8572
  if (group.sub) {
8495
- children.push(buildGroup$1(group.sub, childStyle));
8573
+ const sub = buildGroup$1(group.sub, childStyle);
8574
+ if (style.level === 3) { sub.setAttribute("scriptlevel", "2"); }
8575
+ children.push(sub);
8496
8576
  }
8497
8577
 
8498
8578
  if (group.sup) {
8499
8579
  const sup = buildGroup$1(group.sup, childStyle);
8580
+ if (style.level === 3) { sup.setAttribute("scriptlevel", "2"); }
8500
8581
  const testNode = sup.type === "mrow" ? sup.children[0] : sup;
8501
8582
  if ((testNode && testNode.type === "mo" && testNode.classes.includes("tml-prime"))
8502
- && group.base && group.base.text && group.base.text === "f") {
8583
+ && group.base && group.base.text && "fF".indexOf(group.base.text) > -1) {
8503
8584
  // Chromium does not address italic correction on prime. Prevent f′ from overlapping.
8504
8585
  testNode.classes.push("prime-pad");
8505
8586
  }
@@ -8726,6 +8807,8 @@ var temml = (function () {
8726
8807
  return "script"
8727
8808
  case "mathsf":
8728
8809
  return "sans-serif"
8810
+ case "mathsfit":
8811
+ return "sans-serif-italic"
8729
8812
  case "mathtt":
8730
8813
  return "monospace"
8731
8814
  }
@@ -9190,6 +9273,32 @@ var temml = (function () {
9190
9273
  }
9191
9274
  });
9192
9275
 
9276
+ // \vcenter: Vertically center the argument group on the math axis.
9277
+
9278
+ defineFunction({
9279
+ type: "vcenter",
9280
+ names: ["\\vcenter"],
9281
+ props: {
9282
+ numArgs: 1,
9283
+ argTypes: ["original"],
9284
+ allowedInText: false
9285
+ },
9286
+ handler({ parser }, args) {
9287
+ return {
9288
+ type: "vcenter",
9289
+ mode: parser.mode,
9290
+ body: args[0]
9291
+ };
9292
+ },
9293
+ mathmlBuilder(group, style) {
9294
+ // Use a math table to create vertically centered content.
9295
+ const mtd = new mathMLTree.MathNode("mtd", [buildGroup$1(group.body, style)]);
9296
+ mtd.style.padding = "0";
9297
+ const mtr = new mathMLTree.MathNode("mtr", [mtd]);
9298
+ return new mathMLTree.MathNode("mtable", [mtr])
9299
+ }
9300
+ });
9301
+
9193
9302
  defineFunction({
9194
9303
  type: "verb",
9195
9304
  names: ["\\verb"],
@@ -11456,9 +11565,11 @@ var temml = (function () {
11456
11565
  constructor(data) {
11457
11566
  // Style.level can be 0 | 1 | 2 | 3, which correspond to
11458
11567
  // displaystyle, textstyle, scriptstyle, and scriptscriptstyle.
11459
- // style.level does not directly set MathML's script level. MathML does that itself.
11460
- // We use style.level to track, not set, math style so that we can get the
11461
- // correct scriptlevel when needed in supsub.js, mathchoice.js, or for dimensions in em.
11568
+ // style.level usually does not directly set MathML's script level. MathML does that itself.
11569
+ // However, Chromium does not stop shrinking after scriptscriptstyle, so we do explicitly
11570
+ // set a scriptlevel attribute in those conditions.
11571
+ // We also use style.level to track math style so that we can get the correct
11572
+ // scriptlevel when needed in supsub.js, mathchoice.js, or for dimensions in em.
11462
11573
  this.level = data.level;
11463
11574
  this.color = data.color; // string | void
11464
11575
  // A font family applies to a group of fonts (i.e. SansSerif), while a font
@@ -11582,39 +11693,47 @@ var temml = (function () {
11582
11693
  }
11583
11694
 
11584
11695
  /* Temml Post Process
11585
- * Perform two tasks not done by Temml when it created each individual Temml <math> element.
11586
- * Given a block,
11587
- * 1. At each AMS auto-numbered environment, assign an id.
11588
- * 2. Populate the text contents of each \ref & \eqref
11696
+ * Populate the text contents of each \ref & \eqref
11589
11697
  *
11590
11698
  * As with other Temml code, this file is released under terms of the MIT license.
11591
11699
  * https://mit-license.org/
11592
11700
  */
11593
11701
 
11594
- const version = "0.10.32";
11702
+ const version = "0.10.33";
11595
11703
 
11596
11704
  function postProcess(block) {
11597
11705
  const labelMap = {};
11598
11706
  let i = 0;
11599
11707
 
11600
11708
  // Get a collection of the parents of each \tag & auto-numbered equation
11601
- const parents = block.getElementsByClassName("tml-tageqn");
11602
- for (const parent of parents) {
11603
- const eqns = parent.getElementsByClassName("tml-eqn");
11604
- if (eqns. length > 0 ) {
11605
- // AMS automatically numbered equation.
11606
- // Assign an id.
11607
- i += 1;
11608
- eqns[0].id = "tml-eqn-" + i;
11609
- // No need to write a number into the text content of the element.
11610
- // A CSS counter does that even if this postProcess() function is not used.
11709
+ const amsEqns = document.getElementsByClassName('tml-eqn');
11710
+ for (let parent of amsEqns) {
11711
+ // AMS automatically numbered equation.
11712
+ // Assign an id.
11713
+ i += 1;
11714
+ parent.setAttribute("id", "tml-eqn-" + String(i));
11715
+ // No need to write a number into the text content of the element.
11716
+ // A CSS counter has done that even if this postProcess() function is not used.
11717
+
11718
+ // Find any \label that refers to an AMS eqn number.
11719
+ while (true) {
11720
+ const labels = parent.getElementsByClassName("tml-label");
11721
+ if (labels.length > 0) {
11722
+ parent.setAttribute("id", labels[0].id);
11723
+ labelMap[labels[0].id] = String(i);
11724
+ break
11725
+ } else {
11726
+ if (parent.tagName === "mtable") { break }
11727
+ parent = parent.parentElement;
11728
+ }
11611
11729
  }
11612
- // If there is a \label, add it to labelMap
11730
+ }
11731
+
11732
+ // Find \labels associated with \tag
11733
+ const taggedEqns = document.getElementsByClassName('tml-tageqn');
11734
+ for (const parent of taggedEqns) {
11613
11735
  const labels = parent.getElementsByClassName("tml-label");
11614
- if (labels.length === 0) { continue }
11615
- if (eqns.length > 0) {
11616
- labelMap[labels[0].id] = String(i);
11617
- } else {
11736
+ if (labels.length > 0) {
11618
11737
  const tags = parent.getElementsByClassName("tml-tag");
11619
11738
  if (tags.length > 0) {
11620
11739
  labelMap[labels[0].id] = tags[0].textContent;
@@ -11625,17 +11744,22 @@ var temml = (function () {
11625
11744
  // Populate \ref & \eqref text content
11626
11745
  const refs = block.getElementsByClassName("tml-ref");
11627
11746
  [...refs].forEach(ref => {
11628
- let str = labelMap[ref.getAttribute("href").slice(1)];
11747
+ const attr = ref.getAttribute("href");
11748
+ let str = labelMap[attr.slice(1)];
11629
11749
  if (ref.className.indexOf("tml-eqref") === -1) {
11630
11750
  // \ref. Omit parens.
11631
11751
  str = str.replace(/^\(/, "");
11632
- str = str.replace(/\($/, "");
11633
- } {
11752
+ str = str.replace(/\)$/, "");
11753
+ } else {
11634
11754
  // \eqref. Include parens
11635
11755
  if (str.charAt(0) !== "(") { str = "(" + str; }
11636
11756
  if (str.slice(-1) !== ")") { str = str + ")"; }
11637
11757
  }
11638
- ref.textContent = str;
11758
+ const mtext = document.createElementNS("http://www.w3.org/1998/Math/MathML", "mtext");
11759
+ mtext.appendChild(document.createTextNode(str));
11760
+ const math = document.createElementNS("http://www.w3.org/1998/Math/MathML", "math");
11761
+ math.appendChild(mtext);
11762
+ ref.appendChild(math);
11639
11763
  });
11640
11764
  }
11641
11765