temml 0.9.1 → 0.9.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
@@ -2077,8 +2077,6 @@ function buildMathML(tree, texExpression, style, settings) {
2077
2077
  let wrapper = expression.length === 1 && tag === null && (n1 instanceof MathNode)
2078
2078
  && !(n1.type === "mstyle" && n1.attributes.mathcolor)
2079
2079
  ? expression[0]
2080
- : expression.length > 1 && wrap === "none"
2081
- ? new mathMLTree.MathNode("mrow", expression)
2082
2080
  : setLineBreaks(expression, wrap, settings.displayMode);
2083
2081
 
2084
2082
  if (tag) {
@@ -2093,7 +2091,7 @@ function buildMathML(tree, texExpression, style, settings) {
2093
2091
  wrapper = new mathMLTree.MathNode("semantics", [wrapper, annotation]);
2094
2092
  }
2095
2093
 
2096
- if (wrap !== "none") {
2094
+ if (wrap !== "none" && wrapper.children.length > 1) {
2097
2095
  const maths = [];
2098
2096
  for (let i = 0; i < wrapper.children.length; i++) {
2099
2097
  const math = new mathMLTree.MathNode("math", [wrapper.children[i]]);
@@ -3907,7 +3905,7 @@ defineFunction({
3907
3905
 
3908
3906
  defineFunction({
3909
3907
  type: "enclose",
3910
- names: ["\\angl", "\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\overline", "\\underline"],
3908
+ names: ["\\angl", "\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\overline"],
3911
3909
  // , "\\phase", "\\longdiv"
3912
3910
  props: {
3913
3911
  numArgs: 1
@@ -3924,6 +3922,25 @@ defineFunction({
3924
3922
  mathmlBuilder: mathmlBuilder$8
3925
3923
  });
3926
3924
 
3925
+ defineFunction({
3926
+ type: "enclose",
3927
+ names: ["\\underline"],
3928
+ props: {
3929
+ numArgs: 1,
3930
+ allowedInText: true
3931
+ },
3932
+ handler({ parser, funcName }, args) {
3933
+ const body = args[0];
3934
+ return {
3935
+ type: "enclose",
3936
+ mode: parser.mode,
3937
+ label: funcName,
3938
+ body
3939
+ };
3940
+ },
3941
+ mathmlBuilder: mathmlBuilder$8
3942
+ });
3943
+
3927
3944
  /**
3928
3945
  * All registered environments.
3929
3946
  * `environments.js` exports this same dictionary again and makes it public.
@@ -6729,10 +6746,9 @@ defineFunction({
6729
6746
  }
6730
6747
  });
6731
6748
 
6732
- // \pmb is a simulation of bold font.
6749
+ // In LaTeX, \pmb is a simulation of bold font.
6733
6750
  // The version of \pmb in ambsy.sty works by typesetting three copies of the argument
6734
- // with small offsets. We use CSS text-shadow.
6735
- // It's a hack. Not as good as a real bold font. Better than nothing.
6751
+ // with small offsets. We use CSS font-weight:bold.
6736
6752
 
6737
6753
  defineFunction({
6738
6754
  type: "pmb",
@@ -6752,7 +6768,7 @@ defineFunction({
6752
6768
  const inner = buildExpression(group.body, style);
6753
6769
  // Wrap with an <mstyle> element.
6754
6770
  const node = wrapWithMstyle(inner);
6755
- node.setAttribute("style", "text-shadow: 0.02em 0.01em 0.04px");
6771
+ node.setAttribute("style", "font-weight:bold");
6756
6772
  return node
6757
6773
  }
6758
6774
  });
@@ -7625,8 +7641,8 @@ const smallCaps = Object.freeze({
7625
7641
  const numberRegEx$1 = /^\d(?:[\d,.]*\d)?$/; // Keep in sync with numberRegEx in Parser.js
7626
7642
  const latinRegEx = /[A-Ba-z]/;
7627
7643
 
7628
- const italicNumber = (text, variant) => {
7629
- const mn = new mathMLTree.MathNode("mn", [text]);
7644
+ const italicNumber = (text, variant, tag) => {
7645
+ const mn = new mathMLTree.MathNode(tag, [text]);
7630
7646
  const wrapper = new mathMLTree.MathNode("mstyle", [mn]);
7631
7647
  wrapper.style["font-style"] = "italic";
7632
7648
  wrapper.style["font-family"] = "Cambria, 'Times New Roman', serif";
@@ -7676,28 +7692,24 @@ defineFunctionBuilders({
7676
7692
  const variant = getVariant(group, style) || "normal";
7677
7693
 
7678
7694
  let node;
7679
- if (group.mode === "text") {
7680
- if (variant === "italic" || variant === "bold-italic") {
7681
- if (numberRegEx$1.test(group.text)) {
7682
- return italicNumber(text, variant)
7683
- }
7684
- }
7685
- if (variant !== "normal") {
7686
- text.text = variantChar(text.text, variant);
7687
- }
7688
- node = new mathMLTree.MathNode("mtext", [text]);
7689
- } else if (numberRegEx$1.test(group.text)) {
7695
+ if (numberRegEx$1.test(group.text)) {
7696
+ const tag = group.mode === "text" ? "mtext" : "mn";
7690
7697
  if (variant === "oldstylenums") {
7691
7698
  const ms = new mathMLTree.MathNode("mstyle", [text], ["oldstylenums"]);
7692
- node = new mathMLTree.MathNode("mn", [ms]);
7699
+ node = new mathMLTree.MathNode(tag, [ms]);
7693
7700
  } else if (variant === "italic" || variant === "bold-italic") {
7694
- return italicNumber(text, variant)
7701
+ return italicNumber(text, variant, tag)
7695
7702
  } else {
7696
7703
  if (variant !== "normal") {
7697
7704
  text.text = text.text.split("").map(c => variantChar(c, variant)).join("");
7698
7705
  }
7699
- node = new mathMLTree.MathNode("mn", [text]);
7706
+ node = new mathMLTree.MathNode(tag, [text]);
7700
7707
  }
7708
+ } else if (group.mode === "text") {
7709
+ if (variant !== "normal") {
7710
+ text.text = variantChar(text.text, variant);
7711
+ }
7712
+ node = new mathMLTree.MathNode("mtext", [text]);
7701
7713
  } else if (group.text === "\\prime") {
7702
7714
  node = new mathMLTree.MathNode("mo", [text]);
7703
7715
  // TODO: If/when Chromium uses ssty variant for prime, remove the next line.
@@ -8396,7 +8408,7 @@ defineMacro("\\underbar", "\\underline{\\text{#1}}");
8396
8408
  // \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
8397
8409
  // We'll call \varvdots, which gets a glyph from symbols.js.
8398
8410
  // The zero-width rule gets us an equivalent to the vertical 6pt kern.
8399
- defineMacro("\\vdots", "\\mathord{\\varvdots\\rule{0pt}{15pt}}");
8411
+ defineMacro("\\vdots", "{\\varvdots\\rule{0pt}{15pt}}");
8400
8412
  defineMacro("\u22ee", "\\vdots");
8401
8413
 
8402
8414
  //////////////////////////////////////////////////////////////////////
@@ -12907,7 +12919,7 @@ class Style {
12907
12919
  * https://mit-license.org/
12908
12920
  */
12909
12921
 
12910
- const version = "0.9.1";
12922
+ const version = "0.9.2";
12911
12923
 
12912
12924
  function postProcess(block) {
12913
12925
  const labelMap = {};
@@ -14,7 +14,7 @@
14
14
  * https://mit-license.org/
15
15
  */
16
16
 
17
- const version = "0.9.1";
17
+ const version = "0.9.2";
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.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "TeX to MathML conversion in JavaScript.",
5
5
  "main": "dist/temml.js",
6
6
  "homepage": "https://temml.org",
@@ -195,8 +195,6 @@ export default function buildMathML(tree, texExpression, style, settings) {
195
195
  let wrapper = expression.length === 1 && tag === null && (n1 instanceof MathNode)
196
196
  && !(n1.type === "mstyle" && n1.attributes.mathcolor)
197
197
  ? expression[0]
198
- : expression.length > 1 && wrap === "none"
199
- ? new mathMLTree.MathNode("mrow", expression)
200
198
  : setLineBreaks(expression, wrap, settings.displayMode)
201
199
 
202
200
  if (tag) {
@@ -211,7 +209,7 @@ export default function buildMathML(tree, texExpression, style, settings) {
211
209
  wrapper = new mathMLTree.MathNode("semantics", [wrapper, annotation]);
212
210
  }
213
211
 
214
- if (wrap !== "none") {
212
+ if (wrap !== "none" && wrapper.children.length > 1) {
215
213
  const maths = []
216
214
  for (let i = 0; i < wrapper.children.length; i++) {
217
215
  const math = new mathMLTree.MathNode("math", [wrapper.children[i]])
@@ -175,7 +175,7 @@ defineFunction({
175
175
 
176
176
  defineFunction({
177
177
  type: "enclose",
178
- names: ["\\angl", "\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\overline", "\\underline"],
178
+ names: ["\\angl", "\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\overline"],
179
179
  // , "\\phase", "\\longdiv"
180
180
  props: {
181
181
  numArgs: 1
@@ -191,3 +191,22 @@ defineFunction({
191
191
  },
192
192
  mathmlBuilder
193
193
  });
194
+
195
+ defineFunction({
196
+ type: "enclose",
197
+ names: ["\\underline"],
198
+ props: {
199
+ numArgs: 1,
200
+ allowedInText: true
201
+ },
202
+ handler({ parser, funcName }, args) {
203
+ const body = args[0];
204
+ return {
205
+ type: "enclose",
206
+ mode: parser.mode,
207
+ label: funcName,
208
+ body
209
+ };
210
+ },
211
+ mathmlBuilder
212
+ });
@@ -2,10 +2,9 @@ import defineFunction, { ordargument } from "../defineFunction"
2
2
  import { wrapWithMstyle } from "../mathMLTree"
3
3
  import * as mml from "../buildMathML"
4
4
 
5
- // \pmb is a simulation of bold font.
5
+ // In LaTeX, \pmb is a simulation of bold font.
6
6
  // The version of \pmb in ambsy.sty works by typesetting three copies of the argument
7
- // with small offsets. We use CSS text-shadow.
8
- // It's a hack. Not as good as a real bold font. Better than nothing.
7
+ // with small offsets. We use CSS font-weight:bold.
9
8
 
10
9
  defineFunction({
11
10
  type: "pmb",
@@ -25,7 +24,7 @@ defineFunction({
25
24
  const inner = mml.buildExpression(group.body, style)
26
25
  // Wrap with an <mstyle> element.
27
26
  const node = wrapWithMstyle(inner)
28
- node.setAttribute("style", "text-shadow: 0.02em 0.01em 0.04px")
27
+ node.setAttribute("style", "font-weight:bold")
29
28
  return node
30
29
  }
31
30
  })
@@ -10,8 +10,8 @@ import * as mml from "../buildMathML"
10
10
  const numberRegEx = /^\d(?:[\d,.]*\d)?$/ // Keep in sync with numberRegEx in Parser.js
11
11
  const latinRegEx = /[A-Ba-z]/
12
12
 
13
- const italicNumber = (text, variant) => {
14
- const mn = new mathMLTree.MathNode("mn", [text])
13
+ const italicNumber = (text, variant, tag) => {
14
+ const mn = new mathMLTree.MathNode(tag, [text])
15
15
  const wrapper = new mathMLTree.MathNode("mstyle", [mn])
16
16
  wrapper.style["font-style"] = "italic"
17
17
  wrapper.style["font-family"] = "Cambria, 'Times New Roman', serif"
@@ -61,28 +61,24 @@ defineFunctionBuilders({
61
61
  const variant = getVariant(group, style) || "normal"
62
62
 
63
63
  let node
64
- if (group.mode === "text") {
65
- if (variant === "italic" || variant === "bold-italic") {
66
- if (numberRegEx.test(group.text)) {
67
- return italicNumber(text, variant)
68
- }
69
- }
70
- if (variant !== "normal") {
71
- text.text = variantChar(text.text, variant)
72
- }
73
- node = new mathMLTree.MathNode("mtext", [text])
74
- } else if (numberRegEx.test(group.text)) {
64
+ if (numberRegEx.test(group.text)) {
65
+ const tag = group.mode === "text" ? "mtext" : "mn"
75
66
  if (variant === "oldstylenums") {
76
67
  const ms = new mathMLTree.MathNode("mstyle", [text], ["oldstylenums"])
77
- node = new mathMLTree.MathNode("mn", [ms])
68
+ node = new mathMLTree.MathNode(tag, [ms])
78
69
  } else if (variant === "italic" || variant === "bold-italic") {
79
- return italicNumber(text, variant)
70
+ return italicNumber(text, variant, tag)
80
71
  } else {
81
72
  if (variant !== "normal") {
82
73
  text.text = text.text.split("").map(c => variantChar(c, variant)).join("")
83
74
  }
84
- node = new mathMLTree.MathNode("mn", [text])
75
+ node = new mathMLTree.MathNode(tag, [text])
85
76
  }
77
+ } else if (group.mode === "text") {
78
+ if (variant !== "normal") {
79
+ text.text = variantChar(text.text, variant)
80
+ }
81
+ node = new mathMLTree.MathNode("mtext", [text])
86
82
  } else if (group.text === "\\prime") {
87
83
  node = new mathMLTree.MathNode("mo", [text])
88
84
  // TODO: If/when Chromium uses ssty variant for prime, remove the next line.
package/src/macros.js CHANGED
@@ -228,7 +228,7 @@ defineMacro("\\underbar", "\\underline{\\text{#1}}");
228
228
  // \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
229
229
  // We'll call \varvdots, which gets a glyph from symbols.js.
230
230
  // The zero-width rule gets us an equivalent to the vertical 6pt kern.
231
- defineMacro("\\vdots", "\\mathord{\\varvdots\\rule{0pt}{15pt}}");
231
+ defineMacro("\\vdots", "{\\varvdots\\rule{0pt}{15pt}}");
232
232
  defineMacro("\u22ee", "\\vdots");
233
233
 
234
234
  //////////////////////////////////////////////////////////////////////
@@ -8,7 +8,7 @@
8
8
  * https://mit-license.org/
9
9
  */
10
10
 
11
- export const version = "0.9.1";
11
+ export const version = "0.9.2";
12
12
 
13
13
  export function postProcess(block) {
14
14
  const labelMap = {}