temml 0.11.1 → 0.11.2

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
@@ -1770,7 +1770,7 @@ defineSymbol(text, accent, "\u02d9", "\\."); // dot above
1770
1770
  defineSymbol(text, accent, "\u00b8", "\\c"); // cedilla
1771
1771
  defineSymbol(text, accent, "\u02da", "\\r"); // ring above
1772
1772
  defineSymbol(text, accent, "\u02c7", "\\v"); // caron
1773
- defineSymbol(text, accent, "\u00a8", '\\"'); // diaresis
1773
+ defineSymbol(text, accent, "\u00a8", '\\"'); // diaeresis
1774
1774
  defineSymbol(text, accent, "\u02dd", "\\H"); // double acute
1775
1775
  defineSymbol(math, accent, "\u02ca", "\\'"); // acute
1776
1776
  defineSymbol(math, accent, "\u02cb", "\\`"); // grave
@@ -1782,7 +1782,7 @@ defineSymbol(math, accent, "\u02d9", "\\."); // dot above
1782
1782
  defineSymbol(math, accent, "\u00b8", "\\c"); // cedilla
1783
1783
  defineSymbol(math, accent, "\u02da", "\\r"); // ring above
1784
1784
  defineSymbol(math, accent, "\u02c7", "\\v"); // caron
1785
- defineSymbol(math, accent, "\u00a8", '\\"'); // diaresis
1785
+ defineSymbol(math, accent, "\u00a8", '\\"'); // diaeresis
1786
1786
  defineSymbol(math, accent, "\u02dd", "\\H"); // double acute
1787
1787
 
1788
1788
  // These ligatures are detected and created in Parser.js's `formLigatures`.
@@ -2750,17 +2750,17 @@ const calculateSize = function(sizeValue, style) {
2750
2750
 
2751
2751
  // Helper functions
2752
2752
 
2753
- const padding$2 = width => {
2753
+ const padding$1 = width => {
2754
2754
  const node = new mathMLTree.MathNode("mspace");
2755
2755
  node.setAttribute("width", width + "em");
2756
2756
  return node
2757
2757
  };
2758
2758
 
2759
2759
  const paddedNode = (group, lspace = 0.3, rspace = 0, mustSmash = false) => {
2760
- if (group == null && rspace === 0) { return padding$2(lspace) }
2760
+ if (group == null && rspace === 0) { return padding$1(lspace) }
2761
2761
  const row = group ? [group] : [];
2762
- if (lspace !== 0) { row.unshift(padding$2(lspace)); }
2763
- if (rspace > 0) { row.push(padding$2(rspace)); }
2762
+ if (lspace !== 0) { row.unshift(padding$1(lspace)); }
2763
+ if (rspace > 0) { row.push(padding$1(rspace)); }
2764
2764
  if (mustSmash) {
2765
2765
  // Used for the bottom arrow in a {CD} environment
2766
2766
  const mpadded = new mathMLTree.MathNode("mpadded", row);
@@ -2887,8 +2887,8 @@ defineFunction({
2887
2887
  const node = munderoverNode(group.name, group.body, group.below, style);
2888
2888
  // Create operator spacing for a relation.
2889
2889
  const row = [node];
2890
- row.unshift(padding$2(0.2778));
2891
- row.push(padding$2(0.2778));
2890
+ row.unshift(padding$1(0.2778));
2891
+ row.push(padding$1(0.2778));
2892
2892
  return new mathMLTree.MathNode("mrow", row)
2893
2893
  }
2894
2894
  });
@@ -2963,13 +2963,13 @@ defineFunction({
2963
2963
  botNode.setAttribute("width", "0.5em");
2964
2964
  wrapper = new mathMLTree.MathNode(
2965
2965
  "mpadded",
2966
- [padding$2(0.2778), botNode, raiseNode, padding$2(0.2778)]
2966
+ [padding$1(0.2778), botNode, raiseNode, padding$1(0.2778)]
2967
2967
  );
2968
2968
  } else {
2969
2969
  raiseNode.setAttribute("width", (group.name === "\\equilibriumRight" ? "0.5em" : "0"));
2970
2970
  wrapper = new mathMLTree.MathNode(
2971
2971
  "mpadded",
2972
- [padding$2(0.2778), raiseNode, botArrow, padding$2(0.2778)]
2972
+ [padding$1(0.2778), raiseNode, botArrow, padding$1(0.2778)]
2973
2973
  );
2974
2974
  }
2975
2975
 
@@ -8081,7 +8081,7 @@ defineFunction({
8081
8081
  }
8082
8082
  });
8083
8083
 
8084
- const padding$1 = _ => {
8084
+ const padding = _ => {
8085
8085
  const node = new mathMLTree.MathNode("mspace");
8086
8086
  node.setAttribute("width", "3pt");
8087
8087
  return node
@@ -8094,9 +8094,9 @@ const mathmlBuilder$7 = (group, style) => {
8094
8094
  // Firefox does not reliably add side padding.
8095
8095
  // Insert <mspace>
8096
8096
  node = new mathMLTree.MathNode("mrow", [
8097
- padding$1(),
8097
+ padding(),
8098
8098
  buildGroup$1(group.body, style),
8099
- padding$1()
8099
+ padding()
8100
8100
  ]);
8101
8101
  } else {
8102
8102
  node = new mathMLTree.MathNode("menclose", [buildGroup$1(group.body, style)]);
@@ -9496,12 +9496,6 @@ defineFunction({
9496
9496
 
9497
9497
  const textAtomTypes = ["text", "textord", "mathord", "atom"];
9498
9498
 
9499
- const padding = width => {
9500
- const node = new mathMLTree.MathNode("mspace");
9501
- node.setAttribute("width", width + "em");
9502
- return node
9503
- };
9504
-
9505
9499
  function mathmlBuilder$3(group, style) {
9506
9500
  let node;
9507
9501
  const inner = buildExpression(group.body, style);
@@ -9537,17 +9531,17 @@ function mathmlBuilder$3(group, style) {
9537
9531
  if (doSpacing ) {
9538
9532
  if (group.mclass === "mbin") {
9539
9533
  // medium space
9540
- node.children.unshift(padding(0.2222));
9541
- node.children.push(padding(0.2222));
9534
+ node.children.unshift(padding$1(0.2222));
9535
+ node.children.push(padding$1(0.2222));
9542
9536
  } else if (group.mclass === "mrel") {
9543
9537
  // thickspace
9544
- node.children.unshift(padding(0.2778));
9545
- node.children.push(padding(0.2778));
9538
+ node.children.unshift(padding$1(0.2778));
9539
+ node.children.push(padding$1(0.2778));
9546
9540
  } else if (group.mclass === "mpunct") {
9547
- node.children.push(padding(0.1667));
9541
+ node.children.push(padding$1(0.1667));
9548
9542
  } else if (group.mclass === "minner") {
9549
- node.children.unshift(padding(0.0556)); // 1 mu is the most likely option
9550
- node.children.push(padding(0.0556));
9543
+ node.children.unshift(padding$1(0.0556)); // 1 mu is the most likely option
9544
+ node.children.push(padding$1(0.0556));
9551
9545
  }
9552
9546
  }
9553
9547
  } else {
@@ -9617,14 +9611,19 @@ defineFunction({
9617
9611
  break
9618
9612
  }
9619
9613
  }
9620
- return {
9621
- type: "mclass",
9622
- mode: parser.mode,
9623
- mclass: "m" + funcName.slice(5),
9624
- body: ordargument(mustPromote ? mord : body),
9625
- isCharacterBox,
9626
- mustPromote
9627
- };
9614
+ if (mustPromote && funcName === "\\mathord" && mord.type === "mathord"
9615
+ && mord.text.length > 1) {
9616
+ return mord
9617
+ } else {
9618
+ return {
9619
+ type: "mclass",
9620
+ mode: parser.mode,
9621
+ mclass: "m" + funcName.slice(5),
9622
+ body: ordargument(mustPromote ? mord : body),
9623
+ isCharacterBox,
9624
+ mustPromote
9625
+ };
9626
+ }
9628
9627
  },
9629
9628
  mathmlBuilder: mathmlBuilder$3
9630
9629
  });
@@ -10186,7 +10185,7 @@ const mathmlBuilder$1 = (group, style) => {
10186
10185
  for (let i = 0; i < expression.length; i++) {
10187
10186
  let node = expression[i];
10188
10187
  if (node instanceof mathMLTree.MathNode) {
10189
- if (node.type === "mrow" && node.children.length === 1 &&
10188
+ if ((node.type === "mrow" || node.type === "mpadded") && node.children.length === 1 &&
10190
10189
  node.children[0] instanceof mathMLTree.MathNode) {
10191
10190
  node = node.children[0];
10192
10191
  }
@@ -10804,7 +10803,7 @@ const symbolRegEx = /^m(over|under|underover)$/;
10804
10803
  defineFunctionBuilders({
10805
10804
  type: "supsub",
10806
10805
  mathmlBuilder(group, style) {
10807
- // Is the inner group a relevant horizonal brace?
10806
+ // Is the inner group a relevant horizontal brace?
10808
10807
  let isBrace = false;
10809
10808
  let isOver;
10810
10809
  let isSup;
@@ -10987,6 +10986,14 @@ defineFunctionBuilders({
10987
10986
  // ":" is not in the MathML operator dictionary. Give it BIN spacing.
10988
10987
  node.attributes.lspace = "0.2222em";
10989
10988
  node.attributes.rspace = "0.2222em";
10989
+ } else if (group.needsSpacing) {
10990
+ // Fix a MathML bug that occurs when a <mo> is between two <mtext> elements.
10991
+ if (group.family === "bin") {
10992
+ return new mathMLTree.MathNode("mrow", [padding$1(0.222), node, padding$1(0.222)])
10993
+ } else {
10994
+ // REL spacing
10995
+ return new mathMLTree.MathNode("mrow", [padding$1(0.2778), node, padding$1(0.2778)])
10996
+ }
10990
10997
  }
10991
10998
  return node;
10992
10999
  }
@@ -11354,7 +11361,9 @@ defineFunctionBuilders({
11354
11361
  node.setAttribute("mathvariant", "normal");
11355
11362
  if (text.text.length === 1) {
11356
11363
  // A Firefox bug will apply spacing here, but there should be none. Fix it.
11357
- node = new mathMLTree.MathNode("mrow", [node]);
11364
+ node = new mathMLTree.MathNode("mpadded", [node]);
11365
+ node.setAttribute("lspace", "0");
11366
+ node.setAttribute("rspace", "0");
11358
11367
  }
11359
11368
  }
11360
11369
  return node
@@ -12733,6 +12742,7 @@ var unicodeSymbols = {
12733
12742
 
12734
12743
  const binLeftCancellers = ["bin", "op", "open", "punct", "rel"];
12735
12744
  const sizeRegEx = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/;
12745
+ const textRegEx = /^ *\\text/;
12736
12746
 
12737
12747
  /**
12738
12748
  * This file contains the parser used to parse out a TeX expression from the
@@ -13643,6 +13653,11 @@ class Parser {
13643
13653
  loc,
13644
13654
  text
13645
13655
  };
13656
+ if ((family === "rel" || family === "bin") && this.prevAtomType === "text") {
13657
+ if (textRegEx.test(loc.lexer.input.slice(loc.end))) {
13658
+ s.needsSpacing = true; // Fix a MathML bug.
13659
+ }
13660
+ }
13646
13661
  } else {
13647
13662
  if (asciiFromScript[text]) {
13648
13663
  // Unicode 14 disambiguates chancery from roundhand.
@@ -13900,7 +13915,7 @@ class Style {
13900
13915
  * https://mit-license.org/
13901
13916
  */
13902
13917
 
13903
- const version = "0.11.01";
13918
+ const version = "0.11.02";
13904
13919
 
13905
13920
  function postProcess(block) {
13906
13921
  const labelMap = {};
@@ -11,7 +11,7 @@
11
11
  * https://mit-license.org/
12
12
  */
13
13
 
14
- const version = "0.11.01";
14
+ const version = "0.11.02";
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.01",
3
+ "version": "0.11.02",
4
4
  "description": "TeX to MathML conversion in JavaScript.",
5
5
  "main": "dist/temml.js",
6
6
  "engines": {
package/src/Parser.js CHANGED
@@ -17,6 +17,7 @@ import unicodeSymbols from /*preval*/ "./unicodeSymbols";
17
17
 
18
18
  const binLeftCancellers = ["bin", "op", "open", "punct", "rel"];
19
19
  const sizeRegEx = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/
20
+ const textRegEx = /^ *\\text/
20
21
 
21
22
  /**
22
23
  * This file contains the parser used to parse out a TeX expression from the
@@ -926,7 +927,12 @@ export default class Parser {
926
927
  family,
927
928
  loc,
928
929
  text
929
- };
930
+ }
931
+ if ((family === "rel" || family === "bin") && this.prevAtomType === "text") {
932
+ if (textRegEx.test(loc.lexer.input.slice(loc.end))) {
933
+ s.needsSpacing = true // Fix a MathML bug.
934
+ }
935
+ }
930
936
  } else {
931
937
  if (asciiFromScript[text]) {
932
938
  // Unicode 14 disambiguates chancery from roundhand.
@@ -6,7 +6,7 @@ import * as mml from "../buildMathML";
6
6
 
7
7
  // Helper functions
8
8
 
9
- const padding = width => {
9
+ export const padding = width => {
10
10
  const node = new mathMLTree.MathNode("mspace")
11
11
  node.setAttribute("width", width + "em")
12
12
  return node
@@ -1,18 +1,13 @@
1
1
  import defineFunction, { ordargument } from "../defineFunction";
2
2
  import symbols from "../symbols";
3
3
  import mathMLTree from "../mathMLTree";
4
- import utils from "../utils";
4
+ import utils from "../utils.js"
5
+ import { padding } from "./arrow";
5
6
 
6
7
  import * as mml from "../buildMathML";
7
8
 
8
9
  const textAtomTypes = ["text", "textord", "mathord", "atom"]
9
10
 
10
- const padding = width => {
11
- const node = new mathMLTree.MathNode("mspace")
12
- node.setAttribute("width", width + "em")
13
- return node
14
- }
15
-
16
11
  function mathmlBuilder(group, style) {
17
12
  let node;
18
13
  const inner = mml.buildExpression(group.body, style);
@@ -128,14 +123,19 @@ defineFunction({
128
123
  break
129
124
  }
130
125
  }
131
- return {
132
- type: "mclass",
133
- mode: parser.mode,
134
- mclass: "m" + funcName.slice(5),
135
- body: ordargument(mustPromote ? mord : body),
136
- isCharacterBox,
137
- mustPromote
138
- };
126
+ if (mustPromote && funcName === "\\mathord" && mord.type === "mathord"
127
+ && mord.text.length > 1) {
128
+ return mord
129
+ } else {
130
+ return {
131
+ type: "mclass",
132
+ mode: parser.mode,
133
+ mclass: "m" + funcName.slice(5),
134
+ body: ordargument(mustPromote ? mord : body),
135
+ isCharacterBox,
136
+ mustPromote
137
+ };
138
+ }
139
139
  },
140
140
  mathmlBuilder
141
141
  });
@@ -19,7 +19,7 @@ const mathmlBuilder = (group, style) => {
19
19
  for (let i = 0; i < expression.length; i++) {
20
20
  let node = expression[i]
21
21
  if (node instanceof mathMLTree.MathNode) {
22
- if (node.type === "mrow" && node.children.length === 1 &&
22
+ if ((node.type === "mrow" || node.type === "mpadded") && node.children.length === 1 &&
23
23
  node.children[0] instanceof mathMLTree.MathNode) {
24
24
  node = node.children[0]
25
25
  }
@@ -19,7 +19,7 @@ const symbolRegEx = /^m(over|under|underover)$/
19
19
  defineFunctionBuilders({
20
20
  type: "supsub",
21
21
  mathmlBuilder(group, style) {
22
- // Is the inner group a relevant horizonal brace?
22
+ // Is the inner group a relevant horizontal brace?
23
23
  let isBrace = false
24
24
  let isOver
25
25
  let isSup
@@ -1,6 +1,7 @@
1
1
  import { defineFunctionBuilders } from "../defineFunction";
2
2
  import mathMLTree from "../mathMLTree";
3
3
  import * as mml from "../buildMathML";
4
+ import { padding } from "./arrow";
4
5
 
5
6
  // Operator ParseNodes created in Parser.js from symbol Groups in src/symbols.js.
6
7
 
@@ -47,6 +48,14 @@ defineFunctionBuilders({
47
48
  // ":" is not in the MathML operator dictionary. Give it BIN spacing.
48
49
  node.attributes.lspace = "0.2222em"
49
50
  node.attributes.rspace = "0.2222em"
51
+ } else if (group.needsSpacing) {
52
+ // Fix a MathML bug that occurs when a <mo> is between two <mtext> elements.
53
+ if (group.family === "bin") {
54
+ return new mathMLTree.MathNode("mrow", [padding(0.222), node, padding(0.222)])
55
+ } else {
56
+ // REL spacing
57
+ return new mathMLTree.MathNode("mrow", [padding(0.2778), node, padding(0.2778)])
58
+ }
50
59
  }
51
60
  return node;
52
61
  }
@@ -41,7 +41,9 @@ defineFunctionBuilders({
41
41
  node.setAttribute("mathvariant", "normal")
42
42
  if (text.text.length === 1) {
43
43
  // A Firefox bug will apply spacing here, but there should be none. Fix it.
44
- node = new mathMLTree.MathNode("mrow", [node])
44
+ node = new mathMLTree.MathNode("mpadded", [node])
45
+ node.setAttribute("lspace", "0")
46
+ node.setAttribute("rspace", "0")
45
47
  }
46
48
  }
47
49
  return node
@@ -5,7 +5,7 @@
5
5
  * https://mit-license.org/
6
6
  */
7
7
 
8
- export const version = "0.11.01";
8
+ export const version = "0.11.02";
9
9
 
10
10
  export function postProcess(block) {
11
11
  const labelMap = {}
package/src/symbols.js CHANGED
@@ -895,7 +895,7 @@ defineSymbol(text, accent, "\u02d9", "\\."); // dot above
895
895
  defineSymbol(text, accent, "\u00b8", "\\c"); // cedilla
896
896
  defineSymbol(text, accent, "\u02da", "\\r"); // ring above
897
897
  defineSymbol(text, accent, "\u02c7", "\\v"); // caron
898
- defineSymbol(text, accent, "\u00a8", '\\"'); // diaresis
898
+ defineSymbol(text, accent, "\u00a8", '\\"'); // diaeresis
899
899
  defineSymbol(text, accent, "\u02dd", "\\H"); // double acute
900
900
  defineSymbol(math, accent, "\u02ca", "\\'"); // acute
901
901
  defineSymbol(math, accent, "\u02cb", "\\`"); // grave
@@ -907,7 +907,7 @@ defineSymbol(math, accent, "\u02d9", "\\."); // dot above
907
907
  defineSymbol(math, accent, "\u00b8", "\\c"); // cedilla
908
908
  defineSymbol(math, accent, "\u02da", "\\r"); // ring above
909
909
  defineSymbol(math, accent, "\u02c7", "\\v"); // caron
910
- defineSymbol(math, accent, "\u00a8", '\\"'); // diaresis
910
+ defineSymbol(math, accent, "\u00a8", '\\"'); // diaeresis
911
911
  defineSymbol(math, accent, "\u02dd", "\\H"); // double acute
912
912
 
913
913
  // These ligatures are detected and created in Parser.js's `formLigatures`.