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
package/src/parseNode.ts
CHANGED
|
@@ -1,479 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import type SourceLocation from "./SourceLocation";
|
|
4
|
-
import type {AlignSpec, ColSeparationType} from "./environments/array";
|
|
5
|
-
import type {DelimiterSize, Mode, StyleStr} from "./types";
|
|
6
|
-
import type {MathFont} from "./types/fonts";
|
|
7
|
-
import type {Token} from "./Token";
|
|
8
|
-
import type {Measurement} from "./units";
|
|
9
|
-
export type NodeType = keyof ParseNodeTypes;
|
|
10
|
-
export type ParseNode<TYPE extends NodeType> = ParseNodeTypes[TYPE];
|
|
11
|
-
|
|
12
|
-
// ParseNode's corresponding to Symbol `Group`s in symbols.js.
|
|
13
|
-
export type SymbolParseNode =
|
|
14
|
-
ParseNode<"atom"> |
|
|
15
|
-
ParseNode<"accent-token"> |
|
|
16
|
-
ParseNode<"mathord"> |
|
|
17
|
-
ParseNode<"op-token"> |
|
|
18
|
-
ParseNode<"spacing"> |
|
|
19
|
-
ParseNode<"textord">;
|
|
20
|
-
|
|
21
|
-
// ParseNode from `Parser.formatUnsupportedCmd`
|
|
22
|
-
export type UnsupportedCmdParseNode = ParseNode<"color">;
|
|
23
|
-
|
|
24
|
-
// Union of all possible `ParseNode<>` types.
|
|
25
|
-
export type AnyParseNode = ParseNodeTypes[keyof ParseNodeTypes];
|
|
26
|
-
|
|
27
|
-
// Map from `NodeType` to the corresponding `ParseNode`.
|
|
28
|
-
type ParseNodeTypes = {
|
|
29
|
-
"array": {
|
|
30
|
-
type: "array";
|
|
31
|
-
mode: Mode;
|
|
32
|
-
loc?: SourceLocation | null | undefined;
|
|
33
|
-
colSeparationType?: ColSeparationType;
|
|
34
|
-
hskipBeforeAndAfter?: boolean;
|
|
35
|
-
addJot?: boolean;
|
|
36
|
-
cols?: AlignSpec[];
|
|
37
|
-
arraystretch: number;
|
|
38
|
-
body: AnyParseNode[][];
|
|
39
|
-
// List of rows in the (2D) array.
|
|
40
|
-
rowGaps: (Measurement | null | undefined)[];
|
|
41
|
-
hLinesBeforeRow: Array<boolean[]>;
|
|
42
|
-
// Whether each row should be automatically numbered, or an explicit tag
|
|
43
|
-
tags?: (boolean | AnyParseNode[])[];
|
|
44
|
-
leqno?: boolean;
|
|
45
|
-
isCD?: boolean;
|
|
46
|
-
};
|
|
47
|
-
"cdlabel": {
|
|
48
|
-
type: "cdlabel";
|
|
49
|
-
mode: Mode;
|
|
50
|
-
loc?: SourceLocation | null | undefined;
|
|
51
|
-
side: string;
|
|
52
|
-
label: AnyParseNode;
|
|
53
|
-
};
|
|
54
|
-
"cdlabelparent": {
|
|
55
|
-
type: "cdlabelparent";
|
|
56
|
-
mode: Mode;
|
|
57
|
-
loc?: SourceLocation | null | undefined;
|
|
58
|
-
fragment: AnyParseNode;
|
|
59
|
-
};
|
|
60
|
-
"color": {
|
|
61
|
-
type: "color";
|
|
62
|
-
mode: Mode;
|
|
63
|
-
loc?: SourceLocation | null | undefined;
|
|
64
|
-
color: string;
|
|
65
|
-
body: AnyParseNode[];
|
|
66
|
-
};
|
|
67
|
-
"color-token": {
|
|
68
|
-
type: "color-token";
|
|
69
|
-
mode: Mode;
|
|
70
|
-
loc?: SourceLocation | null | undefined;
|
|
71
|
-
color: string;
|
|
72
|
-
};
|
|
73
|
-
// To avoid requiring run-time type assertions, this more carefully captures
|
|
74
|
-
// the requirements on the fields per the op.js htmlBuilder logic:
|
|
75
|
-
// - `body` and `value` are NEVER set simultaneously.
|
|
76
|
-
// - When `symbol` is true, `body` is set.
|
|
77
|
-
"op": {
|
|
78
|
-
type: "op";
|
|
79
|
-
mode: Mode;
|
|
80
|
-
loc?: SourceLocation | null | undefined;
|
|
81
|
-
limits: boolean;
|
|
82
|
-
alwaysHandleSupSub?: boolean;
|
|
83
|
-
suppressBaseShift?: boolean;
|
|
84
|
-
parentIsSupSub: boolean;
|
|
85
|
-
symbol: boolean;
|
|
86
|
-
name: string;
|
|
87
|
-
body?: void;
|
|
88
|
-
} | {
|
|
89
|
-
type: "op";
|
|
90
|
-
mode: Mode;
|
|
91
|
-
loc?: SourceLocation | null | undefined;
|
|
92
|
-
limits: boolean;
|
|
93
|
-
alwaysHandleSupSub?: boolean;
|
|
94
|
-
suppressBaseShift?: boolean;
|
|
95
|
-
parentIsSupSub: boolean;
|
|
96
|
-
symbol: false;
|
|
97
|
-
// If 'symbol' is true, `body` *must* be set.
|
|
98
|
-
name?: void;
|
|
99
|
-
body: AnyParseNode[];
|
|
100
|
-
};
|
|
101
|
-
"ordgroup": {
|
|
102
|
-
type: "ordgroup";
|
|
103
|
-
mode: Mode;
|
|
104
|
-
loc?: SourceLocation | null | undefined;
|
|
105
|
-
body: AnyParseNode[];
|
|
106
|
-
semisimple?: boolean;
|
|
107
|
-
};
|
|
108
|
-
"raw": {
|
|
109
|
-
type: "raw";
|
|
110
|
-
mode: Mode;
|
|
111
|
-
loc?: SourceLocation | null | undefined;
|
|
112
|
-
string: string;
|
|
113
|
-
};
|
|
114
|
-
"size": {
|
|
115
|
-
type: "size";
|
|
116
|
-
mode: Mode;
|
|
117
|
-
loc?: SourceLocation | null | undefined;
|
|
118
|
-
value: Measurement;
|
|
119
|
-
isBlank: boolean;
|
|
120
|
-
};
|
|
121
|
-
"styling": {
|
|
122
|
-
type: "styling";
|
|
123
|
-
mode: Mode;
|
|
124
|
-
loc?: SourceLocation | null | undefined;
|
|
125
|
-
style: StyleStr;
|
|
126
|
-
resetFont?: boolean;
|
|
127
|
-
body: AnyParseNode[];
|
|
128
|
-
};
|
|
129
|
-
"supsub": {
|
|
130
|
-
type: "supsub";
|
|
131
|
-
mode: Mode;
|
|
132
|
-
loc?: SourceLocation | null | undefined;
|
|
133
|
-
base: AnyParseNode | null | undefined;
|
|
134
|
-
sup?: AnyParseNode | null | undefined;
|
|
135
|
-
sub?: AnyParseNode | null | undefined;
|
|
136
|
-
};
|
|
137
|
-
"tag": {
|
|
138
|
-
type: "tag";
|
|
139
|
-
mode: Mode;
|
|
140
|
-
loc?: SourceLocation | null | undefined;
|
|
141
|
-
body: AnyParseNode[];
|
|
142
|
-
tag: AnyParseNode[];
|
|
143
|
-
};
|
|
144
|
-
"text": {
|
|
145
|
-
type: "text";
|
|
146
|
-
mode: Mode;
|
|
147
|
-
loc?: SourceLocation | null | undefined;
|
|
148
|
-
body: AnyParseNode[];
|
|
149
|
-
font?: string;
|
|
150
|
-
};
|
|
151
|
-
"url": {
|
|
152
|
-
type: "url";
|
|
153
|
-
mode: Mode;
|
|
154
|
-
loc?: SourceLocation | null | undefined;
|
|
155
|
-
url: string;
|
|
156
|
-
};
|
|
157
|
-
"verb": {
|
|
158
|
-
type: "verb";
|
|
159
|
-
mode: Mode;
|
|
160
|
-
loc?: SourceLocation | null | undefined;
|
|
161
|
-
body: string;
|
|
162
|
-
star: boolean;
|
|
163
|
-
};
|
|
164
|
-
// From symbol groups, constructed in Parser.js via `symbols` lookup.
|
|
165
|
-
// (Some of these have "-token" suffix to distinguish them from existing
|
|
166
|
-
// `ParseNode` types.)
|
|
167
|
-
"atom": {
|
|
168
|
-
type: "atom";
|
|
169
|
-
family: Atom;
|
|
170
|
-
mode: Mode;
|
|
171
|
-
loc?: SourceLocation | null | undefined;
|
|
172
|
-
text: string;
|
|
173
|
-
};
|
|
174
|
-
"mathord": {
|
|
175
|
-
type: "mathord";
|
|
176
|
-
mode: Mode;
|
|
177
|
-
loc?: SourceLocation | null | undefined;
|
|
178
|
-
text: string;
|
|
179
|
-
};
|
|
180
|
-
"spacing": {
|
|
181
|
-
type: "spacing";
|
|
182
|
-
mode: Mode;
|
|
183
|
-
loc?: SourceLocation | null | undefined;
|
|
184
|
-
text: string;
|
|
185
|
-
};
|
|
186
|
-
"textord": {
|
|
187
|
-
type: "textord";
|
|
188
|
-
mode: Mode;
|
|
189
|
-
loc?: SourceLocation | null | undefined;
|
|
190
|
-
text: string;
|
|
191
|
-
};
|
|
192
|
-
// These "-token" types don't have corresponding HTML/MathML builders.
|
|
193
|
-
"accent-token": {
|
|
194
|
-
type: "accent-token";
|
|
195
|
-
mode: Mode;
|
|
196
|
-
loc?: SourceLocation | null | undefined;
|
|
197
|
-
text: string;
|
|
198
|
-
};
|
|
199
|
-
"op-token": {
|
|
200
|
-
type: "op-token";
|
|
201
|
-
mode: Mode;
|
|
202
|
-
loc?: SourceLocation | null | undefined;
|
|
203
|
-
text: string;
|
|
204
|
-
};
|
|
205
|
-
// From functions.js and functions/*.js. See also "color", "op", "styling",
|
|
206
|
-
// and "text" above.
|
|
207
|
-
"accent": {
|
|
208
|
-
type: "accent";
|
|
209
|
-
mode: Mode;
|
|
210
|
-
loc?: SourceLocation | null | undefined;
|
|
211
|
-
label: string;
|
|
212
|
-
isStretchy?: boolean;
|
|
213
|
-
isShifty?: boolean;
|
|
214
|
-
base: AnyParseNode;
|
|
215
|
-
};
|
|
216
|
-
"accentUnder": {
|
|
217
|
-
type: "accentUnder";
|
|
218
|
-
mode: Mode;
|
|
219
|
-
loc?: SourceLocation | null | undefined;
|
|
220
|
-
label: string;
|
|
221
|
-
isStretchy?: boolean;
|
|
222
|
-
isShifty?: boolean;
|
|
223
|
-
base: AnyParseNode;
|
|
224
|
-
};
|
|
225
|
-
"cr": {
|
|
226
|
-
type: "cr";
|
|
227
|
-
mode: Mode;
|
|
228
|
-
loc?: SourceLocation | null | undefined;
|
|
229
|
-
newLine: boolean;
|
|
230
|
-
size: Measurement | null | undefined;
|
|
231
|
-
};
|
|
232
|
-
"delimsizing": {
|
|
233
|
-
type: "delimsizing";
|
|
234
|
-
mode: Mode;
|
|
235
|
-
loc?: SourceLocation | null | undefined;
|
|
236
|
-
size: DelimiterSize;
|
|
237
|
-
mclass: "mopen" | "mclose" | "mrel" | "mord";
|
|
238
|
-
delim: string;
|
|
239
|
-
};
|
|
240
|
-
"enclose": {
|
|
241
|
-
type: "enclose";
|
|
242
|
-
mode: Mode;
|
|
243
|
-
loc?: SourceLocation | null | undefined;
|
|
244
|
-
label: string;
|
|
245
|
-
backgroundColor?: string;
|
|
246
|
-
borderColor?: string;
|
|
247
|
-
body: AnyParseNode;
|
|
248
|
-
};
|
|
249
|
-
"environment": {
|
|
250
|
-
type: "environment";
|
|
251
|
-
mode: Mode;
|
|
252
|
-
loc?: SourceLocation | null | undefined;
|
|
253
|
-
name: string;
|
|
254
|
-
nameGroup: AnyParseNode;
|
|
255
|
-
};
|
|
256
|
-
"font": {
|
|
257
|
-
type: "font";
|
|
258
|
-
mode: Mode;
|
|
259
|
-
loc?: SourceLocation | null | undefined;
|
|
260
|
-
font: Exclude<MathFont, "">;
|
|
261
|
-
body: AnyParseNode;
|
|
262
|
-
};
|
|
263
|
-
"genfrac": {
|
|
264
|
-
type: "genfrac";
|
|
265
|
-
mode: Mode;
|
|
266
|
-
loc?: SourceLocation | null | undefined;
|
|
267
|
-
continued: boolean;
|
|
268
|
-
numer: AnyParseNode;
|
|
269
|
-
denom: AnyParseNode;
|
|
270
|
-
hasBarLine: boolean;
|
|
271
|
-
leftDelim: string | null | undefined;
|
|
272
|
-
rightDelim: string | null | undefined;
|
|
273
|
-
barSize: Measurement | null;
|
|
274
|
-
};
|
|
275
|
-
"hbox": {
|
|
276
|
-
type: "hbox";
|
|
277
|
-
mode: Mode;
|
|
278
|
-
loc?: SourceLocation | null | undefined;
|
|
279
|
-
body: AnyParseNode[];
|
|
280
|
-
};
|
|
281
|
-
"horizBrace": {
|
|
282
|
-
type: "horizBrace";
|
|
283
|
-
mode: Mode;
|
|
284
|
-
loc?: SourceLocation | null | undefined;
|
|
285
|
-
label: string;
|
|
286
|
-
isOver: boolean;
|
|
287
|
-
base: AnyParseNode;
|
|
288
|
-
};
|
|
289
|
-
"href": {
|
|
290
|
-
type: "href";
|
|
291
|
-
mode: Mode;
|
|
292
|
-
loc?: SourceLocation | null | undefined;
|
|
293
|
-
href: string;
|
|
294
|
-
body: AnyParseNode[];
|
|
295
|
-
};
|
|
296
|
-
"html": {
|
|
297
|
-
type: "html";
|
|
298
|
-
mode: Mode;
|
|
299
|
-
loc?: SourceLocation | null | undefined;
|
|
300
|
-
attributes: Record<string, string>;
|
|
301
|
-
body: AnyParseNode[];
|
|
302
|
-
};
|
|
303
|
-
"htmlmathml": {
|
|
304
|
-
type: "htmlmathml";
|
|
305
|
-
mode: Mode;
|
|
306
|
-
loc?: SourceLocation | null | undefined;
|
|
307
|
-
html: AnyParseNode[];
|
|
308
|
-
mathml: AnyParseNode[];
|
|
309
|
-
};
|
|
310
|
-
"includegraphics": {
|
|
311
|
-
type: "includegraphics";
|
|
312
|
-
mode: Mode;
|
|
313
|
-
loc?: SourceLocation | null | undefined;
|
|
314
|
-
alt: string;
|
|
315
|
-
width: Measurement;
|
|
316
|
-
height: Measurement;
|
|
317
|
-
totalheight: Measurement;
|
|
318
|
-
src: string;
|
|
319
|
-
};
|
|
320
|
-
"infix": {
|
|
321
|
-
type: "infix";
|
|
322
|
-
mode: Mode;
|
|
323
|
-
loc?: SourceLocation | null | undefined;
|
|
324
|
-
replaceWith: string;
|
|
325
|
-
size?: Measurement;
|
|
326
|
-
token: Token | null | undefined;
|
|
327
|
-
};
|
|
328
|
-
"internal": {
|
|
329
|
-
type: "internal";
|
|
330
|
-
mode: Mode;
|
|
331
|
-
loc?: SourceLocation | null | undefined;
|
|
332
|
-
};
|
|
333
|
-
"kern": {
|
|
334
|
-
type: "kern";
|
|
335
|
-
mode: Mode;
|
|
336
|
-
loc?: SourceLocation | null | undefined;
|
|
337
|
-
dimension: Measurement;
|
|
338
|
-
};
|
|
339
|
-
"lap": {
|
|
340
|
-
type: "lap";
|
|
341
|
-
mode: Mode;
|
|
342
|
-
loc?: SourceLocation | null | undefined;
|
|
343
|
-
alignment: string;
|
|
344
|
-
body: AnyParseNode;
|
|
345
|
-
};
|
|
346
|
-
"leftright": {
|
|
347
|
-
type: "leftright";
|
|
348
|
-
mode: Mode;
|
|
349
|
-
loc?: SourceLocation | null | undefined;
|
|
350
|
-
body: AnyParseNode[];
|
|
351
|
-
left: string;
|
|
352
|
-
right: string;
|
|
353
|
-
rightColor: string | null | undefined; // undefined means "inherit"
|
|
354
|
-
};
|
|
355
|
-
"leftright-right": {
|
|
356
|
-
type: "leftright-right";
|
|
357
|
-
mode: Mode;
|
|
358
|
-
loc?: SourceLocation | null | undefined;
|
|
359
|
-
delim: string;
|
|
360
|
-
color: string | null | undefined; // undefined means "inherit"
|
|
361
|
-
};
|
|
362
|
-
"mathchoice": {
|
|
363
|
-
type: "mathchoice";
|
|
364
|
-
mode: Mode;
|
|
365
|
-
loc?: SourceLocation | null | undefined;
|
|
366
|
-
display: AnyParseNode[];
|
|
367
|
-
text: AnyParseNode[];
|
|
368
|
-
script: AnyParseNode[];
|
|
369
|
-
scriptscript: AnyParseNode[];
|
|
370
|
-
};
|
|
371
|
-
"middle": {
|
|
372
|
-
type: "middle";
|
|
373
|
-
mode: Mode;
|
|
374
|
-
loc?: SourceLocation | null | undefined;
|
|
375
|
-
delim: string;
|
|
376
|
-
};
|
|
377
|
-
"mclass": {
|
|
378
|
-
type: "mclass";
|
|
379
|
-
mode: Mode;
|
|
380
|
-
loc?: SourceLocation | null | undefined;
|
|
381
|
-
mclass: string;
|
|
382
|
-
body: AnyParseNode[];
|
|
383
|
-
isCharacterBox: boolean;
|
|
384
|
-
};
|
|
385
|
-
"operatorname": {
|
|
386
|
-
type: "operatorname";
|
|
387
|
-
mode: Mode;
|
|
388
|
-
loc?: SourceLocation | null | undefined;
|
|
389
|
-
body: AnyParseNode[];
|
|
390
|
-
alwaysHandleSupSub: boolean;
|
|
391
|
-
limits: boolean;
|
|
392
|
-
parentIsSupSub: boolean;
|
|
393
|
-
};
|
|
394
|
-
"overline": {
|
|
395
|
-
type: "overline";
|
|
396
|
-
mode: Mode;
|
|
397
|
-
loc?: SourceLocation | null | undefined;
|
|
398
|
-
body: AnyParseNode;
|
|
399
|
-
};
|
|
400
|
-
"phantom": {
|
|
401
|
-
type: "phantom";
|
|
402
|
-
mode: Mode;
|
|
403
|
-
loc?: SourceLocation | null | undefined;
|
|
404
|
-
body: AnyParseNode[];
|
|
405
|
-
};
|
|
406
|
-
"vphantom": {
|
|
407
|
-
type: "vphantom";
|
|
408
|
-
mode: Mode;
|
|
409
|
-
loc?: SourceLocation | null | undefined;
|
|
410
|
-
body: AnyParseNode;
|
|
411
|
-
};
|
|
412
|
-
"pmb": {
|
|
413
|
-
type: "pmb";
|
|
414
|
-
mode: Mode;
|
|
415
|
-
loc?: SourceLocation | null | undefined;
|
|
416
|
-
mclass: string;
|
|
417
|
-
body: AnyParseNode[];
|
|
418
|
-
};
|
|
419
|
-
"raisebox": {
|
|
420
|
-
type: "raisebox";
|
|
421
|
-
mode: Mode;
|
|
422
|
-
loc?: SourceLocation | null | undefined;
|
|
423
|
-
dy: Measurement;
|
|
424
|
-
body: AnyParseNode;
|
|
425
|
-
};
|
|
426
|
-
"rule": {
|
|
427
|
-
type: "rule";
|
|
428
|
-
mode: Mode;
|
|
429
|
-
loc?: SourceLocation | null | undefined;
|
|
430
|
-
shift: Measurement | null | undefined;
|
|
431
|
-
width: Measurement;
|
|
432
|
-
height: Measurement;
|
|
433
|
-
};
|
|
434
|
-
"sizing": {
|
|
435
|
-
type: "sizing";
|
|
436
|
-
mode: Mode;
|
|
437
|
-
loc?: SourceLocation | null | undefined;
|
|
438
|
-
size: number;
|
|
439
|
-
body: AnyParseNode[];
|
|
440
|
-
};
|
|
441
|
-
"smash": {
|
|
442
|
-
type: "smash";
|
|
443
|
-
mode: Mode;
|
|
444
|
-
loc?: SourceLocation | null | undefined;
|
|
445
|
-
body: AnyParseNode;
|
|
446
|
-
smashHeight: boolean;
|
|
447
|
-
smashDepth: boolean;
|
|
448
|
-
};
|
|
449
|
-
"sqrt": {
|
|
450
|
-
type: "sqrt";
|
|
451
|
-
mode: Mode;
|
|
452
|
-
loc?: SourceLocation | null | undefined;
|
|
453
|
-
body: AnyParseNode;
|
|
454
|
-
index: AnyParseNode | null | undefined;
|
|
455
|
-
};
|
|
456
|
-
"underline": {
|
|
457
|
-
type: "underline";
|
|
458
|
-
mode: Mode;
|
|
459
|
-
loc?: SourceLocation | null | undefined;
|
|
460
|
-
body: AnyParseNode;
|
|
461
|
-
};
|
|
462
|
-
"vcenter": {
|
|
463
|
-
type: "vcenter";
|
|
464
|
-
mode: Mode;
|
|
465
|
-
loc?: SourceLocation | null | undefined;
|
|
466
|
-
body: AnyParseNode;
|
|
467
|
-
};
|
|
468
|
-
"xArrow": {
|
|
469
|
-
type: "xArrow";
|
|
470
|
-
mode: Mode;
|
|
471
|
-
loc?: SourceLocation | null | undefined;
|
|
472
|
-
label: string;
|
|
473
|
-
body: AnyParseNode;
|
|
474
|
-
below: AnyParseNode | null | undefined;
|
|
475
|
-
};
|
|
476
|
-
};
|
|
1
|
+
import {NonAtoms} from "./atoms";
|
|
2
|
+
import type {AnyParseNode, NodeType, ParseNode, SymbolParseNode} from "./types/nodes";
|
|
477
3
|
|
|
478
4
|
/**
|
|
479
5
|
* Asserts that the node is of the given type and returns it with stricter
|
|
@@ -496,7 +22,7 @@ export function assertNodeType<NODETYPE extends NodeType>(
|
|
|
496
22
|
* Returns the node more strictly typed iff it is of the given type. Otherwise,
|
|
497
23
|
* returns null.
|
|
498
24
|
*/
|
|
499
|
-
export function assertSymbolNodeType(node: AnyParseNode
|
|
25
|
+
export function assertSymbolNodeType(node: AnyParseNode): SymbolParseNode {
|
|
500
26
|
const typedNode = checkSymbolNodeType(node);
|
|
501
27
|
if (!typedNode) {
|
|
502
28
|
throw new Error(
|
|
@@ -507,11 +33,11 @@ export function assertSymbolNodeType(node: AnyParseNode | null | undefined): Sym
|
|
|
507
33
|
}
|
|
508
34
|
|
|
509
35
|
/**
|
|
510
|
-
* Returns the node more strictly typed
|
|
36
|
+
* Returns the node more strictly typed if it is of the given type. Otherwise,
|
|
511
37
|
* returns null.
|
|
512
38
|
*/
|
|
513
|
-
export function checkSymbolNodeType(node: AnyParseNode
|
|
514
|
-
if (node
|
|
39
|
+
export function checkSymbolNodeType(node: AnyParseNode): SymbolParseNode | null {
|
|
40
|
+
if (node.type === "atom" || NonAtoms.has(node.type)) {
|
|
515
41
|
return node as SymbolParseNode;
|
|
516
42
|
}
|
|
517
43
|
return null;
|
package/src/parseTree.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provides a single function for parsing an expression using a Parser
|
|
3
|
-
* TODO(emily): Remove this
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
1
|
import Parser from "./Parser";
|
|
7
2
|
import ParseError from "./ParseError";
|
|
8
3
|
import {Token} from "./Token";
|
|
9
4
|
|
|
10
5
|
import type Settings from "./Settings";
|
|
11
|
-
import type {AnyParseNode} from "./
|
|
6
|
+
import type {AnyParseNode} from "./types/nodes";
|
|
12
7
|
|
|
13
8
|
/**
|
|
14
9
|
* Parses an expression using a Parser, then returns the parsed result.
|
package/src/spacingData.ts
CHANGED
package/src/stretchy.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {MathNode, TextNode} from "./mathMLTree";
|
|
|
10
10
|
import {makeEm} from "./units";
|
|
11
11
|
|
|
12
12
|
import type Options from "./Options";
|
|
13
|
-
import type {ParseNode} from "./
|
|
13
|
+
import type {ParseNode} from "./types/nodes";
|
|
14
14
|
import type {DomSpan, HtmlDomNode, SvgSpan} from "./domTree";
|
|
15
15
|
|
|
16
16
|
const stretchyCodePoint: Record<string, string> = {
|
|
@@ -277,7 +277,7 @@ export const stretchySvg = function(
|
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
return {
|
|
280
|
-
span: makeSpan(["stretchy"], spans, options),
|
|
280
|
+
span: makeSpan(["katex-stretchy"], spans, options),
|
|
281
281
|
minWidth,
|
|
282
282
|
height,
|
|
283
283
|
};
|
|
@@ -308,7 +308,7 @@ export const stretchyEnclose = function(
|
|
|
308
308
|
const totalHeight = inner.height + inner.depth + topPad + bottomPad;
|
|
309
309
|
|
|
310
310
|
if (/fbox|color|angl/.test(label)) {
|
|
311
|
-
img = makeSpan(["stretchy", label], [], options);
|
|
311
|
+
img = makeSpan(["katex-stretchy", label], [], options);
|
|
312
312
|
|
|
313
313
|
if (label === "fbox") {
|
|
314
314
|
const color = options.color && options.getColor();
|