katex 0.16.32 → 0.16.34

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 (126) hide show
  1. package/README.md +3 -3
  2. package/contrib/auto-render/{auto-render.js → auto-render.ts} +41 -19
  3. package/contrib/auto-render/{splitAtDelimiters.js → splitAtDelimiters.ts} +18 -4
  4. package/contrib/auto-render/test/{auto-render-spec.js → auto-render-spec.ts} +10 -2
  5. package/contrib/copy-tex/README.md +2 -2
  6. package/contrib/copy-tex/{copy-tex.js → copy-tex.ts} +4 -6
  7. package/contrib/copy-tex/{katex2tex.js → katex2tex.ts} +2 -3
  8. package/contrib/mathtex-script-type/README.md +5 -5
  9. package/contrib/mhchem/README.md +1 -1
  10. package/contrib/render-a11y-string/{render-a11y-string.js → render-a11y-string.ts} +18 -33
  11. package/contrib/render-a11y-string/test/{render-a11y-string-spec.js → render-a11y-string-spec.ts} +0 -1
  12. package/dist/README.md +3 -3
  13. package/dist/contrib/auto-render.js +24 -57
  14. package/dist/contrib/auto-render.min.js +1 -1
  15. package/dist/contrib/auto-render.mjs +16586 -210
  16. package/dist/contrib/copy-tex.js +23 -37
  17. package/dist/contrib/copy-tex.min.js +1 -1
  18. package/dist/contrib/copy-tex.mjs +77 -95
  19. package/dist/contrib/mathtex-script-type.js +0 -3
  20. package/dist/contrib/mathtex-script-type.mjs +16427 -4
  21. package/dist/contrib/mhchem.js +55 -303
  22. package/dist/contrib/mhchem.mjs +12884 -723
  23. package/dist/contrib/render-a11y-string.js +13 -108
  24. package/dist/contrib/render-a11y-string.min.js +1 -1
  25. package/dist/contrib/render-a11y-string.mjs +17020 -760
  26. package/dist/katex-swap.css +2 -1
  27. package/dist/katex-swap.min.css +1 -1
  28. package/dist/katex.css +2 -1
  29. package/dist/katex.js +4547 -5680
  30. package/dist/katex.min.css +1 -1
  31. package/dist/katex.min.js +1 -1
  32. package/dist/katex.mjs +11854 -13828
  33. package/{katex.js → katex.ts} +8 -5
  34. package/package.json +34 -31
  35. package/src/{Lexer.js → Lexer.ts} +1 -2
  36. package/src/{MacroExpander.js → MacroExpander.ts} +11 -15
  37. package/src/{Namespace.js → Namespace.ts} +4 -6
  38. package/src/{Options.js → Options.ts} +7 -12
  39. package/src/{ParseError.js → ParseError.ts} +16 -26
  40. package/src/{Parser.js → Parser.ts} +68 -56
  41. package/src/{Settings.js → Settings.ts} +70 -70
  42. package/src/{SourceLocation.js → SourceLocation.ts} +6 -7
  43. package/src/{Style.js → Style.ts} +4 -5
  44. package/src/{Token.js → Token.ts} +8 -6
  45. package/src/{buildCommon.js → buildCommon.ts} +62 -55
  46. package/src/{buildHTML.js → buildHTML.ts} +29 -25
  47. package/src/{buildMathML.js → buildMathML.ts} +15 -13
  48. package/src/{buildTree.js → buildTree.ts} +1 -2
  49. package/src/{defineEnvironment.js → defineEnvironment.ts} +26 -27
  50. package/src/{defineFunction.js → defineFunction.ts} +54 -56
  51. package/src/{defineMacro.js → defineMacro.ts} +12 -13
  52. package/src/{delimiter.js → delimiter.ts} +19 -17
  53. package/src/{domTree.js → domTree.ts} +94 -103
  54. package/src/environments/{array.js → array.ts} +109 -99
  55. package/src/environments/{cd.js → cd.ts} +9 -11
  56. package/src/{environments.js → environments.ts} +0 -1
  57. package/src/{fontMetrics.js → fontMetrics.ts} +10 -12
  58. package/src/fontMetricsData.d.ts +3 -0
  59. package/src/functions/{accent.js → accent.ts} +1 -2
  60. package/src/functions/{accentunder.js → accentunder.ts} +0 -1
  61. package/src/functions/{arrow.js → arrow.ts} +4 -6
  62. package/src/functions/{char.js → char.ts} +0 -1
  63. package/src/functions/{color.js → color.ts} +5 -6
  64. package/src/functions/{cr.js → cr.ts} +0 -1
  65. package/src/functions/{def.js → def.ts} +9 -7
  66. package/src/functions/{delimsizing.js → delimsizing.ts} +11 -9
  67. package/src/functions/{enclose.js → enclose.ts} +3 -4
  68. package/src/functions/{environment.js → environment.ts} +2 -3
  69. package/src/functions/{font.js → font.ts} +4 -4
  70. package/src/functions/{genfrac.js → genfrac.ts} +14 -15
  71. package/src/functions/{hbox.js → hbox.ts} +0 -1
  72. package/src/functions/{horizBrace.js → horizBrace.ts} +4 -5
  73. package/src/functions/{href.js → href.ts} +4 -4
  74. package/src/functions/{html.js → html.ts} +3 -3
  75. package/src/functions/{htmlmathml.js → htmlmathml.ts} +0 -1
  76. package/src/functions/{includegraphics.js → includegraphics.ts} +0 -1
  77. package/src/functions/{kern.js → kern.ts} +0 -1
  78. package/src/functions/{lap.js → lap.ts} +0 -1
  79. package/src/functions/{math.js → math.ts} +0 -1
  80. package/src/functions/{mathchoice.js → mathchoice.ts} +2 -2
  81. package/src/functions/{mclass.js → mclass.ts} +5 -6
  82. package/src/functions/{op.js → op.ts} +9 -11
  83. package/src/functions/{operatorname.js → operatorname.ts} +4 -7
  84. package/src/functions/{ordgroup.js → ordgroup.ts} +0 -2
  85. package/src/functions/{overline.js → overline.ts} +0 -1
  86. package/src/functions/{phantom.js → phantom.ts} +0 -1
  87. package/src/functions/{pmb.js → pmb.ts} +0 -1
  88. package/src/functions/{raisebox.js → raisebox.ts} +0 -1
  89. package/src/functions/{relax.js → relax.ts} +0 -1
  90. package/src/functions/{rule.js → rule.ts} +0 -1
  91. package/src/functions/{sizing.js → sizing.ts} +0 -1
  92. package/src/functions/{smash.js → smash.ts} +2 -4
  93. package/src/functions/{sqrt.js → sqrt.ts} +0 -1
  94. package/src/functions/{styling.js → styling.ts} +3 -3
  95. package/src/functions/{supsub.js → supsub.ts} +6 -8
  96. package/src/functions/{symbolsOp.js → symbolsOp.ts} +0 -2
  97. package/src/functions/{symbolsOrd.js → symbolsOrd.ts} +1 -2
  98. package/src/functions/{symbolsSpacing.js → symbolsSpacing.ts} +2 -3
  99. package/src/functions/{tag.js → tag.ts} +0 -2
  100. package/src/functions/{text.js → text.ts} +7 -6
  101. package/src/functions/{underline.js → underline.ts} +0 -1
  102. package/src/functions/utils/{assembleSupSub.js → assembleSupSub.ts} +2 -3
  103. package/src/functions/{vcenter.js → vcenter.ts} +0 -2
  104. package/src/functions/{verb.js → verb.ts} +0 -1
  105. package/src/{functions.js → functions.ts} +0 -1
  106. package/src/{macros.js → macros.ts} +10 -8
  107. package/src/{mathMLTree.js → mathMLTree.ts} +5 -6
  108. package/src/parseNode.ts +522 -0
  109. package/src/{parseTree.js → parseTree.ts} +5 -3
  110. package/src/{spacingData.js → spacingData.ts} +11 -12
  111. package/src/{stretchy.js → stretchy.ts} +7 -7
  112. package/src/styles/katex-swap.scss +1 -4
  113. package/src/styles/katex.scss +9 -0
  114. package/src/{svgGeometry.js → svgGeometry.ts} +1 -2
  115. package/src/{symbols.js → symbols.ts} +6 -6
  116. package/src/{tree.js → tree.ts} +5 -7
  117. package/src/{types.js → types.ts} +1 -2
  118. package/src/unicodeAccents.js +4 -1
  119. package/src/{unicodeScripts.js → unicodeScripts.ts} +1 -3
  120. package/src/{unicodeSupOrSub.js → unicodeSupOrSub.ts} +1 -1
  121. package/src/unicodeSymbols.js +4 -3
  122. package/src/{units.js → units.ts} +2 -4
  123. package/src/{utils.js → utils.ts} +2 -3
  124. package/src/{wide-character.js → wide-character.ts} +8 -10
  125. package/types/katex.d.ts +13 -12
  126. package/src/parseNode.js +0 -523
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import defineFunction, {ordargument} from "../defineFunction";
3
2
  import defineMacro from "../defineMacro";
4
3
  import {makeSpan} from "../buildCommon";
@@ -11,7 +10,7 @@ import * as html from "../buildHTML";
11
10
  import * as mml from "../buildMathML";
12
11
 
13
12
  import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";
14
- import type {ParseNode} from "../parseNode";
13
+ import type {AnyParseNode, ParseNode} from "../parseNode";
15
14
 
16
15
  // NOTE: Unlike most `htmlBuilder`s, this one handles not only
17
16
  // "operatorname", but also "supsub" since \operatorname* can
@@ -36,9 +35,8 @@ export const htmlBuilder: HtmlBuilderSupSub<"operatorname"> = (grp, options) =>
36
35
 
37
36
  let base;
38
37
  if (group.body.length > 0) {
39
- const body = group.body.map(child => {
40
- // $FlowFixMe: Check if the node has a string `text` property.
41
- const childText = child.text;
38
+ const body = group.body.map((child): AnyParseNode => {
39
+ const childText = "text" in child ? child.text : undefined;
42
40
  if (typeof childText === "string") {
43
41
  return {
44
42
  type: "textord",
@@ -79,7 +77,7 @@ export const htmlBuilder: HtmlBuilderSupSub<"operatorname"> = (grp, options) =>
79
77
 
80
78
  const mathmlBuilder: MathMLBuilder<"operatorname"> = (group, options) => {
81
79
  // The steps taken here are similar to the html version.
82
- let expression = mml.buildExpression(
80
+ let expression: Array<MathNode | TextNode> = mml.buildExpression(
83
81
  group.body, options.withFont("mathrm"));
84
82
 
85
83
  // Is expression a string or has it something like a fraction?
@@ -92,7 +90,6 @@ const mathmlBuilder: MathMLBuilder<"operatorname"> = (group, options) => {
92
90
  switch (node.type) {
93
91
  case "mi":
94
92
  case "mn":
95
- case "ms":
96
93
  case "mspace":
97
94
  case "mtext":
98
95
  break; // Do nothing yet.
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {defineFunctionBuilders} from "../defineFunction";
3
2
  import {makeFragment, makeSpan} from "../buildCommon";
4
3
 
@@ -19,4 +18,3 @@ defineFunctionBuilders({
19
18
  return mml.buildExpressionRow(group.body, options, true);
20
19
  },
21
20
  });
22
-
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import defineFunction from "../defineFunction";
3
2
  import {makeLineSpan, makeSpan, makeVList} from "../buildCommon";
4
3
  import {MathNode, TextNode} from "../mathMLTree";
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import defineFunction, {ordargument} from "../defineFunction";
3
2
  import {makeFragment, makeSpan, makeVList} from "../buildCommon";
4
3
  import {MathNode} from "../mathMLTree";
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import defineFunction, {ordargument} from "../defineFunction";
3
2
  import {makeSpan} from "../buildCommon";
4
3
  import {MathNode} from "../mathMLTree";
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import defineFunction from "../defineFunction";
3
2
  import {makeVList} from "../buildCommon";
4
3
  import {MathNode} from "../mathMLTree";
@@ -1,4 +1,3 @@
1
- //@flow
2
1
  import defineFunction from "../defineFunction";
3
2
 
4
3
  defineFunction({
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {makeSpan} from "../buildCommon";
3
2
  import defineFunction from "../defineFunction";
4
3
  import {MathNode} from "../mathMLTree";
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {makeFragment} from "../buildCommon";
3
2
  import defineFunction from "../defineFunction";
4
3
  import {MathNode} from "../mathMLTree";
@@ -1,9 +1,8 @@
1
- // @flow
2
1
  // smash, with optional [tb], as in AMS
3
2
  import defineFunction from "../defineFunction";
4
3
  import {makeSpan, makeVList} from "../buildCommon";
5
4
  import {MathNode} from "../mathMLTree";
6
- import {assertNodeType} from "../parseNode";
5
+ import {assertNodeType, assertSymbolNodeType} from "../parseNode";
7
6
 
8
7
  import * as html from "../buildHTML";
9
8
  import * as mml from "../buildMathML";
@@ -27,8 +26,7 @@ defineFunction({
27
26
  let letter = "";
28
27
  for (let i = 0; i < tbArg.body.length; ++i) {
29
28
  const node = tbArg.body[i];
30
- // $FlowFixMe: Not every node type has a `text` property.
31
- letter = node.text;
29
+ letter = assertSymbolNodeType(node).text;
32
30
  if (letter === "t") {
33
31
  smashHeight = true;
34
32
  } else if (letter === "b") {
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import defineFunction from "../defineFunction";
3
2
  import {makeSpan, makeVList, wrapFragment} from "../buildCommon";
4
3
  import {MathNode} from "../mathMLTree";
@@ -1,10 +1,10 @@
1
- // @flow
2
1
  import defineFunction from "../defineFunction";
3
2
  import {MathNode} from "../mathMLTree";
4
3
  import Style from "../Style";
5
4
  import {sizingGroup} from "./sizing";
6
5
 
7
6
  import * as mml from "../buildMathML";
7
+ import type {StyleStr} from "../types";
8
8
 
9
9
  const styleMap = {
10
10
  "display": Style.DISPLAY,
@@ -30,8 +30,8 @@ defineFunction({
30
30
 
31
31
  // TODO: Refactor to avoid duplicating styleMap in multiple places (e.g.
32
32
  // here and in buildHTML and de-dupe the enumeration of all the styles).
33
- // $FlowFixMe: The names above exactly match the styles.
34
- const style: StyleStr = funcName.slice(1, funcName.length - 5);
33
+ // TODO(ts): The names above exactly match the styles.
34
+ const style = funcName.slice(1, funcName.length - 5) as StyleStr;
35
35
  return {
36
36
  type: "styling",
37
37
  mode: parser.mode,
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {defineFunctionBuilders} from "../defineFunction";
3
2
  import {makeSpan, makeVList} from "../buildCommon";
4
3
  import {SymbolNode} from "../domTree";
@@ -29,7 +28,7 @@ import type {MathNodeType} from "../mathMLTree";
29
28
  const htmlBuilderDelegate = function(
30
29
  group: ParseNode<"supsub">,
31
30
  options: Options,
32
- ): ?HtmlBuilder<*> {
31
+ ): HtmlBuilder<any> | null | undefined {
33
32
  const base = group.base;
34
33
  if (!base) {
35
34
  return null;
@@ -123,7 +122,7 @@ defineFunctionBuilders({
123
122
  group.base && group.base.type === "op" && group.base.name &&
124
123
  (group.base.name === "\\oiint" || group.base.name === "\\oiiint");
125
124
  if (base instanceof SymbolNode || isOiint) {
126
- // $FlowFixMe
125
+ // @ts-ignore
127
126
  marginLeft = makeEm(-base.italic);
128
127
  }
129
128
  }
@@ -148,9 +147,9 @@ defineFunctionBuilders({
148
147
  }
149
148
 
150
149
  const vlistElem = [
151
- {type: "elem", elem: subm, shift: subShift, marginRight,
150
+ {type: "elem" as const, elem: subm, shift: subShift, marginRight,
152
151
  marginLeft},
153
- {type: "elem", elem: supm, shift: -supShift, marginRight},
152
+ {type: "elem" as const, elem: supm, shift: -supShift, marginRight},
154
153
  ];
155
154
 
156
155
  supsub = makeVList({
@@ -164,7 +163,7 @@ defineFunctionBuilders({
164
163
  subm.height - 0.8 * metrics.xHeight);
165
164
 
166
165
  const vlistElem =
167
- [{type: "elem", elem: subm, marginLeft, marginRight}];
166
+ [{type: "elem" as const, elem: subm, marginLeft, marginRight}];
168
167
 
169
168
  supsub = makeVList({
170
169
  positionType: "shift",
@@ -179,7 +178,7 @@ defineFunctionBuilders({
179
178
  supsub = makeVList({
180
179
  positionType: "shift",
181
180
  positionData: -supShift,
182
- children: [{type: "elem", elem: supm, marginRight}],
181
+ children: [{type: "elem" as const, elem: supm, marginRight}],
183
182
  }, options);
184
183
  } else {
185
184
  throw new Error("supsub must have either sup or sub.");
@@ -264,4 +263,3 @@ defineFunctionBuilders({
264
263
  return new MathNode(nodeType, children);
265
264
  },
266
265
  });
267
-
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {defineFunctionBuilders} from "../defineFunction";
3
2
  import {mathsym} from "../buildCommon";
4
3
  import {MathNode} from "../mathMLTree";
@@ -31,4 +30,3 @@ defineFunctionBuilders({
31
30
  return node;
32
31
  },
33
32
  });
34
-
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {defineFunctionBuilders} from "../defineFunction";
3
2
  import {makeOrd} from "../buildCommon";
4
3
  import {MathNode} from "../mathMLTree";
@@ -10,7 +9,7 @@ import type {ParseNode} from "../parseNode";
10
9
  // "mathord" and "textord" ParseNodes created in Parser.js from symbol Groups in
11
10
  // src/symbols.js.
12
11
 
13
- const defaultVariant: {[string]: string} = {
12
+ const defaultVariant: Record<string, string> = {
14
13
  "mi": "italic",
15
14
  "mn": "normal",
16
15
  "mtext": "normal",
@@ -1,11 +1,10 @@
1
- // @flow
2
1
  import {defineFunctionBuilders} from "../defineFunction";
3
2
  import {mathsym, makeOrd, makeSpan} from "../buildCommon";
4
3
  import {MathNode, TextNode} from "../mathMLTree";
5
4
  import ParseError from "../ParseError";
6
5
 
7
6
  // A map of CSS-based spacing functions to their CSS class.
8
- const cssSpace: {[string]: string} = {
7
+ const cssSpace: Record<string, string> = {
9
8
  "\\nobreak": "nobreak",
10
9
  "\\allowbreak": "allowbreak",
11
10
  };
@@ -15,7 +14,7 @@ const cssSpace: {[string]: string} = {
15
14
  // in this table, then it should be a regular space character. Furthermore,
16
15
  // the associated value may have a `className` specifying an extra CSS class
17
16
  // to add to the created `span`.
18
- const regularSpace: {[string]: { className?: string }} = {
17
+ const regularSpace: Record<string, {className?: string}> = {
19
18
  " ": {},
20
19
  "\\ ": {},
21
20
  "~": {
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {defineFunctionBuilders} from "../defineFunction";
3
2
  import {MathNode} from "../mathMLTree";
4
3
 
@@ -37,4 +36,3 @@ defineFunctionBuilders({
37
36
  // need to rewrite the way this function is called.
38
37
  },
39
38
  });
40
-
@@ -1,27 +1,28 @@
1
- // @flow
2
1
  import defineFunction, {ordargument} from "../defineFunction";
3
2
  import {makeSpan} from "../buildCommon";
4
3
 
5
4
  import * as html from "../buildHTML";
6
5
  import * as mml from "../buildMathML";
6
+ import type Options from "../Options";
7
+ import type {ParseNode} from "../parseNode";
7
8
 
8
9
  // Non-mathy text, possibly in a font
9
- const textFontFamilies = {
10
+ const textFontFamilies: Record<string, string | undefined> = {
10
11
  "\\text": undefined, "\\textrm": "textrm", "\\textsf": "textsf",
11
12
  "\\texttt": "texttt", "\\textnormal": "textrm",
12
13
  };
13
14
 
14
- const textFontWeights = {
15
+ const textFontWeights: Record<string, "textbf" | "textmd"> = {
15
16
  "\\textbf": "textbf",
16
17
  "\\textmd": "textmd",
17
18
  };
18
19
 
19
- const textFontShapes = {
20
+ const textFontShapes: Record<string, "textit" | "textup"> = {
20
21
  "\\textit": "textit",
21
22
  "\\textup": "textup",
22
23
  };
23
24
 
24
- const optionsWithFont = (group, options) => {
25
+ const optionsWithFont = (group: ParseNode<"text">, options: Options): Options => {
25
26
  const font = group.font;
26
27
  // Checks if the argument is a font family or a font style.
27
28
  if (!font) {
@@ -36,7 +37,7 @@ const optionsWithFont = (group, options) => {
36
37
  options.withTextFontShape("textit");
37
38
  }
38
39
 
39
- return options.withTextFontShape(textFontShapes[font]);
40
+ return options.withTextFontShape(textFontShapes[font] as "textit" | "textup");
40
41
  };
41
42
 
42
43
  defineFunction({
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import defineFunction from "../defineFunction";
3
2
  import {makeLineSpan, makeSpan, makeVList} from "../buildCommon";
4
3
  import {MathNode, TextNode} from "../mathMLTree";
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {makeSpan, makeVList} from "../../buildCommon";
3
2
  import * as html from "../../buildHTML";
4
3
  import {isCharacterBox} from "../../utils";
@@ -12,8 +11,8 @@ import {makeEm} from "../../units";
12
11
 
13
12
  export const assembleSupSub = (
14
13
  base: DomSpan | SymbolNode,
15
- supGroup: ?AnyParseNode,
16
- subGroup: ?AnyParseNode,
14
+ supGroup: AnyParseNode | null | undefined,
15
+ subGroup: AnyParseNode | null | undefined,
17
16
  options: Options,
18
17
  style: StyleInterface,
19
18
  slant: number,
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import defineFunction from "../defineFunction";
3
2
  import {makeVList} from "../buildCommon";
4
3
  import {MathNode} from "../mathMLTree";
@@ -41,4 +40,3 @@ defineFunction({
41
40
  "mpadded", [mml.buildGroup(group.body, options)], ["vcenter"]);
42
41
  },
43
42
  });
44
-
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import defineFunction from "../defineFunction";
3
2
  import {makeSpan, makeSymbol, tryCombineChars} from "../buildCommon";
4
3
  import {MathNode, TextNode} from "../mathMLTree";
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /** Include this to ensure that all functions are defined. */
3
2
  import {_functions} from "./defineFunction";
4
3
 
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /**
3
2
  * Predefined macros for KaTeX.
4
3
  * This can be used to define some commands in terms of others.
@@ -15,6 +14,7 @@ import symbols from "./symbols";
15
14
  import {makeEm} from "./units";
16
15
  import ParseError from "./ParseError";
17
16
 
17
+ import type {MacroContextInterface} from "./defineMacro";
18
18
 
19
19
  //////////////////////////////////////////////////////////////////////
20
20
  // macro tools
@@ -88,7 +88,7 @@ defineMacro("\\TextOrMath", function(context) {
88
88
  });
89
89
 
90
90
  // Lookup table for parsing numbers in base 8 through 16
91
- const digitToNumber = {
91
+ const digitToNumber: Record<string, number> = {
92
92
  "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8,
93
93
  "9": 9, "a": 10, "A": 10, "b": 11, "B": 11, "c": 12, "C": 12,
94
94
  "d": 13, "D": 13, "e": 14, "E": 14, "f": 15, "F": 15,
@@ -106,7 +106,7 @@ const digitToNumber = {
106
106
  defineMacro("\\char", function(context) {
107
107
  let token = context.popToken();
108
108
  let base;
109
- let number = '';
109
+ let number = 0;
110
110
  if (token.text === "'") {
111
111
  base = 8;
112
112
  token = context.popToken();
@@ -146,7 +146,10 @@ defineMacro("\\char", function(context) {
146
146
  // \renewcommand{\macro}[args]{definition}
147
147
  // TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
148
148
  const newcommand = (
149
- context, existsOK: boolean, nonexistsOK: boolean, skipIfExists: boolean
149
+ context: MacroContextInterface,
150
+ existsOK: boolean,
151
+ nonexistsOK: boolean,
152
+ skipIfExists: boolean,
150
153
  ) => {
151
154
  let arg = context.consumeArg().tokens;
152
155
  if (arg.length !== 1) {
@@ -332,7 +335,6 @@ defineMacro("\u231E", "\\llcorner");
332
335
  defineMacro("\u231F", "\\lrcorner");
333
336
  defineMacro("\u00A9", "\\copyright");
334
337
  defineMacro("\u00AE", "\\textregistered");
335
- defineMacro("\uFE0F", "\\textregistered");
336
338
 
337
339
  // The KaTeX fonts have corners at codepoints that don't match Unicode.
338
340
  // For MathML purposes, use the Unicode code point.
@@ -394,7 +396,7 @@ defineMacro("\\dddot", "{\\overset{\\raisebox{-0.1ex}{\\normalsize ...}}{#1}}");
394
396
  defineMacro("\\ddddot", "{\\overset{\\raisebox{-0.1ex}{\\normalsize ....}}{#1}}");
395
397
 
396
398
  // AMSMath's automatic \dots, based on \mdots@@ macro.
397
- const dotsByToken = {
399
+ const dotsByToken: Record<string, string> = {
398
400
  ',': '\\dotsc',
399
401
  '\\not': '\\dotsb',
400
402
  // \keybin@ checks for the following:
@@ -919,7 +921,7 @@ defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
919
921
  defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
920
922
  defineMacro("\\Bra", "\\left\\langle#1\\right|");
921
923
  defineMacro("\\Ket", "\\left|#1\\right\\rangle");
922
- const braketHelper = (one) => (context) => {
924
+ const braketHelper = (one: boolean) => (context: MacroContextInterface) => {
923
925
  const left = context.consumeArg().tokens;
924
926
  const middle = context.consumeArg().tokens;
925
927
  const middleDouble = context.consumeArg().tokens;
@@ -927,7 +929,7 @@ const braketHelper = (one) => (context) => {
927
929
  const oldMiddle = context.macros.get("|");
928
930
  const oldMiddleDouble = context.macros.get("\\|");
929
931
  context.macros.beginGroup();
930
- const midMacro = (double) => (context) => {
932
+ const midMacro = (double: boolean) => (context: MacroContextInterface) => {
931
933
  if (one) {
932
934
  // Only modify the first instance of | or \|
933
935
  context.macros.set("|", oldMiddle);
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /**
3
2
  * These objects store data about MathML nodes. This is the MathML equivalent
4
3
  * of the types in domTree.js. Since MathML handles its own rendering, and
@@ -35,7 +34,7 @@ export interface MathDomNode extends VirtualNode {
35
34
 
36
35
  export type documentFragment = DocumentFragment<MathDomNode>;
37
36
  export function newDocumentFragment(
38
- children: $ReadOnlyArray<MathDomNode>
37
+ children: ReadonlyArray<MathDomNode>
39
38
  ): documentFragment {
40
39
  return new DocumentFragment(children);
41
40
  }
@@ -47,13 +46,13 @@ export function newDocumentFragment(
47
46
  */
48
47
  export class MathNode implements MathDomNode {
49
48
  type: MathNodeType;
50
- attributes: {[string]: string};
51
- children: $ReadOnlyArray<MathDomNode>;
49
+ attributes: Record<string, string>;
50
+ children: MathDomNode[];
52
51
  classes: string[];
53
52
 
54
53
  constructor(
55
54
  type: MathNodeType,
56
- children?: $ReadOnlyArray<MathDomNode>,
55
+ children?: MathDomNode[],
57
56
  classes?: string[]
58
57
  ) {
59
58
  this.type = type;
@@ -190,7 +189,7 @@ export class TextNode implements MathDomNode {
190
189
  */
191
190
  export class SpaceNode implements MathDomNode {
192
191
  width: number;
193
- character: ?string;
192
+ character: string | null | undefined;
194
193
 
195
194
  /**
196
195
  * Create a Space node with width given in CSS ems.