katex 0.16.47 → 0.18.0
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 +5 -10
- package/cli.js +6 -9
- package/contrib/auto-render/index.html +1 -1
- package/contrib/copy-tex/README.md +3 -3
- package/contrib/copy-tex/index.html +1 -1
- package/contrib/mathtex-script-type/README.md +5 -5
- package/contrib/mhchem/README.md +1 -1
- package/contrib/render-a11y-string/render-a11y-string.ts +1 -1
- package/dist/README.md +5 -10
- package/dist/contrib/render-a11y-string.js +15 -40
- package/dist/contrib/render-a11y-string.min.js +1 -1
- package/dist/contrib/render-a11y-string.mjs +13 -33
- package/dist/katex-swap.css +159 -164
- package/dist/katex-swap.min.css +1 -1
- package/dist/katex.css +159 -164
- package/dist/katex.js +509 -849
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +498 -831
- package/katex.ts +1 -1
- package/package.json +12 -16
- package/src/MacroExpander.ts +11 -8
- package/src/Namespace.ts +17 -21
- package/src/Options.ts +2 -2
- package/src/ParseError.ts +1 -1
- package/src/Parser.ts +44 -50
- package/src/Settings.ts +1 -1
- package/src/SourceLocation.ts +2 -2
- package/src/atoms.ts +22 -22
- package/src/buildCommon.ts +8 -8
- package/src/buildHTML.ts +12 -13
- package/src/buildMathML.ts +4 -4
- package/src/buildTree.ts +1 -1
- package/src/defineEnvironment.ts +1 -2
- package/src/defineFunction.ts +104 -112
- package/src/environments/array.ts +11 -15
- package/src/environments/cd.ts +8 -8
- package/src/fontMetrics.ts +2 -4
- package/src/functions/accent.ts +12 -15
- package/src/functions/accentunder.ts +4 -4
- package/src/functions/arrow.ts +5 -5
- package/src/functions/char.ts +3 -4
- package/src/functions/color.ts +10 -13
- package/src/functions/cr.ts +4 -6
- package/src/functions/def.ts +15 -19
- package/src/functions/delimsizing.ts +23 -23
- package/src/functions/enclose.ts +23 -34
- package/src/functions/environment.ts +5 -6
- package/src/functions/font.ts +15 -27
- package/src/functions/genfrac.ts +19 -23
- package/src/functions/hbox.ts +6 -6
- package/src/functions/horizBrace.ts +4 -4
- package/src/functions/href.ts +10 -11
- package/src/functions/html.ts +8 -8
- package/src/functions/htmlmathml.ts +5 -5
- package/src/functions/includegraphics.ts +7 -7
- package/src/functions/kern.ts +6 -6
- package/src/functions/lap.ts +11 -11
- package/src/functions/math.ts +8 -10
- package/src/functions/mathchoice.ts +5 -5
- package/src/functions/mclass.ts +16 -28
- package/src/functions/op.ts +16 -30
- package/src/functions/operatorname.ts +4 -4
- package/src/functions/overline.ts +4 -4
- package/src/functions/phantom.ts +10 -10
- package/src/functions/pmb.ts +5 -5
- package/src/functions/raisebox.ts +5 -5
- package/src/functions/relax.ts +4 -5
- package/src/functions/rule.ts +8 -8
- package/src/functions/sizing.ts +7 -7
- package/src/functions/smash.ts +6 -6
- package/src/functions/sqrt.ts +5 -5
- package/src/functions/styling.ts +5 -5
- package/src/functions/supsub.ts +1 -1
- package/src/functions/symbolsOrd.ts +3 -3
- package/src/functions/symbolsSpacing.ts +21 -22
- package/src/functions/text.ts +7 -7
- package/src/functions/underline.ts +5 -5
- package/src/functions/utils/assembleSupSub.ts +1 -1
- package/src/functions/vcenter.ts +5 -5
- package/src/functions/verb.ts +5 -5
- package/src/macros.ts +3 -3
- package/src/mathMLTree.ts +6 -10
- package/src/parseNode.ts +6 -480
- package/src/parseTree.ts +1 -6
- package/src/spacingData.ts +2 -1
- package/src/stretchy.ts +3 -3
- package/src/styles/katex.scss +31 -37
- package/src/types/index.ts +12 -0
- package/src/types/nodes.ts +456 -0
- package/src/units.ts +1 -2
- package/src/utils.ts +1 -1
- package/src/wide-character.ts +2 -2
|
@@ -7,7 +7,7 @@ import {stretchyMathML, stretchySvg} from "../stretchy";
|
|
|
7
7
|
import * as html from "../buildHTML";
|
|
8
8
|
import * as mml from "../buildMathML";
|
|
9
9
|
|
|
10
|
-
import type {ParseNode} from "../
|
|
10
|
+
import type {ParseNode} from "../types/nodes";
|
|
11
11
|
|
|
12
12
|
defineFunction({
|
|
13
13
|
type: "accentUnder",
|
|
@@ -15,9 +15,8 @@ defineFunction({
|
|
|
15
15
|
"\\underleftarrow", "\\underrightarrow", "\\underleftrightarrow",
|
|
16
16
|
"\\undergroup", "\\underlinesegment", "\\utilde",
|
|
17
17
|
],
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
18
|
+
numArgs: 1,
|
|
19
|
+
|
|
21
20
|
handler: ({parser, funcName}, args) => {
|
|
22
21
|
const base = args[0];
|
|
23
22
|
return {
|
|
@@ -27,6 +26,7 @@ defineFunction({
|
|
|
27
26
|
base: base,
|
|
28
27
|
};
|
|
29
28
|
},
|
|
29
|
+
|
|
30
30
|
htmlBuilder: (group: ParseNode<"accentUnder">, options) => {
|
|
31
31
|
// Treat under accents much like underlines.
|
|
32
32
|
const innerGroup = html.buildGroup(group.base, options);
|
package/src/functions/arrow.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {stretchyMathML, stretchySvg} from "../stretchy";
|
|
|
6
6
|
import * as html from "../buildHTML";
|
|
7
7
|
import * as mml from "../buildMathML";
|
|
8
8
|
|
|
9
|
-
import type {ParseNode} from "../
|
|
9
|
+
import type {ParseNode} from "../types/nodes";
|
|
10
10
|
import type {MathDomNode} from "../mathMLTree";
|
|
11
11
|
|
|
12
12
|
// Helper function
|
|
@@ -33,10 +33,9 @@ defineFunction({
|
|
|
33
33
|
// The next 3 functions are here only to support the {CD} environment.
|
|
34
34
|
"\\\\cdrightarrow", "\\\\cdleftarrow", "\\\\cdlongequal",
|
|
35
35
|
],
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
36
|
+
numArgs: 1,
|
|
37
|
+
numOptionalArgs: 1,
|
|
38
|
+
|
|
40
39
|
handler({parser, funcName}, args, optArgs) {
|
|
41
40
|
return {
|
|
42
41
|
type: "xArrow",
|
|
@@ -46,6 +45,7 @@ defineFunction({
|
|
|
46
45
|
below: optArgs[0],
|
|
47
46
|
};
|
|
48
47
|
},
|
|
48
|
+
|
|
49
49
|
htmlBuilder(group: ParseNode<"xArrow">, options) {
|
|
50
50
|
const style = options.style;
|
|
51
51
|
|
package/src/functions/char.ts
CHANGED
|
@@ -8,10 +8,9 @@ import {assertNodeType} from "../parseNode";
|
|
|
8
8
|
defineFunction({
|
|
9
9
|
type: "textord",
|
|
10
10
|
names: ["\\@char"],
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
11
|
+
numArgs: 1,
|
|
12
|
+
allowedInText: true,
|
|
13
|
+
|
|
15
14
|
handler({parser}, args) {
|
|
16
15
|
const arg = assertNodeType(args[0], "ordgroup");
|
|
17
16
|
const group = arg.body;
|
package/src/functions/color.ts
CHANGED
|
@@ -2,7 +2,7 @@ import defineFunction, {ordargument} from "../defineFunction";
|
|
|
2
2
|
import {makeFragment} from "../buildCommon";
|
|
3
3
|
import {MathNode} from "../mathMLTree";
|
|
4
4
|
import {assertNodeType} from "../parseNode";
|
|
5
|
-
import type {AnyParseNode} from "../
|
|
5
|
+
import type {AnyParseNode} from "../types/nodes";
|
|
6
6
|
import type {HtmlBuilder, MathMLBuilder} from "../defineFunction";
|
|
7
7
|
|
|
8
8
|
import * as html from "../buildHTML";
|
|
@@ -36,11 +36,10 @@ const mathmlBuilder: MathMLBuilder<"color"> = (group, options) => {
|
|
|
36
36
|
defineFunction({
|
|
37
37
|
type: "color",
|
|
38
38
|
names: ["\\textcolor"],
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
39
|
+
numArgs: 2,
|
|
40
|
+
allowedInText: true,
|
|
41
|
+
argTypes: ["color", "original"],
|
|
42
|
+
|
|
44
43
|
handler({parser}, args) {
|
|
45
44
|
const color = assertNodeType(args[0], "color-token").color;
|
|
46
45
|
const body = args[1];
|
|
@@ -51,6 +50,7 @@ defineFunction({
|
|
|
51
50
|
body: (ordargument(body) as AnyParseNode[]),
|
|
52
51
|
};
|
|
53
52
|
},
|
|
53
|
+
|
|
54
54
|
htmlBuilder,
|
|
55
55
|
mathmlBuilder,
|
|
56
56
|
});
|
|
@@ -58,11 +58,10 @@ defineFunction({
|
|
|
58
58
|
defineFunction({
|
|
59
59
|
type: "color",
|
|
60
60
|
names: ["\\color"],
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
61
|
+
numArgs: 1,
|
|
62
|
+
allowedInText: true,
|
|
63
|
+
argTypes: ["color"],
|
|
64
|
+
|
|
66
65
|
handler({parser, breakOnTokenText}, args) {
|
|
67
66
|
const color = assertNodeType(args[0], "color-token").color;
|
|
68
67
|
|
|
@@ -82,6 +81,4 @@ defineFunction({
|
|
|
82
81
|
body,
|
|
83
82
|
};
|
|
84
83
|
},
|
|
85
|
-
htmlBuilder,
|
|
86
|
-
mathmlBuilder,
|
|
87
84
|
});
|
package/src/functions/cr.ts
CHANGED
|
@@ -10,11 +10,9 @@ import {assertNodeType} from "../parseNode";
|
|
|
10
10
|
defineFunction({
|
|
11
11
|
type: "cr",
|
|
12
12
|
names: ["\\\\"],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
allowedInText: true,
|
|
17
|
-
},
|
|
13
|
+
numArgs: 0,
|
|
14
|
+
numOptionalArgs: 0,
|
|
15
|
+
allowedInText: true,
|
|
18
16
|
|
|
19
17
|
handler({parser}, args, optArgs) {
|
|
20
18
|
const size = parser.gullet.future().text === "[" ?
|
|
@@ -37,7 +35,7 @@ defineFunction({
|
|
|
37
35
|
htmlBuilder(group, options) {
|
|
38
36
|
const span = makeSpan(["mspace"], [], options);
|
|
39
37
|
if (group.newLine) {
|
|
40
|
-
span.classes.push("newline");
|
|
38
|
+
span.classes.push("katex-newline");
|
|
41
39
|
if (group.size) {
|
|
42
40
|
span.style.marginTop =
|
|
43
41
|
makeEm(calculateSize(group.size, options));
|
package/src/functions/def.ts
CHANGED
|
@@ -62,10 +62,9 @@ defineFunction({
|
|
|
62
62
|
"\\global", "\\long",
|
|
63
63
|
"\\\\globallong", // can’t be entered directly
|
|
64
64
|
],
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
65
|
+
numArgs: 0,
|
|
66
|
+
allowedInText: true,
|
|
67
|
+
|
|
69
68
|
handler({parser, funcName}) {
|
|
70
69
|
parser.consumeSpaces();
|
|
71
70
|
const token = parser.fetch();
|
|
@@ -87,11 +86,10 @@ defineFunction({
|
|
|
87
86
|
defineFunction({
|
|
88
87
|
type: "internal",
|
|
89
88
|
names: ["\\def", "\\gdef", "\\edef", "\\xdef"],
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
89
|
+
numArgs: 0,
|
|
90
|
+
allowedInText: true,
|
|
91
|
+
primitive: true,
|
|
92
|
+
|
|
95
93
|
handler({parser, funcName}) {
|
|
96
94
|
let tok = parser.gullet.popToken();
|
|
97
95
|
const name = tok.text;
|
|
@@ -168,11 +166,10 @@ defineFunction({
|
|
|
168
166
|
"\\let",
|
|
169
167
|
"\\\\globallet", // can’t be entered directly
|
|
170
168
|
],
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
},
|
|
169
|
+
numArgs: 0,
|
|
170
|
+
allowedInText: true,
|
|
171
|
+
primitive: true,
|
|
172
|
+
|
|
176
173
|
handler({parser, funcName}) {
|
|
177
174
|
const name = checkControlSequence(parser.gullet.popToken());
|
|
178
175
|
parser.gullet.consumeSpaces();
|
|
@@ -192,11 +189,10 @@ defineFunction({
|
|
|
192
189
|
"\\futurelet",
|
|
193
190
|
"\\\\globalfuture", // can’t be entered directly
|
|
194
191
|
],
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
},
|
|
192
|
+
numArgs: 0,
|
|
193
|
+
allowedInText: true,
|
|
194
|
+
primitive: true,
|
|
195
|
+
|
|
200
196
|
handler({parser, funcName}) {
|
|
201
197
|
const name = checkControlSequence(parser.gullet.popToken());
|
|
202
198
|
const middle = parser.gullet.popToken();
|
|
@@ -10,15 +10,13 @@ import * as html from "../buildHTML";
|
|
|
10
10
|
import * as mml from "../buildMathML";
|
|
11
11
|
|
|
12
12
|
import type Options from "../Options";
|
|
13
|
-
import type {AnyParseNode, ParseNode, SymbolParseNode} from "../parseNode";
|
|
14
13
|
import type {FunctionContext} from "../defineFunction";
|
|
15
14
|
import type {HtmlDomNode} from "../domTree";
|
|
15
|
+
import type {DelimiterSize, MathClass} from "../types";
|
|
16
|
+
import type {AnyParseNode, ParseNode, SymbolParseNode} from "../types/nodes";
|
|
16
17
|
|
|
17
18
|
// Extra data needed for the delimiter handler down below
|
|
18
|
-
const delimiterSizes
|
|
19
|
-
mclass: "mopen" | "mclose" | "mrel" | "mord";
|
|
20
|
-
size: 1 | 2 | 3 | 4;
|
|
21
|
-
}> = {
|
|
19
|
+
const delimiterSizes = {
|
|
22
20
|
"\\bigl" : {mclass: "mopen", size: 1},
|
|
23
21
|
"\\Bigl" : {mclass: "mopen", size: 2},
|
|
24
22
|
"\\biggl": {mclass: "mopen", size: 3},
|
|
@@ -35,7 +33,10 @@ const delimiterSizes: Record<string, {
|
|
|
35
33
|
"\\Big" : {mclass: "mord", size: 2},
|
|
36
34
|
"\\bigg" : {mclass: "mord", size: 3},
|
|
37
35
|
"\\Bigg" : {mclass: "mord", size: 4},
|
|
38
|
-
}
|
|
36
|
+
} as const satisfies Record<string, {
|
|
37
|
+
mclass: MathClass;
|
|
38
|
+
size: DelimiterSize;
|
|
39
|
+
}>;
|
|
39
40
|
|
|
40
41
|
const delimiters = new Set([
|
|
41
42
|
"(", "\\lparen", ")", "\\rparen",
|
|
@@ -92,10 +93,9 @@ defineFunction({
|
|
|
92
93
|
"\\bigm", "\\Bigm", "\\biggm", "\\Biggm",
|
|
93
94
|
"\\big", "\\Big", "\\bigg", "\\Bigg",
|
|
94
95
|
],
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
},
|
|
96
|
+
numArgs: 1,
|
|
97
|
+
argTypes: ["primitive"],
|
|
98
|
+
|
|
99
99
|
handler: (context, args) => {
|
|
100
100
|
const delim = checkDelimiter(args[0], context);
|
|
101
101
|
|
|
@@ -107,6 +107,7 @@ defineFunction({
|
|
|
107
107
|
delim: delim.text,
|
|
108
108
|
};
|
|
109
109
|
},
|
|
110
|
+
|
|
110
111
|
htmlBuilder: (group, options) => {
|
|
111
112
|
if (group.delim === ".") {
|
|
112
113
|
// Empty delimiters still count as elements, even though they don't
|
|
@@ -157,10 +158,9 @@ function assertParsed(group: ParseNode<"leftright">) {
|
|
|
157
158
|
defineFunction({
|
|
158
159
|
type: "leftright-right",
|
|
159
160
|
names: ["\\right"],
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
},
|
|
161
|
+
numArgs: 1,
|
|
162
|
+
primitive: true,
|
|
163
|
+
|
|
164
164
|
handler: (context, args) => {
|
|
165
165
|
// \left case below triggers parsing of \right in
|
|
166
166
|
// `const right = parser.parseFunction();`
|
|
@@ -174,7 +174,7 @@ defineFunction({
|
|
|
174
174
|
type: "leftright-right",
|
|
175
175
|
mode: context.parser.mode,
|
|
176
176
|
delim: checkDelimiter(args[0], context).text,
|
|
177
|
-
color
|
|
177
|
+
color, // undefined if not set via \color
|
|
178
178
|
};
|
|
179
179
|
},
|
|
180
180
|
});
|
|
@@ -183,10 +183,9 @@ defineFunction({
|
|
|
183
183
|
defineFunction({
|
|
184
184
|
type: "leftright",
|
|
185
185
|
names: ["\\left"],
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
},
|
|
186
|
+
numArgs: 1,
|
|
187
|
+
primitive: true,
|
|
188
|
+
|
|
190
189
|
handler: (context, args) => {
|
|
191
190
|
const delim = checkDelimiter(args[0], context);
|
|
192
191
|
|
|
@@ -208,6 +207,7 @@ defineFunction({
|
|
|
208
207
|
rightColor: right.color,
|
|
209
208
|
};
|
|
210
209
|
},
|
|
210
|
+
|
|
211
211
|
htmlBuilder: (group, options) => {
|
|
212
212
|
assertParsed(group);
|
|
213
213
|
// Build the inner expression
|
|
@@ -312,10 +312,9 @@ defineFunction({
|
|
|
312
312
|
defineFunction({
|
|
313
313
|
type: "middle",
|
|
314
314
|
names: ["\\middle"],
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
},
|
|
315
|
+
numArgs: 1,
|
|
316
|
+
primitive: true,
|
|
317
|
+
|
|
319
318
|
handler: (context, args) => {
|
|
320
319
|
const delim = checkDelimiter(args[0], context);
|
|
321
320
|
if (!context.parser.leftrightDepth) {
|
|
@@ -328,6 +327,7 @@ defineFunction({
|
|
|
328
327
|
delim: delim.text,
|
|
329
328
|
};
|
|
330
329
|
},
|
|
330
|
+
|
|
331
331
|
htmlBuilder: (group, options) => {
|
|
332
332
|
let middleDelim;
|
|
333
333
|
if (group.delim === ".") {
|
package/src/functions/enclose.ts
CHANGED
|
@@ -32,7 +32,7 @@ const htmlBuilder: HtmlBuilder<"enclose"> = (group, options) => {
|
|
|
32
32
|
const isSingleChar = isCharacterBox(group.body);
|
|
33
33
|
|
|
34
34
|
if (label === "sout") {
|
|
35
|
-
img = makeSpan(["stretchy", "sout"]);
|
|
35
|
+
img = makeSpan(["katex-stretchy", "katex-sout"]);
|
|
36
36
|
img.height = options.fontMetrics().defaultRuleThickness / scale;
|
|
37
37
|
imgShift = -0.5 * options.fontMetrics().xHeight;
|
|
38
38
|
|
|
@@ -220,11 +220,10 @@ const mathmlBuilder: MathMLBuilder<"enclose"> = (group, options) => {
|
|
|
220
220
|
defineFunction({
|
|
221
221
|
type: "enclose",
|
|
222
222
|
names: ["\\colorbox"],
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
},
|
|
223
|
+
numArgs: 2,
|
|
224
|
+
allowedInText: true,
|
|
225
|
+
argTypes: ["color", "hbox"],
|
|
226
|
+
|
|
228
227
|
handler({parser, funcName}, args, optArgs) {
|
|
229
228
|
const color = assertNodeType(args[0], "color-token").color;
|
|
230
229
|
const body = args[1];
|
|
@@ -236,6 +235,7 @@ defineFunction({
|
|
|
236
235
|
body,
|
|
237
236
|
};
|
|
238
237
|
},
|
|
238
|
+
|
|
239
239
|
htmlBuilder,
|
|
240
240
|
mathmlBuilder,
|
|
241
241
|
});
|
|
@@ -243,11 +243,10 @@ defineFunction({
|
|
|
243
243
|
defineFunction({
|
|
244
244
|
type: "enclose",
|
|
245
245
|
names: ["\\fcolorbox"],
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
},
|
|
246
|
+
numArgs: 3,
|
|
247
|
+
allowedInText: true,
|
|
248
|
+
argTypes: ["color", "color", "hbox"],
|
|
249
|
+
|
|
251
250
|
handler({parser, funcName}, args, optArgs) {
|
|
252
251
|
const borderColor = assertNodeType(args[0], "color-token").color;
|
|
253
252
|
const backgroundColor = assertNodeType(args[1], "color-token").color;
|
|
@@ -261,18 +260,15 @@ defineFunction({
|
|
|
261
260
|
body,
|
|
262
261
|
};
|
|
263
262
|
},
|
|
264
|
-
htmlBuilder,
|
|
265
|
-
mathmlBuilder,
|
|
266
263
|
});
|
|
267
264
|
|
|
268
265
|
defineFunction({
|
|
269
266
|
type: "enclose",
|
|
270
267
|
names: ["\\fbox"],
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
},
|
|
268
|
+
numArgs: 1,
|
|
269
|
+
argTypes: ["hbox"],
|
|
270
|
+
allowedInText: true,
|
|
271
|
+
|
|
276
272
|
handler({parser}, args) {
|
|
277
273
|
return {
|
|
278
274
|
type: "enclose",
|
|
@@ -286,9 +282,8 @@ defineFunction({
|
|
|
286
282
|
defineFunction({
|
|
287
283
|
type: "enclose",
|
|
288
284
|
names: ["\\cancel", "\\bcancel", "\\xcancel", "\\phase"],
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
},
|
|
285
|
+
numArgs: 1,
|
|
286
|
+
|
|
292
287
|
handler({parser, funcName}, args) {
|
|
293
288
|
const body = args[0];
|
|
294
289
|
return {
|
|
@@ -298,17 +293,14 @@ defineFunction({
|
|
|
298
293
|
body,
|
|
299
294
|
};
|
|
300
295
|
},
|
|
301
|
-
htmlBuilder,
|
|
302
|
-
mathmlBuilder,
|
|
303
296
|
});
|
|
304
297
|
|
|
305
298
|
defineFunction({
|
|
306
299
|
type: "enclose",
|
|
307
300
|
names: ["\\sout"],
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
},
|
|
301
|
+
numArgs: 1,
|
|
302
|
+
allowedInText: true,
|
|
303
|
+
|
|
312
304
|
handler({parser, funcName}, args) {
|
|
313
305
|
if (parser.mode === "math") {
|
|
314
306
|
parser.settings.reportNonstrict("mathVsSout",
|
|
@@ -322,18 +314,15 @@ defineFunction({
|
|
|
322
314
|
body,
|
|
323
315
|
};
|
|
324
316
|
},
|
|
325
|
-
htmlBuilder,
|
|
326
|
-
mathmlBuilder,
|
|
327
317
|
});
|
|
328
318
|
|
|
329
319
|
defineFunction({
|
|
330
320
|
type: "enclose",
|
|
331
321
|
names: ["\\angl"],
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
},
|
|
322
|
+
numArgs: 1,
|
|
323
|
+
argTypes: ["hbox"],
|
|
324
|
+
allowedInText: false,
|
|
325
|
+
|
|
337
326
|
handler({parser}, args) {
|
|
338
327
|
return {
|
|
339
328
|
type: "enclose",
|
|
@@ -3,17 +3,16 @@ import ParseError from "../ParseError";
|
|
|
3
3
|
import {assertNodeType} from "../parseNode";
|
|
4
4
|
import environments from "../environments";
|
|
5
5
|
|
|
6
|
-
import type {ParseNode} from "../
|
|
6
|
+
import type {ParseNode} from "../types/nodes";
|
|
7
7
|
|
|
8
8
|
// Environment delimiters. HTML/MathML rendering is defined in the corresponding
|
|
9
9
|
// defineEnvironment definitions.
|
|
10
10
|
defineFunction({
|
|
11
11
|
type: "environment",
|
|
12
12
|
names: ["\\begin", "\\end"],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
13
|
+
numArgs: 1,
|
|
14
|
+
argTypes: ["text"],
|
|
15
|
+
|
|
17
16
|
handler({parser, funcName}, args) {
|
|
18
17
|
const nameGroup = args[0];
|
|
19
18
|
if (nameGroup.type !== "ordgroup") {
|
|
@@ -26,7 +25,7 @@ defineFunction({
|
|
|
26
25
|
|
|
27
26
|
if (funcName === "\\begin") {
|
|
28
27
|
// begin...end is similar to left...right
|
|
29
|
-
if (!
|
|
28
|
+
if (!Object.prototype.hasOwnProperty.call(environments, envName)) {
|
|
30
29
|
throw new ParseError(
|
|
31
30
|
"No such environment: " + envName, nameGroup);
|
|
32
31
|
}
|
package/src/functions/font.ts
CHANGED
|
@@ -8,7 +8,7 @@ import * as html from "../buildHTML";
|
|
|
8
8
|
import * as mml from "../buildMathML";
|
|
9
9
|
|
|
10
10
|
import type Options from "../Options";
|
|
11
|
-
import type {ParseNode} from "../
|
|
11
|
+
import type {ParseNode} from "../types/nodes";
|
|
12
12
|
import type {Slice1} from "../types";
|
|
13
13
|
|
|
14
14
|
const htmlBuilder = (group: ParseNode<"font">, options: Options) => {
|
|
@@ -29,12 +29,6 @@ const fontAliases = {
|
|
|
29
29
|
"\\frak": "\\mathfrak",
|
|
30
30
|
} as const;
|
|
31
31
|
|
|
32
|
-
type OldFontCommands = "\\rm" | "\\sf" | "\\tt" | "\\bf" | "\\it" | "\\cal";
|
|
33
|
-
type FontCommands =
|
|
34
|
-
"\\mathrm" | "\\mathit" | "\\mathbf" | "\\mathnormal" | "\\mathsfit" |
|
|
35
|
-
"\\mathbb" | "\\mathcal" | "\\mathfrak" | "\\mathscr" | "\\mathsf" |
|
|
36
|
-
"\\mathtt";
|
|
37
|
-
|
|
38
32
|
defineFunction({
|
|
39
33
|
type: "font",
|
|
40
34
|
names: [
|
|
@@ -47,24 +41,23 @@ defineFunction({
|
|
|
47
41
|
|
|
48
42
|
// aliases, except \bm defined below
|
|
49
43
|
"\\Bbb", "\\bold", "\\frak",
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
44
|
+
],
|
|
45
|
+
numArgs: 1,
|
|
46
|
+
allowedInArgument: true,
|
|
47
|
+
|
|
55
48
|
handler: ({parser, funcName}, args) => {
|
|
56
49
|
const body = normalizeArgument(args[0]);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
50
|
+
const func = funcName in fontAliases
|
|
51
|
+
? fontAliases[funcName as keyof typeof fontAliases]
|
|
52
|
+
: funcName as Exclude<typeof funcName, keyof typeof fontAliases>;
|
|
61
53
|
return {
|
|
62
54
|
type: "font",
|
|
63
55
|
mode: parser.mode,
|
|
64
|
-
font: func.slice(1) as Slice1<
|
|
56
|
+
font: func.slice(1) as Slice1<typeof func>,
|
|
65
57
|
body,
|
|
66
58
|
};
|
|
67
59
|
},
|
|
60
|
+
|
|
68
61
|
htmlBuilder,
|
|
69
62
|
mathmlBuilder,
|
|
70
63
|
});
|
|
@@ -72,9 +65,8 @@ defineFunction({
|
|
|
72
65
|
defineFunction({
|
|
73
66
|
type: "mclass",
|
|
74
67
|
names: ["\\boldsymbol", "\\bm"],
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
68
|
+
numArgs: 1,
|
|
69
|
+
|
|
78
70
|
handler: ({parser}, args) => {
|
|
79
71
|
const body = args[0];
|
|
80
72
|
// amsbsy.sty's \boldsymbol uses \binrel spacing to inherit the
|
|
@@ -100,10 +92,8 @@ defineFunction({
|
|
|
100
92
|
defineFunction({
|
|
101
93
|
type: "font",
|
|
102
94
|
names: ["\\rm", "\\sf", "\\tt", "\\bf", "\\it", "\\cal"],
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
allowedInText: true,
|
|
106
|
-
},
|
|
95
|
+
numArgs: 0,
|
|
96
|
+
allowedInText: true,
|
|
107
97
|
handler: ({parser, funcName, breakOnTokenText}, args) => {
|
|
108
98
|
const {mode} = parser;
|
|
109
99
|
const body = parser.parseExpression(true, breakOnTokenText);
|
|
@@ -111,7 +101,7 @@ defineFunction({
|
|
|
111
101
|
return {
|
|
112
102
|
type: "font",
|
|
113
103
|
mode: mode,
|
|
114
|
-
font: `math${funcName.slice(1) as Slice1<
|
|
104
|
+
font: `math${funcName.slice(1) as Slice1<typeof funcName>}` as const,
|
|
115
105
|
body: {
|
|
116
106
|
type: "ordgroup",
|
|
117
107
|
mode: parser.mode,
|
|
@@ -119,6 +109,4 @@ defineFunction({
|
|
|
119
109
|
},
|
|
120
110
|
};
|
|
121
111
|
},
|
|
122
|
-
htmlBuilder,
|
|
123
|
-
mathmlBuilder,
|
|
124
112
|
});
|
package/src/functions/genfrac.ts
CHANGED
|
@@ -2,7 +2,7 @@ import defineFunction, {normalizeArgument} from "../defineFunction";
|
|
|
2
2
|
import {makeLineSpan, makeSpan, makeVList} from "../buildCommon";
|
|
3
3
|
import {makeCustomSizedDelim} from "../delimiter";
|
|
4
4
|
import {MathNode, TextNode} from "../mathMLTree";
|
|
5
|
-
import type {ParseNode} from "../
|
|
5
|
+
import type {ParseNode} from "../types/nodes";
|
|
6
6
|
import Style from "../Style";
|
|
7
7
|
import {assertNodeType} from "../parseNode";
|
|
8
8
|
import * as html from "../buildHTML";
|
|
@@ -239,10 +239,9 @@ defineFunction({
|
|
|
239
239
|
"\\\\atopfrac", // can’t be entered directly
|
|
240
240
|
"\\\\bracefrac", "\\\\brackfrac", // ditto
|
|
241
241
|
],
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
},
|
|
242
|
+
numArgs: 2,
|
|
243
|
+
allowedInArgument: true,
|
|
244
|
+
|
|
246
245
|
handler: ({parser, funcName}, args) => {
|
|
247
246
|
const numer = args[0];
|
|
248
247
|
const denom = args[1];
|
|
@@ -302,6 +301,7 @@ defineFunction({
|
|
|
302
301
|
}, style);
|
|
303
302
|
},
|
|
304
303
|
|
|
304
|
+
|
|
305
305
|
htmlBuilder,
|
|
306
306
|
mathmlBuilder,
|
|
307
307
|
});
|
|
@@ -311,10 +311,9 @@ defineFunction({
|
|
|
311
311
|
defineFunction({
|
|
312
312
|
type: "infix",
|
|
313
313
|
names: ["\\over", "\\choose", "\\atop", "\\brace", "\\brack"],
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
},
|
|
314
|
+
numArgs: 0,
|
|
315
|
+
infix: true,
|
|
316
|
+
|
|
318
317
|
handler({parser, funcName, token}) {
|
|
319
318
|
let replaceWith;
|
|
320
319
|
switch (funcName) {
|
|
@@ -359,11 +358,10 @@ const delimFromValue = function(delimString: string): string | null {
|
|
|
359
358
|
defineFunction({
|
|
360
359
|
type: "genfrac",
|
|
361
360
|
names: ["\\genfrac"],
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
},
|
|
361
|
+
numArgs: 6,
|
|
362
|
+
allowedInArgument: true,
|
|
363
|
+
argTypes: ["math", "math", "size", "text", "math", "math"],
|
|
364
|
+
|
|
367
365
|
handler({parser}, args) {
|
|
368
366
|
const numer = args[4];
|
|
369
367
|
const denom = args[5];
|
|
@@ -420,11 +418,10 @@ defineFunction({
|
|
|
420
418
|
defineFunction({
|
|
421
419
|
type: "infix",
|
|
422
420
|
names: ["\\above"],
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
},
|
|
421
|
+
numArgs: 1,
|
|
422
|
+
argTypes: ["size"],
|
|
423
|
+
infix: true,
|
|
424
|
+
|
|
428
425
|
handler({parser, funcName, token}, args) {
|
|
429
426
|
return {
|
|
430
427
|
type: "infix",
|
|
@@ -439,10 +436,9 @@ defineFunction({
|
|
|
439
436
|
defineFunction({
|
|
440
437
|
type: "genfrac",
|
|
441
438
|
names: ["\\\\abovefrac"],
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
},
|
|
439
|
+
numArgs: 3,
|
|
440
|
+
argTypes: ["math", "size", "math"],
|
|
441
|
+
|
|
446
442
|
handler: ({parser, funcName}, args) => {
|
|
447
443
|
const numer = args[0];
|
|
448
444
|
const barSize = assertNodeType(args[1], "infix").size;
|