katex 0.16.28 → 0.16.30

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.
Files changed (84) hide show
  1. package/README.md +3 -3
  2. package/cli.js +3 -1
  3. package/contrib/auto-render/auto-render.js +5 -5
  4. package/contrib/auto-render/index.html +3 -2
  5. package/contrib/copy-tex/README.md +2 -2
  6. package/contrib/mathtex-script-type/README.md +5 -5
  7. package/contrib/mhchem/README.md +1 -1
  8. package/dist/README.md +3 -3
  9. package/dist/contrib/auto-render.js +4 -4
  10. package/dist/contrib/auto-render.min.js +1 -1
  11. package/dist/contrib/auto-render.mjs +2 -2
  12. package/dist/contrib/copy-tex.js +2 -2
  13. package/dist/contrib/copy-tex.min.js +1 -1
  14. package/dist/contrib/mathtex-script-type.min.js +1 -1
  15. package/dist/contrib/mhchem.min.js +1 -1
  16. package/dist/contrib/render-a11y-string.min.js +1 -1
  17. package/dist/katex-swap.css +7 -5
  18. package/dist/katex-swap.min.css +1 -1
  19. package/dist/katex.css +6 -4
  20. package/dist/katex.js +460 -555
  21. package/dist/katex.min.css +1 -1
  22. package/dist/katex.min.js +1 -1
  23. package/dist/katex.mjs +415 -508
  24. package/katex.js +2 -2
  25. package/package.json +3 -4
  26. package/src/MacroExpander.js +2 -2
  27. package/src/Parser.js +4 -3
  28. package/src/Settings.js +2 -2
  29. package/src/buildCommon.js +15 -33
  30. package/src/buildHTML.js +11 -9
  31. package/src/buildMathML.js +17 -15
  32. package/src/buildTree.js +5 -5
  33. package/src/delimiter.js +32 -40
  34. package/src/domTree.js +17 -17
  35. package/src/environments/array.js +40 -39
  36. package/src/environments/cd.js +10 -10
  37. package/src/functions/accent.js +17 -17
  38. package/src/functions/accentunder.js +8 -8
  39. package/src/functions/arrow.js +16 -16
  40. package/src/functions/color.js +4 -4
  41. package/src/functions/cr.js +4 -4
  42. package/src/functions/delimsizing.js +18 -19
  43. package/src/functions/enclose.js +15 -15
  44. package/src/functions/font.js +2 -3
  45. package/src/functions/genfrac.js +25 -20
  46. package/src/functions/hbox.js +4 -4
  47. package/src/functions/horizBrace.js +12 -12
  48. package/src/functions/href.js +2 -2
  49. package/src/functions/html.js +2 -2
  50. package/src/functions/htmlmathml.js +3 -2
  51. package/src/functions/includegraphics.js +2 -2
  52. package/src/functions/kern.js +4 -4
  53. package/src/functions/lap.js +11 -11
  54. package/src/functions/mathchoice.js +2 -2
  55. package/src/functions/mclass.js +10 -12
  56. package/src/functions/op.js +20 -20
  57. package/src/functions/operatorname.js +12 -12
  58. package/src/functions/ordgroup.js +3 -3
  59. package/src/functions/overline.js +8 -8
  60. package/src/functions/phantom.js +14 -14
  61. package/src/functions/pmb.js +4 -4
  62. package/src/functions/raisebox.js +4 -4
  63. package/src/functions/rule.js +5 -5
  64. package/src/functions/sizing.js +4 -4
  65. package/src/functions/smash.js +6 -6
  66. package/src/functions/sqrt.js +12 -12
  67. package/src/functions/styling.js +2 -2
  68. package/src/functions/supsub.js +13 -13
  69. package/src/functions/symbolsOp.js +4 -4
  70. package/src/functions/symbolsOrd.js +9 -9
  71. package/src/functions/symbolsSpacing.js +9 -9
  72. package/src/functions/tag.js +6 -6
  73. package/src/functions/text.js +2 -2
  74. package/src/functions/underline.js +8 -8
  75. package/src/functions/utils/assembleSupSub.js +9 -9
  76. package/src/functions/vcenter.js +4 -4
  77. package/src/functions/verb.js +7 -7
  78. package/src/macros.js +5 -2
  79. package/src/mathMLTree.js +5 -12
  80. package/src/stretchy.js +18 -28
  81. package/src/styles/fonts.scss +5 -3
  82. package/src/styles/katex-swap.scss +4 -1
  83. package/src/styles/katex.scss +6 -4
  84. package/src/utils.js +10 -41
@@ -1,11 +1,10 @@
1
1
  // @flow
2
2
  import defineFunction, {normalizeArgument} from "../defineFunction";
3
- import buildCommon from "../buildCommon";
4
- import delimiter from "../delimiter";
5
- import mathMLTree from "../mathMLTree";
3
+ import {makeLineSpan, makeSpan, makeVList} from "../buildCommon";
4
+ import {makeCustomSizedDelim} from "../delimiter";
5
+ import {MathNode, TextNode} from "../mathMLTree";
6
6
  import Style from "../Style";
7
7
  import {assertNodeType} from "../parseNode";
8
- import {assert} from "../utils";
9
8
 
10
9
  import * as html from "../buildHTML";
11
10
  import * as mml from "../buildMathML";
@@ -60,9 +59,9 @@ const htmlBuilder = (group, options) => {
60
59
  if (group.hasBarLine) {
61
60
  if (group.barSize) {
62
61
  ruleWidth = calculateSize(group.barSize, options);
63
- rule = buildCommon.makeLineSpan("frac-line", options, ruleWidth);
62
+ rule = makeLineSpan("frac-line", options, ruleWidth);
64
63
  } else {
65
- rule = buildCommon.makeLineSpan("frac-line", options);
64
+ rule = makeLineSpan("frac-line", options);
66
65
  }
67
66
  ruleWidth = rule.height;
68
67
  ruleSpacing = rule.height;
@@ -105,7 +104,7 @@ const htmlBuilder = (group, options) => {
105
104
  denomShift += 0.5 * (clearance - candidateClearance);
106
105
  }
107
106
 
108
- frac = buildCommon.makeVList({
107
+ frac = makeVList({
109
108
  positionType: "individualShift",
110
109
  children: [
111
110
  {type: "elem", elem: denomm, shift: denomShift},
@@ -132,7 +131,7 @@ const htmlBuilder = (group, options) => {
132
131
 
133
132
  const midShift = -(axisHeight - 0.5 * ruleWidth);
134
133
 
135
- frac = buildCommon.makeVList({
134
+ frac = makeVList({
136
135
  positionType: "individualShift",
137
136
  children: [
138
137
  {type: "elem", elem: denomm, shift: denomShift},
@@ -163,29 +162,29 @@ const htmlBuilder = (group, options) => {
163
162
  if (group.leftDelim == null) {
164
163
  leftDelim = html.makeNullDelimiter(options, ["mopen"]);
165
164
  } else {
166
- leftDelim = delimiter.customSizedDelim(
165
+ leftDelim = makeCustomSizedDelim(
167
166
  group.leftDelim, delimSize, true,
168
167
  options.havingStyle(style), group.mode, ["mopen"]);
169
168
  }
170
169
 
171
170
  if (group.continued) {
172
- rightDelim = buildCommon.makeSpan([]); // zero width for \cfrac
171
+ rightDelim = makeSpan([]); // zero width for \cfrac
173
172
  } else if (group.rightDelim == null) {
174
173
  rightDelim = html.makeNullDelimiter(options, ["mclose"]);
175
174
  } else {
176
- rightDelim = delimiter.customSizedDelim(
175
+ rightDelim = makeCustomSizedDelim(
177
176
  group.rightDelim, delimSize, true,
178
177
  options.havingStyle(style), group.mode, ["mclose"]);
179
178
  }
180
179
 
181
- return buildCommon.makeSpan(
180
+ return makeSpan(
182
181
  ["mord"].concat(newOptions.sizingClasses(options)),
183
- [leftDelim, buildCommon.makeSpan(["mfrac"], [frac]), rightDelim],
182
+ [leftDelim, makeSpan(["mfrac"], [frac]), rightDelim],
184
183
  options);
185
184
  };
186
185
 
187
186
  const mathmlBuilder = (group, options) => {
188
- let node = new mathMLTree.MathNode(
187
+ let node = new MathNode(
189
188
  "mfrac",
190
189
  [
191
190
  mml.buildGroup(group.numer, options),
@@ -201,7 +200,7 @@ const mathmlBuilder = (group, options) => {
201
200
 
202
201
  const style = adjustStyle(group.size, options.style);
203
202
  if (style.size !== options.style.size) {
204
- node = new mathMLTree.MathNode("mstyle", [node]);
203
+ node = new MathNode("mstyle", [node]);
205
204
  const isDisplay = (style.size === Style.DISPLAY.size) ? "true" : "false";
206
205
  node.setAttribute("displaystyle", isDisplay);
207
206
  node.setAttribute("scriptlevel", "0");
@@ -211,9 +210,9 @@ const mathmlBuilder = (group, options) => {
211
210
  const withDelims = [];
212
211
 
213
212
  if (group.leftDelim != null) {
214
- const leftOp = new mathMLTree.MathNode(
213
+ const leftOp = new MathNode(
215
214
  "mo",
216
- [new mathMLTree.TextNode(group.leftDelim.replace("\\", ""))]
215
+ [new TextNode(group.leftDelim.replace("\\", ""))]
217
216
  );
218
217
 
219
218
  leftOp.setAttribute("fence", "true");
@@ -224,9 +223,9 @@ const mathmlBuilder = (group, options) => {
224
223
  withDelims.push(node);
225
224
 
226
225
  if (group.rightDelim != null) {
227
- const rightOp = new mathMLTree.MathNode(
226
+ const rightOp = new MathNode(
228
227
  "mo",
229
- [new mathMLTree.TextNode(group.rightDelim.replace("\\", ""))]
228
+ [new TextNode(group.rightDelim.replace("\\", ""))]
230
229
  );
231
230
 
232
231
  rightOp.setAttribute("fence", "true");
@@ -487,7 +486,13 @@ defineFunction({
487
486
  },
488
487
  handler: ({parser, funcName}, args) => {
489
488
  const numer = args[0];
490
- const barSize = assert(assertNodeType(args[1], "infix").size);
489
+ const barSize = assertNodeType(args[1], "infix").size;
490
+
491
+ if (!barSize) {
492
+ throw new Error(
493
+ `\\\\abovefrac expected size, but got ${String(barSize)}`);
494
+ }
495
+
491
496
  const denom = args[2];
492
497
 
493
498
  const hasBarLine = barSize.number > 0;
@@ -1,7 +1,7 @@
1
1
  // @flow
2
2
  import defineFunction, {ordargument} from "../defineFunction";
3
- import buildCommon from "../buildCommon";
4
- import mathMLTree from "../mathMLTree";
3
+ import {makeFragment} from "../buildCommon";
4
+ import {MathNode} from "../mathMLTree";
5
5
 
6
6
  import * as html from "../buildHTML";
7
7
  import * as mml from "../buildMathML";
@@ -29,10 +29,10 @@ defineFunction({
29
29
  },
30
30
  htmlBuilder(group, options) {
31
31
  const elements = html.buildExpression(group.body, options, false);
32
- return buildCommon.makeFragment(elements);
32
+ return makeFragment(elements);
33
33
  },
34
34
  mathmlBuilder(group, options) {
35
- return new mathMLTree.MathNode(
35
+ return new MathNode(
36
36
  "mrow", mml.buildExpression(group.body, options)
37
37
  );
38
38
  },
@@ -1,8 +1,8 @@
1
1
  // @flow
2
2
  import defineFunction from "../defineFunction";
3
- import buildCommon from "../buildCommon";
4
- import mathMLTree from "../mathMLTree";
5
- import stretchy from "../stretchy";
3
+ import {makeSpan, makeVList} from "../buildCommon";
4
+ import {MathNode} from "../mathMLTree";
5
+ import {stretchyMathML, stretchySvg} from "../stretchy";
6
6
  import Style from "../Style";
7
7
  import {assertNodeType} from "../parseNode";
8
8
 
@@ -37,13 +37,13 @@ export const htmlBuilder: HtmlBuilderSupSub<"horizBrace"> = (grp, options) => {
37
37
  group.base, options.havingBaseStyle(Style.DISPLAY));
38
38
 
39
39
  // Create the stretchy element
40
- const braceBody = stretchy.svgSpan(group, options);
40
+ const braceBody = stretchySvg(group, options);
41
41
 
42
42
  // Generate the vlist, with the appropriate kerns ┏━━━━━━━━┓
43
43
  // This first vlist contains the content and the brace: equation
44
44
  let vlist;
45
45
  if (group.isOver) {
46
- vlist = buildCommon.makeVList({
46
+ vlist = makeVList({
47
47
  positionType: "firstBaseline",
48
48
  children: [
49
49
  {type: "elem", elem: body},
@@ -54,7 +54,7 @@ export const htmlBuilder: HtmlBuilderSupSub<"horizBrace"> = (grp, options) => {
54
54
  // $FlowFixMe: Replace this with passing "svg-align" into makeVList.
55
55
  vlist.children[0].children[0].children[1].classes.push("svg-align");
56
56
  } else {
57
- vlist = buildCommon.makeVList({
57
+ vlist = makeVList({
58
58
  positionType: "bottom",
59
59
  positionData: body.depth + 0.1 + braceBody.height,
60
60
  children: [
@@ -77,12 +77,12 @@ export const htmlBuilder: HtmlBuilderSupSub<"horizBrace"> = (grp, options) => {
77
77
  // ┏━━━━━━━━┓ or ┏━━━┓ not ┏━━━━━━━━━┓
78
78
  // equation eqn eqn
79
79
 
80
- const vSpan = buildCommon.makeSpan(
80
+ const vSpan = makeSpan(
81
81
  ["mord", (group.isOver ? "mover" : "munder")],
82
82
  [vlist], options);
83
83
 
84
84
  if (group.isOver) {
85
- vlist = buildCommon.makeVList({
85
+ vlist = makeVList({
86
86
  positionType: "firstBaseline",
87
87
  children: [
88
88
  {type: "elem", elem: vSpan},
@@ -91,7 +91,7 @@ export const htmlBuilder: HtmlBuilderSupSub<"horizBrace"> = (grp, options) => {
91
91
  ],
92
92
  }, options);
93
93
  } else {
94
- vlist = buildCommon.makeVList({
94
+ vlist = makeVList({
95
95
  positionType: "bottom",
96
96
  positionData: vSpan.depth + 0.2 + supSubGroup.height +
97
97
  supSubGroup.depth,
@@ -104,13 +104,13 @@ export const htmlBuilder: HtmlBuilderSupSub<"horizBrace"> = (grp, options) => {
104
104
  }
105
105
  }
106
106
 
107
- return buildCommon.makeSpan(
107
+ return makeSpan(
108
108
  ["mord", (group.isOver ? "mover" : "munder")], [vlist], options);
109
109
  };
110
110
 
111
111
  const mathmlBuilder: MathMLBuilder<"horizBrace"> = (group, options) => {
112
- const accentNode = stretchy.mathMLnode(group.label);
113
- return new mathMLTree.MathNode(
112
+ const accentNode = stretchyMathML(group.label);
113
+ return new MathNode(
114
114
  (group.isOver ? "mover" : "munder"),
115
115
  [mml.buildGroup(group.base, options), accentNode]
116
116
  );
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
  import defineFunction, {ordargument} from "../defineFunction";
3
- import buildCommon from "../buildCommon";
3
+ import {makeAnchor} from "../buildCommon";
4
4
  import {assertNodeType} from "../parseNode";
5
5
  import {MathNode} from "../mathMLTree";
6
6
 
@@ -35,7 +35,7 @@ defineFunction({
35
35
  },
36
36
  htmlBuilder: (group, options) => {
37
37
  const elements = html.buildExpression(group.body, options, false);
38
- return buildCommon.makeAnchor(group.href, [], elements, options);
38
+ return makeAnchor(group.href, [], elements, options);
39
39
  },
40
40
  mathmlBuilder: (group, options) => {
41
41
  let math = mml.buildExpressionRow(group.body, options);
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
  import defineFunction, {ordargument} from "../defineFunction";
3
- import buildCommon from "../buildCommon";
3
+ import {makeSpan} from "../buildCommon";
4
4
  import {assertNodeType} from "../parseNode";
5
5
  import ParseError from "../ParseError";
6
6
 
@@ -91,7 +91,7 @@ defineFunction({
91
91
  classes.push(...group.attributes.class.trim().split(/\s+/));
92
92
  }
93
93
 
94
- const span = buildCommon.makeSpan(classes, elements, options);
94
+ const span = makeSpan(classes, elements, options);
95
95
  for (const attr in group.attributes) {
96
96
  if (attr !== "class" && group.attributes.hasOwnProperty(attr)) {
97
97
  span.setAttribute(attr, group.attributes[attr]);
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
  import defineFunction, {ordargument} from "../defineFunction";
3
- import buildCommon from "../buildCommon";
3
+ import {makeFragment} from "../buildCommon";
4
4
 
5
5
  import * as html from "../buildHTML";
6
6
  import * as mml from "../buildMathML";
@@ -10,6 +10,7 @@ defineFunction({
10
10
  names: ["\\html@mathml"],
11
11
  props: {
12
12
  numArgs: 2,
13
+ allowedInArgument: true,
13
14
  allowedInText: true,
14
15
  },
15
16
  handler: ({parser}, args) => {
@@ -26,7 +27,7 @@ defineFunction({
26
27
  options,
27
28
  false
28
29
  );
29
- return buildCommon.makeFragment(elements);
30
+ return makeFragment(elements);
30
31
  },
31
32
  mathmlBuilder: (group, options) => {
32
33
  return mml.buildExpressionRow(group.mathml, options);
@@ -4,7 +4,7 @@ import type {Measurement} from "../units";
4
4
  import {calculateSize, validUnit, makeEm} from "../units";
5
5
  import ParseError from "../ParseError";
6
6
  import {Img} from "../domTree";
7
- import mathMLTree from "../mathMLTree";
7
+ import {MathNode} from "../mathMLTree";
8
8
  import {assertNodeType} from "../parseNode";
9
9
  import type {CssStyle} from "../domTree";
10
10
 
@@ -130,7 +130,7 @@ defineFunction({
130
130
  return node;
131
131
  },
132
132
  mathmlBuilder: (group, options) => {
133
- const node = new mathMLTree.MathNode("mglyph", []);
133
+ const node = new MathNode("mglyph", []);
134
134
  node.setAttribute("alt", group.alt);
135
135
 
136
136
  const height = calculateSize(group.height, options);
@@ -2,8 +2,8 @@
2
2
  // Horizontal spacing commands
3
3
 
4
4
  import defineFunction from "../defineFunction";
5
- import buildCommon from "../buildCommon";
6
- import mathMLTree from "../mathMLTree";
5
+ import {makeGlue} from "../buildCommon";
6
+ import {SpaceNode} from "../mathMLTree";
7
7
  import {calculateSize} from "../units";
8
8
  import {assertNodeType} from "../parseNode";
9
9
 
@@ -47,10 +47,10 @@ defineFunction({
47
47
  };
48
48
  },
49
49
  htmlBuilder(group, options) {
50
- return buildCommon.makeGlue(group.dimension, options);
50
+ return makeGlue(group.dimension, options);
51
51
  },
52
52
  mathmlBuilder(group, options) {
53
53
  const dimension = calculateSize(group.dimension, options);
54
- return new mathMLTree.SpaceNode(dimension);
54
+ return new SpaceNode(dimension);
55
55
  },
56
56
  });
@@ -1,8 +1,8 @@
1
1
  // @flow
2
2
  // Horizontal overlap functions
3
3
  import defineFunction from "../defineFunction";
4
- import buildCommon from "../buildCommon";
5
- import mathMLTree from "../mathMLTree";
4
+ import {makeSpan} from "../buildCommon";
5
+ import {MathNode} from "../mathMLTree";
6
6
  import {makeEm} from "../units";
7
7
 
8
8
  import * as html from "../buildHTML";
@@ -29,16 +29,16 @@ defineFunction({
29
29
  let inner;
30
30
  if (group.alignment === "clap") {
31
31
  // ref: https://www.math.lsu.edu/~aperlis/publications/mathclap/
32
- inner = buildCommon.makeSpan(
32
+ inner = makeSpan(
33
33
  [], [html.buildGroup(group.body, options)]);
34
34
  // wrap, since CSS will center a .clap > .inner > span
35
- inner = buildCommon.makeSpan(["inner"], [inner], options);
35
+ inner = makeSpan(["inner"], [inner], options);
36
36
  } else {
37
- inner = buildCommon.makeSpan(
37
+ inner = makeSpan(
38
38
  ["inner"], [html.buildGroup(group.body, options)]);
39
39
  }
40
- const fix = buildCommon.makeSpan(["fix"], []);
41
- let node = buildCommon.makeSpan(
40
+ const fix = makeSpan(["fix"], []);
41
+ let node = makeSpan(
42
42
  [group.alignment], [inner, fix], options);
43
43
 
44
44
  // At this point, we have correctly set horizontal alignment of the
@@ -46,7 +46,7 @@ defineFunction({
46
46
  // Next, use a strut to set the height of the HTML bounding box.
47
47
  // Otherwise, a tall argument may be misplaced.
48
48
  // This code resolved issue #1153
49
- const strut = buildCommon.makeSpan(["strut"]);
49
+ const strut = makeSpan(["strut"]);
50
50
  strut.style.height = makeEm(node.height + node.depth);
51
51
  if (node.depth) {
52
52
  strut.style.verticalAlign = makeEm(-node.depth);
@@ -55,12 +55,12 @@ defineFunction({
55
55
 
56
56
  // Next, prevent vertical misplacement when next to something tall.
57
57
  // This code resolves issue #1234
58
- node = buildCommon.makeSpan(["thinbox"], [node], options);
59
- return buildCommon.makeSpan(["mord", "vbox"], [node], options);
58
+ node = makeSpan(["thinbox"], [node], options);
59
+ return makeSpan(["mord", "vbox"], [node], options);
60
60
  },
61
61
  mathmlBuilder: (group, options) => {
62
62
  // mathllap, mathrlap, mathclap
63
- const node = new mathMLTree.MathNode(
63
+ const node = new MathNode(
64
64
  "mpadded", [mml.buildGroup(group.body, options)]);
65
65
 
66
66
  if (group.alignment !== "rlap") {
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
  import defineFunction, {ordargument} from "../defineFunction";
3
- import buildCommon from "../buildCommon";
3
+ import {makeFragment} from "../buildCommon";
4
4
  import Style from "../Style";
5
5
 
6
6
  import * as html from "../buildHTML";
@@ -42,7 +42,7 @@ defineFunction({
42
42
  options,
43
43
  false
44
44
  );
45
- return buildCommon.makeFragment(elements);
45
+ return makeFragment(elements);
46
46
  },
47
47
  mathmlBuilder: (group, options) => {
48
48
  const body = chooseMathStyle(group, options);
@@ -1,8 +1,8 @@
1
1
  // @flow
2
2
  import defineFunction, {ordargument} from "../defineFunction";
3
- import buildCommon from "../buildCommon";
4
- import mathMLTree from "../mathMLTree";
5
- import utils from "../utils";
3
+ import {makeSpan} from "../buildCommon";
4
+ import {isCharacterBox} from "../utils";
5
+ import {MathNode} from "../mathMLTree";
6
6
  import type {AnyParseNode} from "../parseNode";
7
7
 
8
8
  import * as html from "../buildHTML";
@@ -10,32 +10,30 @@ import * as mml from "../buildMathML";
10
10
 
11
11
  import type {ParseNode} from "../parseNode";
12
12
 
13
- const makeSpan = buildCommon.makeSpan;
14
-
15
13
  function htmlBuilder(group: ParseNode<"mclass">, options) {
16
14
  const elements = html.buildExpression(group.body, options, true);
17
15
  return makeSpan([group.mclass], elements, options);
18
16
  }
19
17
 
20
18
  function mathmlBuilder(group: ParseNode<"mclass">, options) {
21
- let node: mathMLTree.MathNode;
19
+ let node: MathNode;
22
20
  const inner = mml.buildExpression(group.body, options);
23
21
 
24
22
  if (group.mclass === "minner") {
25
- node = new mathMLTree.MathNode("mpadded", inner);
23
+ node = new MathNode("mpadded", inner);
26
24
  } else if (group.mclass === "mord") {
27
25
  if (group.isCharacterBox) {
28
26
  node = inner[0];
29
27
  node.type = "mi";
30
28
  } else {
31
- node = new mathMLTree.MathNode("mi", inner);
29
+ node = new MathNode("mi", inner);
32
30
  }
33
31
  } else {
34
32
  if (group.isCharacterBox) {
35
33
  node = inner[0];
36
34
  node.type = "mo";
37
35
  } else {
38
- node = new mathMLTree.MathNode("mo", inner);
36
+ node = new MathNode("mo", inner);
39
37
  }
40
38
 
41
39
  // Set spacing based on what is the most likely adjacent atom type.
@@ -77,7 +75,7 @@ defineFunction({
77
75
  mode: parser.mode,
78
76
  mclass: "m" + funcName.slice(5), // TODO(kevinb): don't prefix with 'm'
79
77
  body: ordargument(body),
80
- isCharacterBox: utils.isCharacterBox(body),
78
+ isCharacterBox: isCharacterBox(body),
81
79
  };
82
80
  },
83
81
  htmlBuilder,
@@ -111,7 +109,7 @@ defineFunction({
111
109
  mode: parser.mode,
112
110
  mclass: binrelClass(args[0]),
113
111
  body: ordargument(args[1]),
114
- isCharacterBox: utils.isCharacterBox(args[1]),
112
+ isCharacterBox: isCharacterBox(args[1]),
115
113
  };
116
114
  },
117
115
  });
@@ -159,7 +157,7 @@ defineFunction({
159
157
  mode: parser.mode,
160
158
  mclass,
161
159
  body: [supsub],
162
- isCharacterBox: utils.isCharacterBox(supsub),
160
+ isCharacterBox: isCharacterBox(supsub),
163
161
  };
164
162
  },
165
163
  htmlBuilder,
@@ -1,9 +1,9 @@
1
1
  // @flow
2
2
  // Limits, symbols
3
3
  import defineFunction, {ordargument} from "../defineFunction";
4
- import buildCommon from "../buildCommon";
4
+ import {mathsym, makeSpan, makeSymbol, makeVList, staticSvg} from "../buildCommon";
5
5
  import {SymbolNode} from "../domTree";
6
- import * as mathMLTree from "../mathMLTree";
6
+ import {MathNode, newDocumentFragment, TextNode} from "../mathMLTree";
7
7
  import Style from "../Style";
8
8
  import {assembleSupSub} from "./utils/assembleSupSub";
9
9
  import {assertNodeType} from "../parseNode";
@@ -16,9 +16,9 @@ import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";
16
16
  import type {ParseNode} from "../parseNode";
17
17
 
18
18
  // Most operators have a large successor symbol, but these don't.
19
- const noSuccessor = [
19
+ const noSuccessor = new Set([
20
20
  "\\smallint",
21
- ];
21
+ ]);
22
22
 
23
23
  // NOTE: Unlike most `htmlBuilder`s, this one handles not only "op", but also
24
24
  // "supsub" since some of them (like \int) can affect super/subscripting.
@@ -45,7 +45,7 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
45
45
  let large = false;
46
46
  if (style.size === Style.DISPLAY.size &&
47
47
  group.symbol &&
48
- !noSuccessor.includes(group.name)) {
48
+ !noSuccessor.has(group.name)) {
49
49
 
50
50
  // Most symbol operators get larger in displaystyle (rule 13)
51
51
  large = true;
@@ -64,7 +64,7 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
64
64
  group.name = stash === "oiint" ? "\\iint" : "\\iiint";
65
65
  }
66
66
 
67
- base = buildCommon.makeSymbol(
67
+ base = makeSymbol(
68
68
  group.name, fontName, "math", options,
69
69
  ["mop", "op-symbol", large ? "large-op" : "small-op"]);
70
70
 
@@ -72,9 +72,9 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
72
72
  // We're in \oiint or \oiiint. Overlay the oval.
73
73
  // TODO: When font glyphs are available, delete this code.
74
74
  const italic = base.italic;
75
- const oval = buildCommon.staticSvg(stash + "Size"
75
+ const oval = staticSvg(stash + "Size"
76
76
  + (large ? "2" : "1"), options);
77
- base = buildCommon.makeVList({
77
+ base = makeVList({
78
78
  positionType: "individualShift",
79
79
  children: [
80
80
  {type: "elem", elem: base, shift: 0},
@@ -93,16 +93,16 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
93
93
  base = inner[0];
94
94
  base.classes[0] = "mop"; // replace old mclass
95
95
  } else {
96
- base = buildCommon.makeSpan(["mop"], inner, options);
96
+ base = makeSpan(["mop"], inner, options);
97
97
  }
98
98
  } else {
99
99
  // Otherwise, this is a text operator. Build the text from the
100
100
  // operator's name.
101
101
  const output = [];
102
102
  for (let i = 1; i < group.name.length; i++) {
103
- output.push(buildCommon.mathsym(group.name[i], group.mode, options));
103
+ output.push(mathsym(group.name[i], group.mode, options));
104
104
  }
105
- base = buildCommon.makeSpan(["mop"], output, options);
105
+ base = makeSpan(["mop"], output, options);
106
106
  }
107
107
 
108
108
  // If content of op is a single symbol, shift it vertically.
@@ -144,28 +144,28 @@ const mathmlBuilder: MathMLBuilder<"op"> = (group, options) => {
144
144
 
145
145
  if (group.symbol) {
146
146
  // This is a symbol. Just add the symbol.
147
- node = new mathMLTree.MathNode(
147
+ node = new MathNode(
148
148
  "mo", [mml.makeText(group.name, group.mode)]);
149
- if (noSuccessor.includes(group.name)) {
149
+ if (noSuccessor.has(group.name)) {
150
150
  node.setAttribute("largeop", "false");
151
151
  }
152
152
  } else if (group.body) {
153
153
  // This is an operator with children. Add them.
154
- node = new mathMLTree.MathNode(
154
+ node = new MathNode(
155
155
  "mo", mml.buildExpression(group.body, options));
156
156
  } else {
157
- // This is a text operator. Add all of the characters from the
157
+ // This is a text operator. Add all the characters from the
158
158
  // operator's name.
159
- node = new mathMLTree.MathNode(
160
- "mi", [new mathMLTree.TextNode(group.name.slice(1))]);
159
+ node = new MathNode(
160
+ "mi", [new TextNode(group.name.slice(1))]);
161
161
  // Append an <mo>&ApplyFunction;</mo>.
162
162
  // ref: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.4
163
- const operator = new mathMLTree.MathNode("mo",
163
+ const operator = new MathNode("mo",
164
164
  [mml.makeText("\u2061", "text")]);
165
165
  if (group.parentIsSupSub) {
166
- node = new mathMLTree.MathNode("mrow", [node, operator]);
166
+ node = new MathNode("mrow", [node, operator]);
167
167
  } else {
168
- node = mathMLTree.newDocumentFragment([node, operator]);
168
+ node = newDocumentFragment([node, operator]);
169
169
  }
170
170
  }
171
171
 
@@ -1,8 +1,8 @@
1
1
  // @flow
2
2
  import defineFunction, {ordargument} from "../defineFunction";
3
3
  import defineMacro from "../defineMacro";
4
- import buildCommon from "../buildCommon";
5
- import mathMLTree from "../mathMLTree";
4
+ import {makeSpan} from "../buildCommon";
5
+ import {MathNode, newDocumentFragment, SpaceNode, TextNode} from "../mathMLTree";
6
6
  import {SymbolNode} from "../domTree";
7
7
  import {assembleSupSub} from "./utils/assembleSupSub";
8
8
  import {assertNodeType} from "../parseNode";
@@ -63,9 +63,9 @@ export const htmlBuilder: HtmlBuilderSupSub<"operatorname"> = (grp, options) =>
63
63
  .replace(/\u2217/, "*");
64
64
  }
65
65
  }
66
- base = buildCommon.makeSpan(["mop"], expression, options);
66
+ base = makeSpan(["mop"], expression, options);
67
67
  } else {
68
- base = buildCommon.makeSpan(["mop"], [], options);
68
+ base = makeSpan(["mop"], [], options);
69
69
  }
70
70
 
71
71
  if (hasLimits) {
@@ -86,9 +86,9 @@ const mathmlBuilder: MathMLBuilder<"operatorname"> = (group, options) => {
86
86
  let isAllString = true; // default
87
87
  for (let i = 0; i < expression.length; i++) {
88
88
  const node = expression[i];
89
- if (node instanceof mathMLTree.SpaceNode) {
89
+ if (node instanceof SpaceNode) {
90
90
  // Do nothing
91
- } else if (node instanceof mathMLTree.MathNode) {
91
+ } else if (node instanceof MathNode) {
92
92
  switch (node.type) {
93
93
  case "mi":
94
94
  case "mn":
@@ -99,7 +99,7 @@ const mathmlBuilder: MathMLBuilder<"operatorname"> = (group, options) => {
99
99
  case "mo": {
100
100
  const child = node.children[0];
101
101
  if (node.children.length === 1 &&
102
- child instanceof mathMLTree.TextNode) {
102
+ child instanceof TextNode) {
103
103
  child.text =
104
104
  child.text.replace(/\u2212/, "-")
105
105
  .replace(/\u2217/, "*");
@@ -119,21 +119,21 @@ const mathmlBuilder: MathMLBuilder<"operatorname"> = (group, options) => {
119
119
  if (isAllString) {
120
120
  // Write a single TextNode instead of multiple nested tags.
121
121
  const word = expression.map(node => node.toText()).join("");
122
- expression = [new mathMLTree.TextNode(word)];
122
+ expression = [new TextNode(word)];
123
123
  }
124
124
 
125
- const identifier = new mathMLTree.MathNode("mi", expression);
125
+ const identifier = new MathNode("mi", expression);
126
126
  identifier.setAttribute("mathvariant", "normal");
127
127
 
128
128
  // \u2061 is the same as &ApplyFunction;
129
129
  // ref: https://www.w3schools.com/charsets/ref_html_entities_a.asp
130
- const operator = new mathMLTree.MathNode("mo",
130
+ const operator = new MathNode("mo",
131
131
  [mml.makeText("\u2061", "text")]);
132
132
 
133
133
  if (group.parentIsSupSub) {
134
- return new mathMLTree.MathNode("mrow", [identifier, operator]);
134
+ return new MathNode("mrow", [identifier, operator]);
135
135
  } else {
136
- return mathMLTree.newDocumentFragment([identifier, operator]);
136
+ return newDocumentFragment([identifier, operator]);
137
137
  }
138
138
  };
139
139