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.
- package/README.md +3 -3
- package/contrib/auto-render/{auto-render.js → auto-render.ts} +41 -19
- package/contrib/auto-render/{splitAtDelimiters.js → splitAtDelimiters.ts} +18 -4
- package/contrib/auto-render/test/{auto-render-spec.js → auto-render-spec.ts} +10 -2
- package/contrib/copy-tex/README.md +2 -2
- package/contrib/copy-tex/{copy-tex.js → copy-tex.ts} +4 -6
- package/contrib/copy-tex/{katex2tex.js → katex2tex.ts} +2 -3
- package/contrib/mathtex-script-type/README.md +5 -5
- package/contrib/mhchem/README.md +1 -1
- package/contrib/render-a11y-string/{render-a11y-string.js → render-a11y-string.ts} +18 -33
- package/contrib/render-a11y-string/test/{render-a11y-string-spec.js → render-a11y-string-spec.ts} +0 -1
- package/dist/README.md +3 -3
- package/dist/contrib/auto-render.js +24 -57
- package/dist/contrib/auto-render.min.js +1 -1
- package/dist/contrib/auto-render.mjs +16586 -210
- package/dist/contrib/copy-tex.js +23 -37
- package/dist/contrib/copy-tex.min.js +1 -1
- package/dist/contrib/copy-tex.mjs +77 -95
- package/dist/contrib/mathtex-script-type.js +0 -3
- package/dist/contrib/mathtex-script-type.mjs +16427 -4
- package/dist/contrib/mhchem.js +55 -303
- package/dist/contrib/mhchem.mjs +12884 -723
- package/dist/contrib/render-a11y-string.js +13 -108
- package/dist/contrib/render-a11y-string.min.js +1 -1
- package/dist/contrib/render-a11y-string.mjs +17020 -760
- package/dist/katex-swap.css +2 -1
- package/dist/katex-swap.min.css +1 -1
- package/dist/katex.css +2 -1
- package/dist/katex.js +4547 -5680
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +11854 -13828
- package/{katex.js → katex.ts} +8 -5
- package/package.json +34 -31
- package/src/{Lexer.js → Lexer.ts} +1 -2
- package/src/{MacroExpander.js → MacroExpander.ts} +11 -15
- package/src/{Namespace.js → Namespace.ts} +4 -6
- package/src/{Options.js → Options.ts} +7 -12
- package/src/{ParseError.js → ParseError.ts} +16 -26
- package/src/{Parser.js → Parser.ts} +68 -56
- package/src/{Settings.js → Settings.ts} +70 -70
- package/src/{SourceLocation.js → SourceLocation.ts} +6 -7
- package/src/{Style.js → Style.ts} +4 -5
- package/src/{Token.js → Token.ts} +8 -6
- package/src/{buildCommon.js → buildCommon.ts} +62 -55
- package/src/{buildHTML.js → buildHTML.ts} +29 -25
- package/src/{buildMathML.js → buildMathML.ts} +15 -13
- package/src/{buildTree.js → buildTree.ts} +1 -2
- package/src/{defineEnvironment.js → defineEnvironment.ts} +26 -27
- package/src/{defineFunction.js → defineFunction.ts} +54 -56
- package/src/{defineMacro.js → defineMacro.ts} +12 -13
- package/src/{delimiter.js → delimiter.ts} +19 -17
- package/src/{domTree.js → domTree.ts} +94 -103
- package/src/environments/{array.js → array.ts} +109 -99
- package/src/environments/{cd.js → cd.ts} +9 -11
- package/src/{environments.js → environments.ts} +0 -1
- package/src/{fontMetrics.js → fontMetrics.ts} +10 -12
- package/src/fontMetricsData.d.ts +3 -0
- package/src/functions/{accent.js → accent.ts} +1 -2
- package/src/functions/{accentunder.js → accentunder.ts} +0 -1
- package/src/functions/{arrow.js → arrow.ts} +4 -6
- package/src/functions/{char.js → char.ts} +0 -1
- package/src/functions/{color.js → color.ts} +5 -6
- package/src/functions/{cr.js → cr.ts} +0 -1
- package/src/functions/{def.js → def.ts} +9 -7
- package/src/functions/{delimsizing.js → delimsizing.ts} +11 -9
- package/src/functions/{enclose.js → enclose.ts} +3 -4
- package/src/functions/{environment.js → environment.ts} +2 -3
- package/src/functions/{font.js → font.ts} +4 -4
- package/src/functions/{genfrac.js → genfrac.ts} +14 -15
- package/src/functions/{hbox.js → hbox.ts} +0 -1
- package/src/functions/{horizBrace.js → horizBrace.ts} +4 -5
- package/src/functions/{href.js → href.ts} +4 -4
- package/src/functions/{html.js → html.ts} +3 -3
- package/src/functions/{htmlmathml.js → htmlmathml.ts} +0 -1
- package/src/functions/{includegraphics.js → includegraphics.ts} +0 -1
- package/src/functions/{kern.js → kern.ts} +0 -1
- package/src/functions/{lap.js → lap.ts} +0 -1
- package/src/functions/{math.js → math.ts} +0 -1
- package/src/functions/{mathchoice.js → mathchoice.ts} +2 -2
- package/src/functions/{mclass.js → mclass.ts} +5 -6
- package/src/functions/{op.js → op.ts} +9 -11
- package/src/functions/{operatorname.js → operatorname.ts} +4 -7
- package/src/functions/{ordgroup.js → ordgroup.ts} +0 -2
- package/src/functions/{overline.js → overline.ts} +0 -1
- package/src/functions/{phantom.js → phantom.ts} +0 -1
- package/src/functions/{pmb.js → pmb.ts} +0 -1
- package/src/functions/{raisebox.js → raisebox.ts} +0 -1
- package/src/functions/{relax.js → relax.ts} +0 -1
- package/src/functions/{rule.js → rule.ts} +0 -1
- package/src/functions/{sizing.js → sizing.ts} +0 -1
- package/src/functions/{smash.js → smash.ts} +2 -4
- package/src/functions/{sqrt.js → sqrt.ts} +0 -1
- package/src/functions/{styling.js → styling.ts} +3 -3
- package/src/functions/{supsub.js → supsub.ts} +6 -8
- package/src/functions/{symbolsOp.js → symbolsOp.ts} +0 -2
- package/src/functions/{symbolsOrd.js → symbolsOrd.ts} +1 -2
- package/src/functions/{symbolsSpacing.js → symbolsSpacing.ts} +2 -3
- package/src/functions/{tag.js → tag.ts} +0 -2
- package/src/functions/{text.js → text.ts} +7 -6
- package/src/functions/{underline.js → underline.ts} +0 -1
- package/src/functions/utils/{assembleSupSub.js → assembleSupSub.ts} +2 -3
- package/src/functions/{vcenter.js → vcenter.ts} +0 -2
- package/src/functions/{verb.js → verb.ts} +0 -1
- package/src/{functions.js → functions.ts} +0 -1
- package/src/{macros.js → macros.ts} +10 -8
- package/src/{mathMLTree.js → mathMLTree.ts} +5 -6
- package/src/parseNode.ts +522 -0
- package/src/{parseTree.js → parseTree.ts} +5 -3
- package/src/{spacingData.js → spacingData.ts} +11 -12
- package/src/{stretchy.js → stretchy.ts} +7 -7
- package/src/styles/katex-swap.scss +1 -4
- package/src/styles/katex.scss +9 -0
- package/src/{svgGeometry.js → svgGeometry.ts} +1 -2
- package/src/{symbols.js → symbols.ts} +6 -6
- package/src/{tree.js → tree.ts} +5 -7
- package/src/{types.js → types.ts} +1 -2
- package/src/unicodeAccents.js +4 -1
- package/src/{unicodeScripts.js → unicodeScripts.ts} +1 -3
- package/src/{unicodeSupOrSub.js → unicodeSupOrSub.ts} +1 -1
- package/src/unicodeSymbols.js +4 -3
- package/src/{units.js → units.ts} +2 -4
- package/src/{utils.js → utils.ts} +2 -3
- package/src/{wide-character.js → wide-character.ts} +8 -10
- package/types/katex.d.ts +13 -12
- package/src/parseNode.js +0 -523
|
@@ -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";
|
|
@@ -8,9 +7,10 @@ import * as html from "../buildHTML";
|
|
|
8
7
|
import * as mml from "../buildMathML";
|
|
9
8
|
|
|
10
9
|
import type {ParseNode} from "../parseNode";
|
|
10
|
+
import type {MathDomNode} from "../mathMLTree";
|
|
11
11
|
|
|
12
12
|
// Helper function
|
|
13
|
-
const paddedNode = group => {
|
|
13
|
+
const paddedNode = (group?: MathDomNode | null | undefined) => {
|
|
14
14
|
const node = new MathNode("mpadded", group ? [group] : []);
|
|
15
15
|
node.setAttribute("width", "+0.6em");
|
|
16
16
|
node.setAttribute("lspace", "0.3em");
|
|
@@ -46,8 +46,6 @@ defineFunction({
|
|
|
46
46
|
below: optArgs[0],
|
|
47
47
|
};
|
|
48
48
|
},
|
|
49
|
-
// Flow is unable to correctly infer the type of `group`, even though it's
|
|
50
|
-
// unambiguously determined from the passed-in `type` above.
|
|
51
49
|
htmlBuilder(group: ParseNode<"xArrow">, options) {
|
|
52
50
|
const style = options.style;
|
|
53
51
|
|
|
@@ -108,8 +106,8 @@ defineFunction({
|
|
|
108
106
|
}, options);
|
|
109
107
|
}
|
|
110
108
|
|
|
111
|
-
//
|
|
112
|
-
vlist.children[0].children[0].children[1].classes.push("svg-align");
|
|
109
|
+
// TODO(ts): Replace this with passing "svg-align" into makeVList.
|
|
110
|
+
(vlist as any).children[0].children[0].children[1].classes.push("svg-align");
|
|
113
111
|
|
|
114
112
|
return makeSpan(["mrel", "x-arrow"], [vlist], options);
|
|
115
113
|
},
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import defineFunction, {ordargument} from "../defineFunction";
|
|
3
2
|
import {makeFragment} from "../buildCommon";
|
|
4
3
|
import {MathNode} from "../mathMLTree";
|
|
5
4
|
import {assertNodeType} from "../parseNode";
|
|
6
|
-
|
|
7
|
-
import type {
|
|
5
|
+
import type {AnyParseNode} from "../parseNode";
|
|
6
|
+
import type {HtmlBuilder, MathMLBuilder} from "../defineFunction";
|
|
8
7
|
|
|
9
8
|
import * as html from "../buildHTML";
|
|
10
9
|
import * as mml from "../buildMathML";
|
|
11
10
|
|
|
12
|
-
const htmlBuilder = (group, options) => {
|
|
11
|
+
const htmlBuilder: HtmlBuilder<"color"> = (group, options) => {
|
|
13
12
|
const elements = html.buildExpression(
|
|
14
13
|
group.body,
|
|
15
14
|
options.withColor(group.color),
|
|
@@ -23,7 +22,7 @@ const htmlBuilder = (group, options) => {
|
|
|
23
22
|
return makeFragment(elements);
|
|
24
23
|
};
|
|
25
24
|
|
|
26
|
-
const mathmlBuilder = (group, options) => {
|
|
25
|
+
const mathmlBuilder: MathMLBuilder<"color"> = (group, options) => {
|
|
27
26
|
const inner = mml.buildExpression(group.body,
|
|
28
27
|
options.withColor(group.color));
|
|
29
28
|
|
|
@@ -49,7 +48,7 @@ defineFunction({
|
|
|
49
48
|
type: "color",
|
|
50
49
|
mode: parser.mode,
|
|
51
50
|
color,
|
|
52
|
-
body: (ordargument(body)
|
|
51
|
+
body: (ordargument(body) as AnyParseNode[]),
|
|
53
52
|
};
|
|
54
53
|
},
|
|
55
54
|
htmlBuilder,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
//@flow
|
|
2
1
|
import defineFunction from "../defineFunction";
|
|
3
2
|
import ParseError from "../ParseError";
|
|
4
3
|
import {assertNodeType} from "../parseNode";
|
|
4
|
+
import {Token} from "../Token";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import type Parser from "../Parser";
|
|
7
|
+
|
|
8
|
+
const globalMap: Record<string, string> = {
|
|
7
9
|
"\\global": "\\global",
|
|
8
10
|
"\\long": "\\\\globallong",
|
|
9
11
|
"\\\\globallong": "\\\\globallong",
|
|
@@ -15,7 +17,7 @@ const globalMap = {
|
|
|
15
17
|
"\\futurelet": "\\\\globalfuture",
|
|
16
18
|
};
|
|
17
19
|
|
|
18
|
-
const checkControlSequence = (tok) => {
|
|
20
|
+
const checkControlSequence = (tok: Token): string => {
|
|
19
21
|
const name = tok.text;
|
|
20
22
|
if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
|
|
21
23
|
throw new ParseError("Expected a control sequence", tok);
|
|
@@ -23,7 +25,7 @@ const checkControlSequence = (tok) => {
|
|
|
23
25
|
return name;
|
|
24
26
|
};
|
|
25
27
|
|
|
26
|
-
const getRHS = (parser) => {
|
|
28
|
+
const getRHS = (parser: Parser): Token => {
|
|
27
29
|
let tok = parser.gullet.popToken();
|
|
28
30
|
if (tok.text === "=") { // consume optional equals
|
|
29
31
|
tok = parser.gullet.popToken();
|
|
@@ -34,7 +36,7 @@ const getRHS = (parser) => {
|
|
|
34
36
|
return tok;
|
|
35
37
|
};
|
|
36
38
|
|
|
37
|
-
const letCommand = (parser, name, tok, global) => {
|
|
39
|
+
const letCommand = (parser: Parser, name: string, tok: Token, global: boolean) => {
|
|
38
40
|
let macro = parser.gullet.macros.get(tok.text);
|
|
39
41
|
if (macro == null) {
|
|
40
42
|
// don't expand it later even if a macro with the same name is defined
|
|
@@ -98,8 +100,8 @@ defineFunction({
|
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
let numArgs = 0;
|
|
101
|
-
let insert;
|
|
102
|
-
const delimiters = [[]];
|
|
103
|
+
let insert: Token | undefined;
|
|
104
|
+
const delimiters: string[][] = [[]];
|
|
103
105
|
// <parameter text> contains no braces
|
|
104
106
|
while (parser.gullet.future().text !== "{") {
|
|
105
107
|
tok = parser.gullet.popToken();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import {makeSpan} from "../buildCommon";
|
|
3
2
|
import defineFunction from "../defineFunction";
|
|
4
3
|
import {makeLeftRightDelim, makeSizedDelim, sizeToMaxHeight} from "../delimiter";
|
|
@@ -15,7 +14,10 @@ import type {AnyParseNode, ParseNode, SymbolParseNode} from "../parseNode";
|
|
|
15
14
|
import type {FunctionContext} from "../defineFunction";
|
|
16
15
|
|
|
17
16
|
// Extra data needed for the delimiter handler down below
|
|
18
|
-
const delimiterSizes
|
|
17
|
+
const delimiterSizes: Record<string, {
|
|
18
|
+
mclass: "mopen" | "mclose" | "mrel" | "mord";
|
|
19
|
+
size: 1 | 2 | 3 | 4;
|
|
20
|
+
}> = {
|
|
19
21
|
"\\bigl" : {mclass: "mopen", size: 1},
|
|
20
22
|
"\\Bigl" : {mclass: "mopen", size: 2},
|
|
21
23
|
"\\biggl": {mclass: "mopen", size: 3},
|
|
@@ -161,7 +163,7 @@ defineFunction({
|
|
|
161
163
|
type: "leftright-right",
|
|
162
164
|
mode: context.parser.mode,
|
|
163
165
|
delim: checkDelimiter(args[0], context).text,
|
|
164
|
-
color, // undefined if not set via \color
|
|
166
|
+
color: color as string | null | undefined, // undefined if not set via \color
|
|
165
167
|
};
|
|
166
168
|
},
|
|
167
169
|
});
|
|
@@ -209,8 +211,8 @@ defineFunction({
|
|
|
209
211
|
for (let i = 0; i < inner.length; i++) {
|
|
210
212
|
// Property `isMiddle` not defined on `span`. See comment in
|
|
211
213
|
// "middle"'s htmlBuilder.
|
|
212
|
-
//
|
|
213
|
-
if (inner[i].isMiddle) {
|
|
214
|
+
// TODO(ts)
|
|
215
|
+
if ((inner[i] as any).isMiddle) {
|
|
214
216
|
hadMiddle = true;
|
|
215
217
|
} else {
|
|
216
218
|
innerHeight = Math.max(inner[i].height, innerHeight);
|
|
@@ -244,8 +246,8 @@ defineFunction({
|
|
|
244
246
|
const middleDelim = inner[i];
|
|
245
247
|
// Property `isMiddle` not defined on `span`. See comment in
|
|
246
248
|
// "middle"'s htmlBuilder.
|
|
247
|
-
//
|
|
248
|
-
const isMiddle: IsMiddle = middleDelim.isMiddle;
|
|
249
|
+
// TODO(ts)
|
|
250
|
+
const isMiddle: IsMiddle = (middleDelim as any).isMiddle;
|
|
249
251
|
if (isMiddle) {
|
|
250
252
|
// Apply the options that were active when \middle was called
|
|
251
253
|
inner[i] = makeLeftRightDelim(
|
|
@@ -334,8 +336,8 @@ defineFunction({
|
|
|
334
336
|
// this file above.
|
|
335
337
|
// TODO: Fix this violation of the `span` type and possibly rename
|
|
336
338
|
// things since `isMiddle` sounds like a boolean, but is a struct.
|
|
337
|
-
//
|
|
338
|
-
middleDelim.isMiddle = isMiddle;
|
|
339
|
+
// TODO(ts)
|
|
340
|
+
(middleDelim as any).isMiddle = isMiddle;
|
|
339
341
|
}
|
|
340
342
|
return middleDelim;
|
|
341
343
|
},
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import defineFunction from "../defineFunction";
|
|
3
2
|
import {makeSpan, makeSvgSpan, makeVList, wrapFragment} from "../buildCommon";
|
|
4
3
|
import {isCharacterBox} from "../utils";
|
|
@@ -11,9 +10,9 @@ import {assertNodeType} from "../parseNode";
|
|
|
11
10
|
|
|
12
11
|
import * as html from "../buildHTML";
|
|
13
12
|
import * as mml from "../buildMathML";
|
|
13
|
+
import type {HtmlBuilder, MathMLBuilder} from "../defineFunction";
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
const htmlBuilder = (group, options) => {
|
|
15
|
+
const htmlBuilder: HtmlBuilder<"enclose"> = (group, options) => {
|
|
17
16
|
// \cancel, \bcancel, \xcancel, \sout, \fbox, \colorbox, \fcolorbox, \phase
|
|
18
17
|
// Some groups can return document fragments. Handle those by wrapping
|
|
19
18
|
// them in a span.
|
|
@@ -165,7 +164,7 @@ const htmlBuilder = (group, options) => {
|
|
|
165
164
|
}
|
|
166
165
|
};
|
|
167
166
|
|
|
168
|
-
const mathmlBuilder = (group, options) => {
|
|
167
|
+
const mathmlBuilder: MathMLBuilder<"enclose"> = (group, options) => {
|
|
169
168
|
let fboxsep = 0;
|
|
170
169
|
const node = new MathNode(
|
|
171
170
|
group.label.includes("colorbox") ? "mpadded" : "menclose",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import defineFunction from "../defineFunction";
|
|
3
2
|
import ParseError from "../ParseError";
|
|
4
3
|
import {assertNodeType} from "../parseNode";
|
|
@@ -48,8 +47,8 @@ defineFunction({
|
|
|
48
47
|
`Mismatch: \\begin{${envName}} matched by \\end{${end.name}}`,
|
|
49
48
|
endNameToken);
|
|
50
49
|
}
|
|
51
|
-
//
|
|
52
|
-
return result;
|
|
50
|
+
// TODO(ts), "environment" handler returns an environment ParseNode
|
|
51
|
+
return result as any;
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
return {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
// TODO(kevinb): implement \\sl and \\sc
|
|
3
2
|
|
|
4
3
|
import {binrelClass} from "./mclass";
|
|
@@ -8,21 +7,22 @@ import {isCharacterBox} from "../utils";
|
|
|
8
7
|
import * as html from "../buildHTML";
|
|
9
8
|
import * as mml from "../buildMathML";
|
|
10
9
|
|
|
10
|
+
import type Options from "../Options";
|
|
11
11
|
import type {ParseNode} from "../parseNode";
|
|
12
12
|
|
|
13
|
-
const htmlBuilder = (group: ParseNode<"font">, options) => {
|
|
13
|
+
const htmlBuilder = (group: ParseNode<"font">, options: Options) => {
|
|
14
14
|
const font = group.font;
|
|
15
15
|
const newOptions = options.withFont(font);
|
|
16
16
|
return html.buildGroup(group.body, newOptions);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
const mathmlBuilder = (group: ParseNode<"font">, options) => {
|
|
19
|
+
const mathmlBuilder = (group: ParseNode<"font">, options: Options) => {
|
|
20
20
|
const font = group.font;
|
|
21
21
|
const newOptions = options.withFont(font);
|
|
22
22
|
return mml.buildGroup(group.body, newOptions);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const fontAliases = {
|
|
25
|
+
const fontAliases: Record<string, string> = {
|
|
26
26
|
"\\Bbb": "\\mathbb",
|
|
27
27
|
"\\bold": "\\mathbf",
|
|
28
28
|
"\\frak": "\\mathfrak",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import defineFunction, {normalizeArgument} from "../defineFunction";
|
|
3
2
|
import {makeLineSpan, makeSpan, makeVList} from "../buildCommon";
|
|
4
3
|
import {makeCustomSizedDelim} from "../delimiter";
|
|
@@ -6,13 +5,13 @@ import {MathNode, TextNode} from "../mathMLTree";
|
|
|
6
5
|
import type {ParseNode} from "../parseNode";
|
|
7
6
|
import Style from "../Style";
|
|
8
7
|
import {assertNodeType} from "../parseNode";
|
|
9
|
-
import type {StyleStr} from "../types";
|
|
10
|
-
|
|
11
8
|
import * as html from "../buildHTML";
|
|
12
9
|
import * as mml from "../buildMathML";
|
|
13
10
|
import {calculateSize, makeEm} from "../units";
|
|
11
|
+
import type {StyleStr} from "../types";
|
|
12
|
+
import type {HtmlBuilder, MathMLBuilder} from "../defineFunction";
|
|
14
13
|
|
|
15
|
-
const htmlBuilder = (group, options) => {
|
|
14
|
+
const htmlBuilder: HtmlBuilder<"genfrac"> = (group, options) => {
|
|
16
15
|
// Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
|
|
17
16
|
const style = options.style;
|
|
18
17
|
|
|
@@ -165,7 +164,7 @@ const htmlBuilder = (group, options) => {
|
|
|
165
164
|
options);
|
|
166
165
|
};
|
|
167
166
|
|
|
168
|
-
const mathmlBuilder = (group, options) => {
|
|
167
|
+
const mathmlBuilder: MathMLBuilder<"genfrac"> = (group, options) => {
|
|
169
168
|
const node = new MathNode(
|
|
170
169
|
"mfrac",
|
|
171
170
|
[
|
|
@@ -228,7 +227,7 @@ const wrapWithStyle = (
|
|
|
228
227
|
body: [frac],
|
|
229
228
|
};
|
|
230
229
|
|
|
231
|
-
//
|
|
230
|
+
// @ts-ignore defineFunction handler needs to return ParseNode<"genfrac">
|
|
232
231
|
return wrapper;
|
|
233
232
|
};
|
|
234
233
|
|
|
@@ -247,9 +246,9 @@ defineFunction({
|
|
|
247
246
|
handler: ({parser, funcName}, args) => {
|
|
248
247
|
const numer = args[0];
|
|
249
248
|
const denom = args[1];
|
|
250
|
-
let hasBarLine;
|
|
251
|
-
let leftDelim = null;
|
|
252
|
-
let rightDelim = null;
|
|
249
|
+
let hasBarLine: boolean;
|
|
250
|
+
let leftDelim: string | null = null;
|
|
251
|
+
let rightDelim: string | null = null;
|
|
253
252
|
|
|
254
253
|
switch (funcName) {
|
|
255
254
|
case "\\cfrac":
|
|
@@ -285,9 +284,9 @@ defineFunction({
|
|
|
285
284
|
const continued = funcName === "\\cfrac";
|
|
286
285
|
let style = null;
|
|
287
286
|
if (continued || funcName.startsWith("\\d")) {
|
|
288
|
-
style = "display";
|
|
287
|
+
style = "display" as StyleStr;
|
|
289
288
|
} else if (funcName.startsWith("\\t")) {
|
|
290
|
-
style = "text";
|
|
289
|
+
style = "text" as StyleStr;
|
|
291
290
|
}
|
|
292
291
|
|
|
293
292
|
return wrapWithStyle({
|
|
@@ -346,7 +345,7 @@ defineFunction({
|
|
|
346
345
|
},
|
|
347
346
|
});
|
|
348
347
|
|
|
349
|
-
const stylArray = ["display", "text", "script", "scriptscript"];
|
|
348
|
+
const stylArray: StyleStr[] = ["display", "text", "script", "scriptscript"];
|
|
350
349
|
|
|
351
350
|
const delimFromValue = function(delimString: string): string | null {
|
|
352
351
|
let delim = null;
|
|
@@ -378,7 +377,7 @@ defineFunction({
|
|
|
378
377
|
? delimFromValue(rightNode.text) : null;
|
|
379
378
|
|
|
380
379
|
const barNode = assertNodeType(args[2], "size");
|
|
381
|
-
let hasBarLine;
|
|
380
|
+
let hasBarLine: boolean;
|
|
382
381
|
let barSize = null;
|
|
383
382
|
if (barNode.isBlank) {
|
|
384
383
|
// \genfrac acts differently than \above.
|
|
@@ -396,11 +395,11 @@ defineFunction({
|
|
|
396
395
|
if (styl.type === "ordgroup") {
|
|
397
396
|
if (styl.body.length > 0) {
|
|
398
397
|
const textOrd = assertNodeType(styl.body[0], "textord");
|
|
399
|
-
size = stylArray[Number(textOrd.text)];
|
|
398
|
+
size = stylArray[Number(textOrd.text)] as StyleStr;
|
|
400
399
|
}
|
|
401
400
|
} else {
|
|
402
401
|
styl = assertNodeType(styl, "textord");
|
|
403
|
-
size = stylArray[Number(styl.text)];
|
|
402
|
+
size = stylArray[Number(styl.text)] as StyleStr;
|
|
404
403
|
}
|
|
405
404
|
|
|
406
405
|
return wrapWithStyle({
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import defineFunction from "../defineFunction";
|
|
3
2
|
import {makeSpan, makeVList} from "../buildCommon";
|
|
4
3
|
import {MathNode} from "../mathMLTree";
|
|
@@ -51,8 +50,8 @@ export const htmlBuilder: HtmlBuilderSupSub<"horizBrace"> = (grp, options) => {
|
|
|
51
50
|
{type: "elem", elem: braceBody},
|
|
52
51
|
],
|
|
53
52
|
}, options);
|
|
54
|
-
//
|
|
55
|
-
vlist.children[0].children[0].children[1].classes.push("svg-align");
|
|
53
|
+
// TODO(ts): Replace this with passing "svg-align" into makeVList.
|
|
54
|
+
(vlist as any).children[0].children[0].children[1].classes.push("svg-align");
|
|
56
55
|
} else {
|
|
57
56
|
vlist = makeVList({
|
|
58
57
|
positionType: "bottom",
|
|
@@ -63,8 +62,8 @@ export const htmlBuilder: HtmlBuilderSupSub<"horizBrace"> = (grp, options) => {
|
|
|
63
62
|
{type: "elem", elem: body},
|
|
64
63
|
],
|
|
65
64
|
}, options);
|
|
66
|
-
//
|
|
67
|
-
vlist.children[0].children[0].children[0].classes.push("svg-align");
|
|
65
|
+
// TODO(ts): Replace this with passing "svg-align" into makeVList.
|
|
66
|
+
(vlist as any).children[0].children[0].children[0].classes.push("svg-align");
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
if (supSubGroup) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import defineFunction, {ordargument} from "../defineFunction";
|
|
3
2
|
import {makeAnchor} from "../buildCommon";
|
|
4
3
|
import {assertNodeType} from "../parseNode";
|
|
@@ -6,6 +5,7 @@ import {MathNode} from "../mathMLTree";
|
|
|
6
5
|
|
|
7
6
|
import * as html from "../buildHTML";
|
|
8
7
|
import * as mml from "../buildMathML";
|
|
8
|
+
import type {ParseNode} from "../parseNode";
|
|
9
9
|
|
|
10
10
|
defineFunction({
|
|
11
11
|
type: "href",
|
|
@@ -42,7 +42,7 @@ defineFunction({
|
|
|
42
42
|
if (!(math instanceof MathNode)) {
|
|
43
43
|
math = new MathNode("mrow", [math]);
|
|
44
44
|
}
|
|
45
|
-
math.setAttribute("href", group.href);
|
|
45
|
+
(math as MathNode).setAttribute("href", group.href);
|
|
46
46
|
return math;
|
|
47
47
|
},
|
|
48
48
|
});
|
|
@@ -65,7 +65,7 @@ defineFunction({
|
|
|
65
65
|
return parser.formatUnsupportedCmd("\\url");
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const chars = [];
|
|
68
|
+
const chars: ParseNode<"textord">[] = [];
|
|
69
69
|
for (let i = 0; i < href.length; i++) {
|
|
70
70
|
let c = href[i];
|
|
71
71
|
if (c === "~") {
|
|
@@ -77,7 +77,7 @@ defineFunction({
|
|
|
77
77
|
text: c,
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
-
const body = {
|
|
80
|
+
const body: ParseNode<"text"> = {
|
|
81
81
|
type: "text",
|
|
82
82
|
mode: parser.mode,
|
|
83
83
|
font: "\\texttt",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import defineFunction, {ordargument} from "../defineFunction";
|
|
3
2
|
import {makeSpan} from "../buildCommon";
|
|
4
3
|
import {assertNodeType} from "../parseNode";
|
|
@@ -6,6 +5,7 @@ import ParseError from "../ParseError";
|
|
|
6
5
|
|
|
7
6
|
import * as html from "../buildHTML";
|
|
8
7
|
import * as mml from "../buildMathML";
|
|
8
|
+
import type {AnyTrustContext} from "../Settings";
|
|
9
9
|
|
|
10
10
|
defineFunction({
|
|
11
11
|
type: "html",
|
|
@@ -24,8 +24,8 @@ defineFunction({
|
|
|
24
24
|
"HTML extension is disabled on strict mode");
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
let trustContext;
|
|
28
|
-
const attributes = {};
|
|
27
|
+
let trustContext: AnyTrustContext;
|
|
28
|
+
const attributes: Record<string, string> = {};
|
|
29
29
|
|
|
30
30
|
switch (funcName) {
|
|
31
31
|
case "\\htmlClass":
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import defineFunction, {ordargument} from "../defineFunction";
|
|
3
2
|
import {makeFragment} from "../buildCommon";
|
|
4
3
|
import Style from "../Style";
|
|
@@ -6,9 +5,10 @@ import Style from "../Style";
|
|
|
6
5
|
import * as html from "../buildHTML";
|
|
7
6
|
import * as mml from "../buildMathML";
|
|
8
7
|
|
|
8
|
+
import type Options from "../Options";
|
|
9
9
|
import type {ParseNode} from "../parseNode";
|
|
10
10
|
|
|
11
|
-
const chooseMathStyle = (group: ParseNode<"mathchoice">, options) => {
|
|
11
|
+
const chooseMathStyle = (group: ParseNode<"mathchoice">, options: Options) => {
|
|
12
12
|
switch (options.style.size) {
|
|
13
13
|
case Style.DISPLAY.size: return group.display;
|
|
14
14
|
case Style.TEXT.size: return group.text;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import defineFunction, {ordargument} from "../defineFunction";
|
|
3
2
|
import {makeSpan} from "../buildCommon";
|
|
4
3
|
import {isCharacterBox} from "../utils";
|
|
@@ -8,14 +7,15 @@ import type {AnyParseNode} from "../parseNode";
|
|
|
8
7
|
import * as html from "../buildHTML";
|
|
9
8
|
import * as mml from "../buildMathML";
|
|
10
9
|
|
|
10
|
+
import type Options from "../Options";
|
|
11
11
|
import type {ParseNode} from "../parseNode";
|
|
12
12
|
|
|
13
|
-
function htmlBuilder(group: ParseNode<"mclass">, options) {
|
|
13
|
+
function htmlBuilder(group: ParseNode<"mclass">, options: Options) {
|
|
14
14
|
const elements = html.buildExpression(group.body, options, true);
|
|
15
15
|
return makeSpan([group.mclass], elements, options);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function mathmlBuilder(group: ParseNode<"mclass">, options) {
|
|
18
|
+
function mathmlBuilder(group: ParseNode<"mclass">, options: Options) {
|
|
19
19
|
let node: MathNode;
|
|
20
20
|
const inner = mml.buildExpression(group.body, options);
|
|
21
21
|
|
|
@@ -133,7 +133,7 @@ defineFunction({
|
|
|
133
133
|
mclass = "mrel"; // for \stackrel
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
const baseOp = {
|
|
136
|
+
const baseOp: ParseNode<"op"> = {
|
|
137
137
|
type: "op",
|
|
138
138
|
mode: baseArg.mode,
|
|
139
139
|
limits: true,
|
|
@@ -144,7 +144,7 @@ defineFunction({
|
|
|
144
144
|
body: ordargument(baseArg),
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
const supsub = {
|
|
147
|
+
const supsub: ParseNode<"supsub"> = {
|
|
148
148
|
type: "supsub",
|
|
149
149
|
mode: shiftedArg.mode,
|
|
150
150
|
base: baseOp,
|
|
@@ -163,4 +163,3 @@ defineFunction({
|
|
|
163
163
|
htmlBuilder,
|
|
164
164
|
mathmlBuilder,
|
|
165
165
|
});
|
|
166
|
-
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
// Limits, symbols
|
|
3
2
|
import defineFunction, {ordargument} from "../defineFunction";
|
|
4
3
|
import {mathsym, makeSpan, makeSymbol, makeVList, staticSvg} from "../buildCommon";
|
|
@@ -83,8 +82,8 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
|
|
|
83
82
|
}, options);
|
|
84
83
|
group.name = "\\" + stash;
|
|
85
84
|
base.classes.unshift("mop");
|
|
86
|
-
//
|
|
87
|
-
base.italic = italic;
|
|
85
|
+
// TODO(ts)
|
|
86
|
+
(base as any).italic = italic;
|
|
88
87
|
}
|
|
89
88
|
} else if (group.body) {
|
|
90
89
|
// If this is a list, compose that list.
|
|
@@ -99,8 +98,8 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
|
|
|
99
98
|
// Otherwise, this is a text operator. Build the text from the
|
|
100
99
|
// operator's name.
|
|
101
100
|
const output = [];
|
|
102
|
-
for (let i = 1; i < group.name
|
|
103
|
-
output.push(mathsym(group.name[i], group.mode, options));
|
|
101
|
+
for (let i = 1; i < group.name!.length; i++) {
|
|
102
|
+
output.push(mathsym(group.name![i], group.mode, options));
|
|
104
103
|
}
|
|
105
104
|
base = makeSpan(["mop"], output, options);
|
|
106
105
|
}
|
|
@@ -121,8 +120,8 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
|
|
|
121
120
|
options.fontMetrics().axisHeight;
|
|
122
121
|
|
|
123
122
|
// The slant of the symbol is just its italic correction.
|
|
124
|
-
//
|
|
125
|
-
slant = base.italic;
|
|
123
|
+
// TODO(ts)
|
|
124
|
+
slant = (base as SymbolNode & {italic?: number}).italic || 0;
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
if (hasLimits) {
|
|
@@ -157,7 +156,7 @@ const mathmlBuilder: MathMLBuilder<"op"> = (group, options) => {
|
|
|
157
156
|
// This is a text operator. Add all the characters from the
|
|
158
157
|
// operator's name.
|
|
159
158
|
node = new MathNode(
|
|
160
|
-
"mi", [new TextNode(group.name
|
|
159
|
+
"mi", [new TextNode(group.name!.slice(1))]);
|
|
161
160
|
// Append an <mo>⁡</mo>.
|
|
162
161
|
// ref: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.4
|
|
163
162
|
const operator = new MathNode("mo",
|
|
@@ -172,7 +171,7 @@ const mathmlBuilder: MathMLBuilder<"op"> = (group, options) => {
|
|
|
172
171
|
return node;
|
|
173
172
|
};
|
|
174
173
|
|
|
175
|
-
const singleCharBigOps:
|
|
174
|
+
const singleCharBigOps: Record<string, string> = {
|
|
176
175
|
"\u220F": "\\prod",
|
|
177
176
|
"\u2210": "\\coprod",
|
|
178
177
|
"\u2211": "\\sum",
|
|
@@ -244,8 +243,7 @@ defineFunction({
|
|
|
244
243
|
// There are 2 flags for operators; whether they produce limits in
|
|
245
244
|
// displaystyle, and whether they are symbols and should grow in
|
|
246
245
|
// displaystyle. These four groups cover the four possible choices.
|
|
247
|
-
|
|
248
|
-
const singleCharIntegrals: {[string]: string} = {
|
|
246
|
+
const singleCharIntegrals: Record<string, string> = {
|
|
249
247
|
"\u222b": "\\int",
|
|
250
248
|
"\u222c": "\\iint",
|
|
251
249
|
"\u222d": "\\iiint",
|