temml 0.11.7 → 0.11.8

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
@@ -837,6 +837,9 @@ var temml = (function () {
837
837
  xtwoheadrightarrow: "\u21a0",
838
838
  xlongequal: "=",
839
839
  xrightleftarrows: "\u21c4",
840
+ xtofrom: "\u21c4",
841
+ xleftrightharpoons: "\u21cb",
842
+ xrightleftharpoons: "\u21cc",
840
843
  yields: "\u2192",
841
844
  yieldsLeft: "\u2190",
842
845
  mesomerism: "\u2194",
@@ -846,7 +849,9 @@ var temml = (function () {
846
849
  eqleftharpoondown: "\u21bd",
847
850
  "\\cdrightarrow": "\u2192",
848
851
  "\\cdleftarrow": "\u2190",
849
- "\\cdlongequal": "="
852
+ "\\cdlongequal": "=",
853
+ yieldsLeftRight: "\u21c4",
854
+ chemequilibrium: "\u21cc"
850
855
  };
851
856
 
852
857
  const mathMLnode = function(label) {
@@ -1774,7 +1779,7 @@ var temml = (function () {
1774
1779
  defineSymbol(math, inner, "\u22f1", "\\ddots", true);
1775
1780
  defineSymbol(math, textord, "\u22ee", "\\varvdots"); // \vdots is a macro
1776
1781
  defineSymbol(text, textord, "\u22ee", "\\varvdots");
1777
- defineSymbol(math, accent, "\u02ca", "\\acute");
1782
+ defineSymbol(math, accent, "\u00b4", "\\acute");
1778
1783
  defineSymbol(math, accent, "\u0060", "\\grave");
1779
1784
  defineSymbol(math, accent, "\u00a8", "\\ddot");
1780
1785
  defineSymbol(math, accent, "\u2026", "\\dddot");
@@ -1800,7 +1805,7 @@ var temml = (function () {
1800
1805
  defineSymbol(text, accent, "\u02ca", "\\'"); // acute
1801
1806
  defineSymbol(text, accent, "\u02cb", "\\`"); // grave
1802
1807
  defineSymbol(text, accent, "\u02c6", "\\^"); // circumflex
1803
- defineSymbol(text, accent, "\u02dc", "\\~"); // tilde
1808
+ defineSymbol(text, accent, "\u007e", "\\~"); // tilde
1804
1809
  defineSymbol(text, accent, "\u02c9", "\\="); // macron
1805
1810
  defineSymbol(text, accent, "\u02d8", "\\u"); // breve
1806
1811
  defineSymbol(text, accent, "\u02d9", "\\."); // dot above
@@ -1812,7 +1817,7 @@ var temml = (function () {
1812
1817
  defineSymbol(math, accent, "\u02ca", "\\'"); // acute
1813
1818
  defineSymbol(math, accent, "\u02cb", "\\`"); // grave
1814
1819
  defineSymbol(math, accent, "\u02c6", "\\^"); // circumflex
1815
- defineSymbol(math, accent, "\u02dc", "\\~"); // tilde
1820
+ defineSymbol(math, accent, "\u007e", "\\~"); // tilde
1816
1821
  defineSymbol(math, accent, "\u02c9", "\\="); // macron
1817
1822
  defineSymbol(math, accent, "\u02d8", "\\u"); // breve
1818
1823
  defineSymbol(math, accent, "\u02d9", "\\."); // dot above
@@ -2469,46 +2474,61 @@ var temml = (function () {
2469
2474
  return math;
2470
2475
  }
2471
2476
 
2477
+ // Identify letters to which we'll attach a combining accent character
2472
2478
  const smalls = "acegıȷmnopqrsuvwxyzαγεηικμνοπρςστυχωϕ𝐚𝐜𝐞𝐠𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐮𝐯𝐰𝐱𝐲𝐳";
2473
- const talls = "ABCDEFGHIJKLMNOPQRSTUVWXYZbdfhkltΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩβδλζφθψ"
2474
- + "𝐀𝐁𝐂𝐃𝐄𝐅𝐆𝐇𝐈𝐉𝐊𝐋𝐌𝐍𝐎𝐏𝐐𝐑𝐒𝐓𝐔𝐕𝐖𝐗𝐘𝐙𝐛𝐝𝐟𝐡𝐤𝐥𝐭";
2475
- const longSmalls = new Set(["\\alpha", "\\gamma", "\\delta", "\\epsilon", "\\eta", "\\iota",
2476
- "\\kappa", "\\mu", "\\nu", "\\pi", "\\rho", "\\sigma", "\\tau", "\\upsilon", "\\chi", "\\psi",
2477
- "\\omega", "\\imath", "\\jmath"]);
2478
- const longTalls = new Set(["\\Gamma", "\\Delta", "\\Sigma", "\\Omega", "\\beta", "\\delta",
2479
- "\\lambda", "\\theta", "\\psi"]);
2479
+
2480
+ // From the KaTeX font metrics, identify letters whose accents need a italic correction.
2481
+ const smallNudge = "DHKLUcegorsuvxyzΠΥΨαδηιμνοτυχϵ";
2482
+ const mediumNudge = "BCEGIMNOPQRSTXZlpqtwΓΘΞΣΦΩβεζθξρςφψϑϕϱ";
2483
+ const largeNudge = "AFJdfΔΛ";
2480
2484
 
2481
2485
  const mathmlBuilder$a = (group, style) => {
2482
2486
  const accentNode = group.isStretchy
2483
2487
  ? stretchy.accentNode(group)
2484
2488
  : new mathMLTree.MathNode("mo", [makeText(group.label, group.mode)]);
2485
-
2486
- if (group.label === "\\vec") {
2487
- accentNode.style.transform = "scale(0.75) translate(10%, 30%)";
2488
- } else {
2489
- accentNode.style.mathStyle = "normal";
2490
- accentNode.style.mathDepth = "0";
2491
- if (needWebkitShift.has(group.label) && utils.isCharacterBox(group.base)) {
2492
- let shift = "";
2493
- const ch = group.base.text;
2494
- if (smalls.indexOf(ch) > -1 || longSmalls.has(ch)) { shift = "tml-xshift"; }
2495
- if (talls.indexOf(ch) > -1 || longTalls.has(ch)) { shift = "tml-capshift"; }
2496
- if (shift) { accentNode.classes.push(shift); }
2497
- }
2498
- }
2499
2489
  if (!group.isStretchy) {
2500
- accentNode.setAttribute("stretchy", "false");
2501
- }
2502
-
2503
- const node = new mathMLTree.MathNode((group.label === "\\c" ? "munder" : "mover"),
2504
- [buildGroup$1(group.base, style), accentNode]
2505
- );
2506
-
2490
+ accentNode.setAttribute("stretchy", "false"); // Keep Firefox from stretching \check
2491
+ }
2492
+ if (group.label !== "\\vec") {
2493
+ accentNode.style.mathDepth = "0"; // not scriptstyle
2494
+ // Don't use attribute accent="true" because MathML Core eliminates a needed space.
2495
+ }
2496
+ const tag = group.label === "\\c" ? "munder" : "mover";
2497
+ const needsWbkVertShift = needsWebkitVerticalShift.has(group.label);
2498
+ if (tag === "mover" && group.mode === "math" && (!group.isStretchy) && group.base.text
2499
+ && group.base.text.length === 1) {
2500
+ const text = group.base.text;
2501
+ const isVec = group.label === "\\vec";
2502
+ const vecPostfix = isVec === "\\vec" ? "-vec" : "";
2503
+ if (isVec) {
2504
+ accentNode.classes.push("tml-vec"); // Firefox sizing of \vec arrow
2505
+ }
2506
+ const wbkPostfix = isVec ? "-vec" : needsWbkVertShift ? "-acc" : "";
2507
+ if (smallNudge.indexOf(text) > -1) {
2508
+ accentNode.classes.push(`chr-sml${vecPostfix}`);
2509
+ accentNode.classes.push(`wbk-sml${wbkPostfix}`);
2510
+ } else if (mediumNudge.indexOf(text) > -1) {
2511
+ accentNode.classes.push(`chr-med${vecPostfix}`);
2512
+ accentNode.classes.push(`wbk-med${wbkPostfix}`);
2513
+ } else if (largeNudge.indexOf(text) > -1) {
2514
+ accentNode.classes.push(`chr-lrg${vecPostfix}`);
2515
+ accentNode.classes.push(`wbk-lrg${wbkPostfix}`);
2516
+ } else if (isVec) {
2517
+ accentNode.classes.push(`wbk-vec`);
2518
+ } else if (needsWbkVertShift) {
2519
+ accentNode.classes.push(`wbk-acc`);
2520
+ }
2521
+ } else if (needsWbkVertShift) {
2522
+ // text-mode accents
2523
+ accentNode.classes.push("wbk-acc");
2524
+ }
2525
+ const node = new mathMLTree.MathNode(tag, [buildGroup$1(group.base, style), accentNode]);
2507
2526
  return node;
2508
2527
  };
2509
2528
 
2510
2529
  const nonStretchyAccents = new Set([
2511
2530
  "\\acute",
2531
+ "\\check",
2512
2532
  "\\grave",
2513
2533
  "\\ddot",
2514
2534
  "\\dddot",
@@ -2523,7 +2543,7 @@ var temml = (function () {
2523
2543
  "\\mathring"
2524
2544
  ]);
2525
2545
 
2526
- const needWebkitShift = new Set([
2546
+ const needsWebkitVerticalShift = new Set([
2527
2547
  "\\acute",
2528
2548
  "\\bar",
2529
2549
  "\\breve",
@@ -2533,7 +2553,7 @@ var temml = (function () {
2533
2553
  "\\grave",
2534
2554
  "\\hat",
2535
2555
  "\\mathring",
2536
- "\\'", "\\^", "\\~", "\\=", "\\u", "\\.", '\\"', "\\r", "\\H", "\\v"
2556
+ "\\`", "\\'", "\\^", "\\=", "\\u", "\\.", '\\"', "\\r", "\\H", "\\v"
2537
2557
  ]);
2538
2558
 
2539
2559
  const combiningChar = {
@@ -2547,7 +2567,8 @@ var temml = (function () {
2547
2567
  '\\"': "\u0308",
2548
2568
  "\\r": "\u030A",
2549
2569
  "\\H": "\u030B",
2550
- "\\v": "\u030C"
2570
+ "\\v": "\u030C",
2571
+ "\\c": "\u0327"
2551
2572
  };
2552
2573
 
2553
2574
  // Accents
@@ -2592,8 +2613,8 @@ var temml = (function () {
2592
2613
  type: "accent",
2593
2614
  mode: context.parser.mode,
2594
2615
  label: context.funcName,
2595
- isStretchy: isStretchy,
2596
- base: base
2616
+ isStretchy,
2617
+ base
2597
2618
  };
2598
2619
  },
2599
2620
  mathmlBuilder: mathmlBuilder$a
@@ -2620,21 +2641,25 @@ var temml = (function () {
2620
2641
  }
2621
2642
 
2622
2643
  if (mode === "text" && base.text && base.text.length === 1
2623
- && context.funcName in combiningChar && smalls.indexOf(base.text) > -1) {
2644
+ && context.funcName in combiningChar && smalls.indexOf(base.text) > -1) {
2624
2645
  // Return a combining accent character
2625
2646
  return {
2626
2647
  type: "textord",
2627
2648
  mode: "text",
2628
2649
  text: base.text + combiningChar[context.funcName]
2629
2650
  }
2651
+ } else if (context.funcName === "\\c" && mode === "text" && base.text
2652
+ && base.text.length === 1) {
2653
+ // combining cedilla
2654
+ return { type: "textord", mode: "text", text: base.text + "\u0327" }
2630
2655
  } else {
2631
2656
  // Build up the accent
2632
2657
  return {
2633
2658
  type: "accent",
2634
- mode: mode,
2659
+ mode,
2635
2660
  label: context.funcName,
2636
2661
  isStretchy: false,
2637
- base: base
2662
+ base
2638
2663
  }
2639
2664
  }
2640
2665
  },
@@ -2892,12 +2917,17 @@ var temml = (function () {
2892
2917
  "\\xlongequal",
2893
2918
  "\\xtwoheadrightarrow",
2894
2919
  "\\xtwoheadleftarrow",
2895
- // The next 5 functions are here only to support mhchem
2920
+ "\\xtofrom", // expfeil
2921
+ "\\xleftrightharpoons", // mathtools
2922
+ "\\xrightleftharpoons", // mathtools
2923
+ // The next 7 functions are here only to support mhchem
2896
2924
  "\\yields",
2897
2925
  "\\yieldsLeft",
2898
2926
  "\\mesomerism",
2899
2927
  "\\longrightharpoonup",
2900
2928
  "\\longleftharpoondown",
2929
+ "\\yieldsLeftRight",
2930
+ "\\chemequilibrium",
2901
2931
  // The next 3 functions are here only to support the {CD} environment.
2902
2932
  "\\\\cdrightarrow",
2903
2933
  "\\\\cdleftarrow",
@@ -2928,26 +2958,15 @@ var temml = (function () {
2928
2958
  });
2929
2959
 
2930
2960
  const arrowComponent = {
2931
- "\\xtofrom": ["\\xrightarrow", "\\xleftarrow"],
2932
- "\\xleftrightharpoons": ["\\xleftharpoonup", "\\xrightharpoondown"],
2933
- "\\xrightleftharpoons": ["\\xrightharpoonup", "\\xleftharpoondown"],
2934
- "\\yieldsLeftRight": ["\\yields", "\\yieldsLeft"],
2935
- // The next three all get the same harpoon glyphs. Only the lengths and paddings differ.
2936
- "\\equilibrium": ["\\longrightharpoonup", "\\longleftharpoondown"],
2937
2961
  "\\equilibriumRight": ["\\longrightharpoonup", "\\eqleftharpoondown"],
2938
2962
  "\\equilibriumLeft": ["\\eqrightharpoonup", "\\longleftharpoondown"]
2939
2963
  };
2940
2964
 
2941
- // Browsers are not good at stretching a glyph that contains a pair of stacked arrows such as ⇄.
2942
- // So we stack a pair of single arrows.
2965
+ // Math fonts do not have a single glyph for these two mhchem functions.
2966
+ // So we stack a pair of single harpoons.
2943
2967
  defineFunction({
2944
2968
  type: "stackedArrow",
2945
2969
  names: [
2946
- "\\xtofrom", // expfeil
2947
- "\\xleftrightharpoons", // mathtools
2948
- "\\xrightleftharpoons", // mathtools
2949
- "\\yieldsLeftRight", // mhchem
2950
- "\\equilibrium", // mhchem
2951
2970
  "\\equilibriumRight",
2952
2971
  "\\equilibriumLeft"
2953
2972
  ],
@@ -3454,7 +3473,6 @@ var temml = (function () {
3454
3473
  alwaysHandleSupSub: true,
3455
3474
  parentIsSupSub: true,
3456
3475
  symbol: false,
3457
- stack: true,
3458
3476
  suppressBaseShift: true,
3459
3477
  body: [container]
3460
3478
  };
@@ -3462,6 +3480,7 @@ var temml = (function () {
3462
3480
  const mover = {
3463
3481
  type: "supsub", // We're using the MathML equivalent
3464
3482
  mode: "math", // of TeX \overset.
3483
+ stack: true,
3465
3484
  base: base, // That keeps the {pmatrix} aligned with
3466
3485
  sup: topWrapper, // the math centerline.
3467
3486
  sub: null
@@ -6275,7 +6294,8 @@ var temml = (function () {
6275
6294
  case "\\boxed":
6276
6295
  // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}} from amsmath.sty
6277
6296
  node.setAttribute("notation", "box");
6278
- node.classes.push("tml-box");
6297
+ node.style.padding = "padding: 3pt 0 3pt 0";
6298
+ node.style.border = "1px solid";
6279
6299
  node.setAttribute("scriptlevel", "0");
6280
6300
  node.setAttribute("displaystyle", "true");
6281
6301
  break
@@ -7688,7 +7708,9 @@ var temml = (function () {
7688
7708
  // (by rendering separately and with {}s before and after, and measuring
7689
7709
  // the change in spacing). We'll do roughly the same by detecting the
7690
7710
  // atom type directly.
7691
- const atom = arg.type === "ordgroup" && arg.body.length ? arg.body[0] : arg;
7711
+ const atom = arg.type === "ordgroup" && arg.body.length && arg.body.length === 1
7712
+ ? arg.body[0]
7713
+ : arg;
7692
7714
  if (atom.type === "atom" && (atom.family === "bin" || atom.family === "rel")) {
7693
7715
  return "m" + atom.family;
7694
7716
  } else {
@@ -7726,14 +7748,25 @@ var temml = (function () {
7726
7748
  const baseArg = args[1];
7727
7749
  const shiftedArg = args[0];
7728
7750
 
7751
+ let mclass;
7752
+ if (funcName !== "\\stackrel") {
7753
+ // LaTeX applies \binrel spacing to \overset and \underset.
7754
+ mclass = binrelClass(baseArg);
7755
+ } else {
7756
+ mclass = "mrel"; // for \stackrel
7757
+ }
7758
+
7759
+ const baseType = mclass === "mrel" || mclass === "mbin"
7760
+ ? "op"
7761
+ : "ordgroup";
7762
+
7729
7763
  const baseOp = {
7730
- type: "op",
7764
+ type: baseType,
7731
7765
  mode: baseArg.mode,
7732
7766
  limits: true,
7733
7767
  alwaysHandleSupSub: true,
7734
7768
  parentIsSupSub: false,
7735
7769
  symbol: false,
7736
- stack: true,
7737
7770
  suppressBaseShift: funcName !== "\\stackrel",
7738
7771
  body: ordargument(baseArg)
7739
7772
  };
@@ -7741,6 +7774,7 @@ var temml = (function () {
7741
7774
  return {
7742
7775
  type: "supsub",
7743
7776
  mode: shiftedArg.mode,
7777
+ stack: true,
7744
7778
  base: baseOp,
7745
7779
  sup: funcName === "\\underset" ? null : shiftedArg,
7746
7780
  sub: funcName === "\\underset" ? shiftedArg : null
@@ -8642,6 +8676,71 @@ var temml = (function () {
8642
8676
  }
8643
8677
  });
8644
8678
 
8679
+ const numRegEx = /^[0-9]$/;
8680
+ const unicodeNumSubs = {
8681
+ '0': '₀',
8682
+ '1': '₁',
8683
+ '2': '₂',
8684
+ '3': '₃',
8685
+ '4': '₄',
8686
+ '5': '₅',
8687
+ '6': '₆',
8688
+ '7': '₇',
8689
+ '8': '₈',
8690
+ '9': '₉'
8691
+ };
8692
+ const unicodeNumSups = {
8693
+ '0': '⁰',
8694
+ '1': '¹',
8695
+ '2': '²',
8696
+ '3': '³',
8697
+ '4': '⁴',
8698
+ '5': '⁵',
8699
+ '6': '⁶',
8700
+ '7': '⁷',
8701
+ '8': '⁸',
8702
+ '9': '⁹'
8703
+ };
8704
+
8705
+ defineFunction({
8706
+ type: "sfrac",
8707
+ names: ["\\sfrac"],
8708
+ props: {
8709
+ numArgs: 2,
8710
+ allowedInText: true,
8711
+ allowedInMath: true
8712
+ },
8713
+ handler({ parser }, args) {
8714
+ let numerator = "";
8715
+ for (const node of args[0].body) {
8716
+ if (node.type !== "textord" || !numRegEx.test(node.text)) {
8717
+ throw new ParseError("Numerator must be an integer.", node)
8718
+ }
8719
+ numerator += node.text;
8720
+ }
8721
+ let denominator = "";
8722
+ for (const node of args[1].body) {
8723
+ if (node.type !== "textord" || !numRegEx.test(node.text)) {
8724
+ throw new ParseError("Denominator must be an integer.", node)
8725
+ }
8726
+ denominator += node.text;
8727
+ }
8728
+ return {
8729
+ type: "sfrac",
8730
+ mode: parser.mode,
8731
+ numerator,
8732
+ denominator
8733
+ };
8734
+ },
8735
+ mathmlBuilder(group, style) {
8736
+ const numerator = group.numerator.split('').map(c => unicodeNumSups[c]).join('');
8737
+ const denominator = group.denominator.split('').map(c => unicodeNumSubs[c]).join('');
8738
+ // Use a fraction slash.
8739
+ const text = new mathMLTree.TextNode(numerator + "\u2044" + denominator, group.mode, style);
8740
+ return new mathMLTree.MathNode("mn", [text], ["special-fraction"])
8741
+ }
8742
+ });
8743
+
8645
8744
  // The size mappings are taken from TeX with \normalsize=10pt.
8646
8745
  // We don't have to track script level. MathML does that.
8647
8746
  const sizeMap = {
@@ -8859,6 +8958,11 @@ var temml = (function () {
8859
8958
  // Helpers
8860
8959
  const symbolRegEx = /^m(over|under|underover)$/;
8861
8960
 
8961
+ // From the KaTeX font metrics, identify letters that encroach on a superscript.
8962
+ const smallPad = "DHKLUcegorsuvxyzΠΥΨαδηιμνοτυχϵ";
8963
+ const mediumPad = "BCEFGIMNOPQRSTXZlpqtwΓΘΞΣΦΩβεζθξρςφψϑϕϱ";
8964
+ const largePad = "AJdfΔΛ";
8965
+
8862
8966
  // Super scripts and subscripts, whose precise placement can depend on other
8863
8967
  // functions that precede them.
8864
8968
  defineFunctionBuilders({
@@ -8880,7 +8984,7 @@ var temml = (function () {
8880
8984
  }
8881
8985
  }
8882
8986
 
8883
- if (group.base && !group.base.stack &&
8987
+ if (group.base && !group.stack &&
8884
8988
  (group.base.type === "op" || group.base.type === "operatorname")) {
8885
8989
  group.base.parentIsSupSub = true;
8886
8990
  appendApplyFunction = !group.base.symbol;
@@ -8888,7 +8992,7 @@ var temml = (function () {
8888
8992
  needsLeadingSpace = group.base.needsLeadingSpace;
8889
8993
  }
8890
8994
 
8891
- const children = group.base && group.base.stack
8995
+ const children = group.stack && group.base.body.length === 1
8892
8996
  ? [buildGroup$1(group.base.body[0], style)]
8893
8997
  : [buildGroup$1(group.base, style)];
8894
8998
 
@@ -8908,11 +9012,16 @@ var temml = (function () {
8908
9012
  if (group.sup) {
8909
9013
  const sup = buildGroup$1(group.sup, childStyle);
8910
9014
  if (style.level === 3) { sup.setAttribute("scriptlevel", "2"); }
8911
- const testNode = sup.type === "mrow" ? sup.children[0] : sup;
8912
- if ((testNode && testNode.type === "mo" && testNode.classes.includes("tml-prime"))
8913
- && group.base && group.base.text && "fF".indexOf(group.base.text) > -1) {
8914
- // Chromium does not address italic correction on prime. Prevent f′ from overlapping.
8915
- testNode.classes.push("prime-pad");
9015
+ if (group.base && group.base.text && group.base.text.length === 1) {
9016
+ // Make an italic correction on the superscript.
9017
+ const text = group.base.text;
9018
+ if (smallPad.indexOf(text) > -1) {
9019
+ sup.classes.push("tml-sml-pad");
9020
+ } else if (mediumPad.indexOf(text) > -1) {
9021
+ sup.classes.push("tml-med-pad");
9022
+ } else if (largePad.indexOf(text) > -1) {
9023
+ sup.classes.push("tml-lrg-pad");
9024
+ }
8916
9025
  }
8917
9026
  children.push(sup);
8918
9027
  }
@@ -8941,7 +9050,9 @@ var temml = (function () {
8941
9050
  }
8942
9051
  } else if (!group.sup) {
8943
9052
  const base = group.base;
8944
- if (
9053
+ if (group.stack) {
9054
+ nodeType = "munder";
9055
+ } else if (
8945
9056
  base &&
8946
9057
  base.type === "op" &&
8947
9058
  base.limits &&
@@ -11986,7 +12097,7 @@ var temml = (function () {
11986
12097
  * https://mit-license.org/
11987
12098
  */
11988
12099
 
11989
- const version = "0.11.07";
12100
+ const version = "0.11.08";
11990
12101
 
11991
12102
  function postProcess(block) {
11992
12103
  const labelMap = {};