temml 0.10.22 → 0.10.23

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
@@ -1024,6 +1024,7 @@ defineSymbol(math, mathord, "\u2609", "\\astrosun", true);
1024
1024
  defineSymbol(math, mathord, "\u263c", "\\sun", true);
1025
1025
  defineSymbol(math, mathord, "\u263e", "\\leftmoon", true);
1026
1026
  defineSymbol(math, mathord, "\u263d", "\\rightmoon", true);
1027
+ defineSymbol(math, mathord, "\u2295", "\\Earth");
1027
1028
 
1028
1029
  // AMS Negated Binary Relations
1029
1030
  defineSymbol(math, rel, "\u226e", "\\nless", true);
@@ -1251,6 +1252,8 @@ defineSymbol(math, bin, "\u27d5", "\\leftouterjoin", true);
1251
1252
  defineSymbol(math, bin, "\u27d6", "\\rightouterjoin", true);
1252
1253
  defineSymbol(math, bin, "\u27d7", "\\fullouterjoin", true);
1253
1254
 
1255
+ defineSymbol(math, bin, "\u2238", "\\dotminus", true); // stix
1256
+
1254
1257
  // AMS Arrows
1255
1258
  // Note: unicode-math maps \u21e2 to their own function \rightdasharrow.
1256
1259
  // We'll map it to AMS function \dashrightarrow. It produces the same atom.
@@ -2019,9 +2022,11 @@ const consolidateText = mrow => {
2019
2022
  };
2020
2023
 
2021
2024
  const numberRegEx$1 = /^[0-9]$/;
2022
- const isCommaOrDot = node => {
2023
- return (node.type === "atom" && node.text === ",") ||
2024
- (node.type === "textord" && node.text === ".")
2025
+ const isDotOrComma = (node, followingNode) => {
2026
+ return ((node.type === "textord" && node.text === ".") ||
2027
+ (node.type === "atom" && node.text === ",")) &&
2028
+ // Don't consolidate if there is a space after the comma.
2029
+ node.loc && followingNode.loc && node.loc.end === followingNode.loc.start
2025
2030
  };
2026
2031
  const consolidateNumbers = expression => {
2027
2032
  // Consolidate adjacent numbers. We want to return <mn>1,506.3</mn>,
@@ -2044,7 +2049,8 @@ const consolidateNumbers = expression => {
2044
2049
 
2045
2050
  // Determine if numeral groups are separated by a comma or dot.
2046
2051
  for (let i = nums.length - 1; i > 0; i--) {
2047
- if (nums[i - 1].end === nums[i].start - 2 && isCommaOrDot(expression[nums[i].start - 1])) {
2052
+ if (nums[i - 1].end === nums[i].start - 2 &&
2053
+ isDotOrComma(expression[nums[i].start - 1], expression[nums[i].start])) {
2048
2054
  // Merge the two groups.
2049
2055
  nums[i - 1].end = nums[i].end;
2050
2056
  nums.splice(i, 1);
@@ -5110,6 +5116,21 @@ defineFunction({
5110
5116
  }
5111
5117
  });
5112
5118
 
5119
+ const isLongVariableName = (group, font) => {
5120
+ if (font !== "mathrm" || group.body.type !== "ordgroup" || group.body.body.length === 1) {
5121
+ return false
5122
+ }
5123
+ if (group.body.body[0].type !== "mathord") { return false }
5124
+ for (let i = 1; i < group.body.body.length; i++) {
5125
+ const parseNodeType = group.body.body[i].type;
5126
+ if (!(parseNodeType === "mathord" ||
5127
+ (parseNodeType === "textord" && !isNaN(group.body.body[i].text)))) {
5128
+ return false
5129
+ }
5130
+ }
5131
+ return true
5132
+ };
5133
+
5113
5134
  const mathmlBuilder$6 = (group, style) => {
5114
5135
  const font = group.font;
5115
5136
  const newStyle = style.withFont(font);
@@ -5121,6 +5142,20 @@ const mathmlBuilder$6 = (group, style) => {
5121
5142
  return mathGroup
5122
5143
  }
5123
5144
  // Check if it is possible to consolidate elements into a single <mi> element.
5145
+ if (isLongVariableName(group, font)) {
5146
+ // This is a \mathrm{…} group. It gets special treatment because symbolsOrd.js
5147
+ // wraps <mi> elements with <mrow>s to work around a Firefox bug.
5148
+ const mi = mathGroup.children[0].children[0];
5149
+ delete mi.attributes.mathvariant;
5150
+ for (let i = 1; i < mathGroup.children.length; i++) {
5151
+ mi.children[0].text += mathGroup.children[i].type === "mn"
5152
+ ? mathGroup.children[i].children[0].text
5153
+ : mathGroup.children[i].children[0].children[0].text;
5154
+ }
5155
+ // Wrap in a <mrow> to prevent the same Firefox bug.
5156
+ const bogus = new mathMLTree.MathNode("mtext", new mathMLTree.TextNode("\u200b"));
5157
+ return new mathMLTree.MathNode("mrow", [bogus, mi])
5158
+ }
5124
5159
  let canConsolidate = mathGroup.children[0].type === "mo";
5125
5160
  for (let i = 1; i < mathGroup.children.length; i++) {
5126
5161
  if (mathGroup.children[i].type === "mo" && font === "boldsymbol") {
@@ -13186,7 +13221,7 @@ class Style {
13186
13221
  * https://mit-license.org/
13187
13222
  */
13188
13223
 
13189
- const version = "0.10.22";
13224
+ const version = "0.10.23";
13190
13225
 
13191
13226
  function postProcess(block) {
13192
13227
  const labelMap = {};
@@ -14,7 +14,7 @@
14
14
  * https://mit-license.org/
15
15
  */
16
16
 
17
- const version = "0.10.22";
17
+ const version = "0.10.23";
18
18
 
19
19
  function postProcess(block) {
20
20
  const labelMap = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "temml",
3
- "version": "0.10.22",
3
+ "version": "0.10.23",
4
4
  "description": "TeX to MathML conversion in JavaScript.",
5
5
  "main": "dist/temml.js",
6
6
  "engines": {
@@ -80,9 +80,11 @@ export const consolidateText = mrow => {
80
80
  }
81
81
 
82
82
  const numberRegEx = /^[0-9]$/
83
- const isCommaOrDot = node => {
84
- return (node.type === "atom" && node.text === ",") ||
85
- (node.type === "textord" && node.text === ".")
83
+ const isDotOrComma = (node, followingNode) => {
84
+ return ((node.type === "textord" && node.text === ".") ||
85
+ (node.type === "atom" && node.text === ",")) &&
86
+ // Don't consolidate if there is a space after the comma.
87
+ node.loc && followingNode.loc && node.loc.end === followingNode.loc.start
86
88
  }
87
89
  const consolidateNumbers = expression => {
88
90
  // Consolidate adjacent numbers. We want to return <mn>1,506.3</mn>,
@@ -105,7 +107,8 @@ const consolidateNumbers = expression => {
105
107
 
106
108
  // Determine if numeral groups are separated by a comma or dot.
107
109
  for (let i = nums.length - 1; i > 0; i--) {
108
- if (nums[i - 1].end === nums[i].start - 2 && isCommaOrDot(expression[nums[i].start - 1])) {
110
+ if (nums[i - 1].end === nums[i].start - 2 &&
111
+ isDotOrComma(expression[nums[i].start - 1], expression[nums[i].start])) {
109
112
  // Merge the two groups.
110
113
  nums[i - 1].end = nums[i].end
111
114
  nums.splice(i, 1)
@@ -2,6 +2,21 @@ import defineFunction, { normalizeArgument } from "../defineFunction"
2
2
  import * as mml from "../buildMathML"
3
3
  import mathMLTree from "../mathMLTree"
4
4
 
5
+ const isLongVariableName = (group, font) => {
6
+ if (font !== "mathrm" || group.body.type !== "ordgroup" || group.body.body.length === 1) {
7
+ return false
8
+ }
9
+ if (group.body.body[0].type !== "mathord") { return false }
10
+ for (let i = 1; i < group.body.body.length; i++) {
11
+ const parseNodeType = group.body.body[i].type
12
+ if (!(parseNodeType === "mathord" ||
13
+ (parseNodeType === "textord" && !isNaN(group.body.body[i].text)))) {
14
+ return false
15
+ }
16
+ }
17
+ return true
18
+ }
19
+
5
20
  const mathmlBuilder = (group, style) => {
6
21
  const font = group.font
7
22
  const newStyle = style.withFont(font)
@@ -13,6 +28,20 @@ const mathmlBuilder = (group, style) => {
13
28
  return mathGroup
14
29
  }
15
30
  // Check if it is possible to consolidate elements into a single <mi> element.
31
+ if (isLongVariableName(group, font)) {
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];
35
+ delete mi.attributes.mathvariant
36
+ for (let i = 1; i < mathGroup.children.length; i++) {
37
+ mi.children[0].text += mathGroup.children[i].type === "mn"
38
+ ? mathGroup.children[i].children[0].text
39
+ : mathGroup.children[i].children[0].children[0].text
40
+ }
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])
44
+ }
16
45
  let canConsolidate = mathGroup.children[0].type === "mo"
17
46
  for (let i = 1; i < mathGroup.children.length; i++) {
18
47
  if (mathGroup.children[i].type === "mo" && font === "boldsymbol") {
@@ -25,7 +54,7 @@ const mathmlBuilder = (group, style) => {
25
54
  }
26
55
  if (!canConsolidate) { return mathGroup }
27
56
  // Consolidate the <mi> elements.
28
- const mi = mathGroup.children[0]
57
+ const mi = mathGroup.children[0];
29
58
  for (let i = 1; i < mathGroup.children.length; i++) {
30
59
  mi.children.push(mathGroup.children[i].children[0])
31
60
  }
@@ -8,7 +8,7 @@
8
8
  * https://mit-license.org/
9
9
  */
10
10
 
11
- export const version = "0.10.22";
11
+ export const version = "0.10.23";
12
12
 
13
13
  export function postProcess(block) {
14
14
  const labelMap = {}
package/src/symbols.js CHANGED
@@ -218,6 +218,7 @@ defineSymbol(math, mathord, "\u2609", "\\astrosun", true);
218
218
  defineSymbol(math, mathord, "\u263c", "\\sun", true);
219
219
  defineSymbol(math, mathord, "\u263e", "\\leftmoon", true);
220
220
  defineSymbol(math, mathord, "\u263d", "\\rightmoon", true);
221
+ defineSymbol(math, mathord, "\u2295", "\\Earth");
221
222
 
222
223
  // AMS Negated Binary Relations
223
224
  defineSymbol(math, rel, "\u226e", "\\nless", true);
@@ -445,6 +446,8 @@ defineSymbol(math, bin, "\u27d5", "\\leftouterjoin", true);
445
446
  defineSymbol(math, bin, "\u27d6", "\\rightouterjoin", true);
446
447
  defineSymbol(math, bin, "\u27d7", "\\fullouterjoin", true);
447
448
 
449
+ defineSymbol(math, bin, "\u2238", "\\dotminus", true); // stix
450
+
448
451
  // AMS Arrows
449
452
  // Note: unicode-math maps \u21e2 to their own function \rightdasharrow.
450
453
  // We'll map it to AMS function \dashrightarrow. It produces the same atom.