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
package/src/parseNode.ts
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
import {NON_ATOMS} from "./symbols";
|
|
2
|
+
import type SourceLocation from "./SourceLocation";
|
|
3
|
+
import type {AlignSpec, ColSeparationType} from "./environments/array";
|
|
4
|
+
import type {Atom} from "./symbols";
|
|
5
|
+
import type {Mode, StyleStr} from "./types";
|
|
6
|
+
import type {Token} from "./Token";
|
|
7
|
+
import type {Measurement} from "./units";
|
|
8
|
+
export type NodeType = keyof ParseNodeTypes;
|
|
9
|
+
export type ParseNode<TYPE extends NodeType> = ParseNodeTypes[TYPE];
|
|
10
|
+
|
|
11
|
+
// ParseNode's corresponding to Symbol `Group`s in symbols.js.
|
|
12
|
+
export type SymbolParseNode =
|
|
13
|
+
ParseNode<"atom"> |
|
|
14
|
+
ParseNode<"accent-token"> |
|
|
15
|
+
ParseNode<"mathord"> |
|
|
16
|
+
ParseNode<"op-token"> |
|
|
17
|
+
ParseNode<"spacing"> |
|
|
18
|
+
ParseNode<"textord">;
|
|
19
|
+
|
|
20
|
+
// ParseNode from `Parser.formatUnsupportedCmd`
|
|
21
|
+
export type UnsupportedCmdParseNode = ParseNode<"color">;
|
|
22
|
+
|
|
23
|
+
// Union of all possible `ParseNode<>` types.
|
|
24
|
+
export type AnyParseNode = ParseNodeTypes[keyof ParseNodeTypes];
|
|
25
|
+
|
|
26
|
+
// Map from `NodeType` to the corresponding `ParseNode`.
|
|
27
|
+
type ParseNodeTypes = {
|
|
28
|
+
"array": {
|
|
29
|
+
type: "array";
|
|
30
|
+
mode: Mode;
|
|
31
|
+
loc?: SourceLocation | null | undefined;
|
|
32
|
+
colSeparationType?: ColSeparationType;
|
|
33
|
+
hskipBeforeAndAfter?: boolean;
|
|
34
|
+
addJot?: boolean;
|
|
35
|
+
cols?: AlignSpec[];
|
|
36
|
+
arraystretch: number;
|
|
37
|
+
body: AnyParseNode[][];
|
|
38
|
+
// List of rows in the (2D) array.
|
|
39
|
+
rowGaps: (Measurement | null | undefined)[];
|
|
40
|
+
hLinesBeforeRow: Array<boolean[]>;
|
|
41
|
+
// Whether each row should be automatically numbered, or an explicit tag
|
|
42
|
+
tags?: (boolean | AnyParseNode[])[];
|
|
43
|
+
leqno?: boolean;
|
|
44
|
+
isCD?: boolean;
|
|
45
|
+
};
|
|
46
|
+
"cdlabel": {
|
|
47
|
+
type: "cdlabel";
|
|
48
|
+
mode: Mode;
|
|
49
|
+
loc?: SourceLocation | null | undefined;
|
|
50
|
+
side: string;
|
|
51
|
+
label: AnyParseNode;
|
|
52
|
+
};
|
|
53
|
+
"cdlabelparent": {
|
|
54
|
+
type: "cdlabelparent";
|
|
55
|
+
mode: Mode;
|
|
56
|
+
loc?: SourceLocation | null | undefined;
|
|
57
|
+
fragment: AnyParseNode;
|
|
58
|
+
};
|
|
59
|
+
"color": {
|
|
60
|
+
type: "color";
|
|
61
|
+
mode: Mode;
|
|
62
|
+
loc?: SourceLocation | null | undefined;
|
|
63
|
+
color: string;
|
|
64
|
+
body: AnyParseNode[];
|
|
65
|
+
};
|
|
66
|
+
"color-token": {
|
|
67
|
+
type: "color-token";
|
|
68
|
+
mode: Mode;
|
|
69
|
+
loc?: SourceLocation | null | undefined;
|
|
70
|
+
color: string;
|
|
71
|
+
};
|
|
72
|
+
// To avoid requiring run-time type assertions, this more carefully captures
|
|
73
|
+
// the requirements on the fields per the op.js htmlBuilder logic:
|
|
74
|
+
// - `body` and `value` are NEVER set simultaneously.
|
|
75
|
+
// - When `symbol` is true, `body` is set.
|
|
76
|
+
"op": {
|
|
77
|
+
type: "op";
|
|
78
|
+
mode: Mode;
|
|
79
|
+
loc?: SourceLocation | null | undefined;
|
|
80
|
+
limits: boolean;
|
|
81
|
+
alwaysHandleSupSub?: boolean;
|
|
82
|
+
suppressBaseShift?: boolean;
|
|
83
|
+
parentIsSupSub: boolean;
|
|
84
|
+
symbol: boolean;
|
|
85
|
+
name: string;
|
|
86
|
+
body?: void;
|
|
87
|
+
} | {
|
|
88
|
+
type: "op";
|
|
89
|
+
mode: Mode;
|
|
90
|
+
loc?: SourceLocation | null | undefined;
|
|
91
|
+
limits: boolean;
|
|
92
|
+
alwaysHandleSupSub?: boolean;
|
|
93
|
+
suppressBaseShift?: boolean;
|
|
94
|
+
parentIsSupSub: boolean;
|
|
95
|
+
symbol: false;
|
|
96
|
+
// If 'symbol' is true, `body` *must* be set.
|
|
97
|
+
name?: void;
|
|
98
|
+
body: AnyParseNode[];
|
|
99
|
+
};
|
|
100
|
+
"ordgroup": {
|
|
101
|
+
type: "ordgroup";
|
|
102
|
+
mode: Mode;
|
|
103
|
+
loc?: SourceLocation | null | undefined;
|
|
104
|
+
body: AnyParseNode[];
|
|
105
|
+
semisimple?: boolean;
|
|
106
|
+
};
|
|
107
|
+
"raw": {
|
|
108
|
+
type: "raw";
|
|
109
|
+
mode: Mode;
|
|
110
|
+
loc?: SourceLocation | null | undefined;
|
|
111
|
+
string: string;
|
|
112
|
+
};
|
|
113
|
+
"size": {
|
|
114
|
+
type: "size";
|
|
115
|
+
mode: Mode;
|
|
116
|
+
loc?: SourceLocation | null | undefined;
|
|
117
|
+
value: Measurement;
|
|
118
|
+
isBlank: boolean;
|
|
119
|
+
};
|
|
120
|
+
"styling": {
|
|
121
|
+
type: "styling";
|
|
122
|
+
mode: Mode;
|
|
123
|
+
loc?: SourceLocation | null | undefined;
|
|
124
|
+
style: StyleStr;
|
|
125
|
+
body: AnyParseNode[];
|
|
126
|
+
};
|
|
127
|
+
"supsub": {
|
|
128
|
+
type: "supsub";
|
|
129
|
+
mode: Mode;
|
|
130
|
+
loc?: SourceLocation | null | undefined;
|
|
131
|
+
base: AnyParseNode | null | undefined;
|
|
132
|
+
sup?: AnyParseNode | null | undefined;
|
|
133
|
+
sub?: AnyParseNode | null | undefined;
|
|
134
|
+
};
|
|
135
|
+
"tag": {
|
|
136
|
+
type: "tag";
|
|
137
|
+
mode: Mode;
|
|
138
|
+
loc?: SourceLocation | null | undefined;
|
|
139
|
+
body: AnyParseNode[];
|
|
140
|
+
tag: AnyParseNode[];
|
|
141
|
+
};
|
|
142
|
+
"text": {
|
|
143
|
+
type: "text";
|
|
144
|
+
mode: Mode;
|
|
145
|
+
loc?: SourceLocation | null | undefined;
|
|
146
|
+
body: AnyParseNode[];
|
|
147
|
+
font?: string;
|
|
148
|
+
};
|
|
149
|
+
"url": {
|
|
150
|
+
type: "url";
|
|
151
|
+
mode: Mode;
|
|
152
|
+
loc?: SourceLocation | null | undefined;
|
|
153
|
+
url: string;
|
|
154
|
+
};
|
|
155
|
+
"verb": {
|
|
156
|
+
type: "verb";
|
|
157
|
+
mode: Mode;
|
|
158
|
+
loc?: SourceLocation | null | undefined;
|
|
159
|
+
body: string;
|
|
160
|
+
star: boolean;
|
|
161
|
+
};
|
|
162
|
+
// From symbol groups, constructed in Parser.js via `symbols` lookup.
|
|
163
|
+
// (Some of these have "-token" suffix to distinguish them from existing
|
|
164
|
+
// `ParseNode` types.)
|
|
165
|
+
"atom": {
|
|
166
|
+
type: "atom";
|
|
167
|
+
family: Atom;
|
|
168
|
+
mode: Mode;
|
|
169
|
+
loc?: SourceLocation | null | undefined;
|
|
170
|
+
text: string;
|
|
171
|
+
};
|
|
172
|
+
"mathord": {
|
|
173
|
+
type: "mathord";
|
|
174
|
+
mode: Mode;
|
|
175
|
+
loc?: SourceLocation | null | undefined;
|
|
176
|
+
text: string;
|
|
177
|
+
};
|
|
178
|
+
"spacing": {
|
|
179
|
+
type: "spacing";
|
|
180
|
+
mode: Mode;
|
|
181
|
+
loc?: SourceLocation | null | undefined;
|
|
182
|
+
text: string;
|
|
183
|
+
};
|
|
184
|
+
"textord": {
|
|
185
|
+
type: "textord";
|
|
186
|
+
mode: Mode;
|
|
187
|
+
loc?: SourceLocation | null | undefined;
|
|
188
|
+
text: string;
|
|
189
|
+
};
|
|
190
|
+
// These "-token" types don't have corresponding HTML/MathML builders.
|
|
191
|
+
"accent-token": {
|
|
192
|
+
type: "accent-token";
|
|
193
|
+
mode: Mode;
|
|
194
|
+
loc?: SourceLocation | null | undefined;
|
|
195
|
+
text: string;
|
|
196
|
+
};
|
|
197
|
+
"op-token": {
|
|
198
|
+
type: "op-token";
|
|
199
|
+
mode: Mode;
|
|
200
|
+
loc?: SourceLocation | null | undefined;
|
|
201
|
+
text: string;
|
|
202
|
+
};
|
|
203
|
+
// From functions.js and functions/*.js. See also "color", "op", "styling",
|
|
204
|
+
// and "text" above.
|
|
205
|
+
"accent": {
|
|
206
|
+
type: "accent";
|
|
207
|
+
mode: Mode;
|
|
208
|
+
loc?: SourceLocation | null | undefined;
|
|
209
|
+
label: string;
|
|
210
|
+
isStretchy?: boolean;
|
|
211
|
+
isShifty?: boolean;
|
|
212
|
+
base: AnyParseNode;
|
|
213
|
+
};
|
|
214
|
+
"accentUnder": {
|
|
215
|
+
type: "accentUnder";
|
|
216
|
+
mode: Mode;
|
|
217
|
+
loc?: SourceLocation | null | undefined;
|
|
218
|
+
label: string;
|
|
219
|
+
isStretchy?: boolean;
|
|
220
|
+
isShifty?: boolean;
|
|
221
|
+
base: AnyParseNode;
|
|
222
|
+
};
|
|
223
|
+
"cr": {
|
|
224
|
+
type: "cr";
|
|
225
|
+
mode: Mode;
|
|
226
|
+
loc?: SourceLocation | null | undefined;
|
|
227
|
+
newLine: boolean;
|
|
228
|
+
size: Measurement | null | undefined;
|
|
229
|
+
};
|
|
230
|
+
"delimsizing": {
|
|
231
|
+
type: "delimsizing";
|
|
232
|
+
mode: Mode;
|
|
233
|
+
loc?: SourceLocation | null | undefined;
|
|
234
|
+
size: 1 | 2 | 3 | 4;
|
|
235
|
+
mclass: "mopen" | "mclose" | "mrel" | "mord";
|
|
236
|
+
delim: string;
|
|
237
|
+
};
|
|
238
|
+
"enclose": {
|
|
239
|
+
type: "enclose";
|
|
240
|
+
mode: Mode;
|
|
241
|
+
loc?: SourceLocation | null | undefined;
|
|
242
|
+
label: string;
|
|
243
|
+
backgroundColor?: string;
|
|
244
|
+
borderColor?: string;
|
|
245
|
+
body: AnyParseNode;
|
|
246
|
+
};
|
|
247
|
+
"environment": {
|
|
248
|
+
type: "environment";
|
|
249
|
+
mode: Mode;
|
|
250
|
+
loc?: SourceLocation | null | undefined;
|
|
251
|
+
name: string;
|
|
252
|
+
nameGroup: AnyParseNode;
|
|
253
|
+
};
|
|
254
|
+
"font": {
|
|
255
|
+
type: "font";
|
|
256
|
+
mode: Mode;
|
|
257
|
+
loc?: SourceLocation | null | undefined;
|
|
258
|
+
font: string;
|
|
259
|
+
body: AnyParseNode;
|
|
260
|
+
};
|
|
261
|
+
"genfrac": {
|
|
262
|
+
type: "genfrac";
|
|
263
|
+
mode: Mode;
|
|
264
|
+
loc?: SourceLocation | null | undefined;
|
|
265
|
+
continued: boolean;
|
|
266
|
+
numer: AnyParseNode;
|
|
267
|
+
denom: AnyParseNode;
|
|
268
|
+
hasBarLine: boolean;
|
|
269
|
+
leftDelim: string | null | undefined;
|
|
270
|
+
rightDelim: string | null | undefined;
|
|
271
|
+
barSize: Measurement | null;
|
|
272
|
+
};
|
|
273
|
+
"hbox": {
|
|
274
|
+
type: "hbox";
|
|
275
|
+
mode: Mode;
|
|
276
|
+
loc?: SourceLocation | null | undefined;
|
|
277
|
+
body: AnyParseNode[];
|
|
278
|
+
};
|
|
279
|
+
"horizBrace": {
|
|
280
|
+
type: "horizBrace";
|
|
281
|
+
mode: Mode;
|
|
282
|
+
loc?: SourceLocation | null | undefined;
|
|
283
|
+
label: string;
|
|
284
|
+
isOver: boolean;
|
|
285
|
+
base: AnyParseNode;
|
|
286
|
+
};
|
|
287
|
+
"href": {
|
|
288
|
+
type: "href";
|
|
289
|
+
mode: Mode;
|
|
290
|
+
loc?: SourceLocation | null | undefined;
|
|
291
|
+
href: string;
|
|
292
|
+
body: AnyParseNode[];
|
|
293
|
+
};
|
|
294
|
+
"html": {
|
|
295
|
+
type: "html";
|
|
296
|
+
mode: Mode;
|
|
297
|
+
loc?: SourceLocation | null | undefined;
|
|
298
|
+
attributes: Record<string, string>;
|
|
299
|
+
body: AnyParseNode[];
|
|
300
|
+
};
|
|
301
|
+
"htmlmathml": {
|
|
302
|
+
type: "htmlmathml";
|
|
303
|
+
mode: Mode;
|
|
304
|
+
loc?: SourceLocation | null | undefined;
|
|
305
|
+
html: AnyParseNode[];
|
|
306
|
+
mathml: AnyParseNode[];
|
|
307
|
+
};
|
|
308
|
+
"includegraphics": {
|
|
309
|
+
type: "includegraphics";
|
|
310
|
+
mode: Mode;
|
|
311
|
+
loc?: SourceLocation | null | undefined;
|
|
312
|
+
alt: string;
|
|
313
|
+
width: Measurement;
|
|
314
|
+
height: Measurement;
|
|
315
|
+
totalheight: Measurement;
|
|
316
|
+
src: string;
|
|
317
|
+
};
|
|
318
|
+
"infix": {
|
|
319
|
+
type: "infix";
|
|
320
|
+
mode: Mode;
|
|
321
|
+
loc?: SourceLocation | null | undefined;
|
|
322
|
+
replaceWith: string;
|
|
323
|
+
size?: Measurement;
|
|
324
|
+
token: Token | null | undefined;
|
|
325
|
+
};
|
|
326
|
+
"internal": {
|
|
327
|
+
type: "internal";
|
|
328
|
+
mode: Mode;
|
|
329
|
+
loc?: SourceLocation | null | undefined;
|
|
330
|
+
};
|
|
331
|
+
"kern": {
|
|
332
|
+
type: "kern";
|
|
333
|
+
mode: Mode;
|
|
334
|
+
loc?: SourceLocation | null | undefined;
|
|
335
|
+
dimension: Measurement;
|
|
336
|
+
};
|
|
337
|
+
"lap": {
|
|
338
|
+
type: "lap";
|
|
339
|
+
mode: Mode;
|
|
340
|
+
loc?: SourceLocation | null | undefined;
|
|
341
|
+
alignment: string;
|
|
342
|
+
body: AnyParseNode;
|
|
343
|
+
};
|
|
344
|
+
"leftright": {
|
|
345
|
+
type: "leftright";
|
|
346
|
+
mode: Mode;
|
|
347
|
+
loc?: SourceLocation | null | undefined;
|
|
348
|
+
body: AnyParseNode[];
|
|
349
|
+
left: string;
|
|
350
|
+
right: string;
|
|
351
|
+
rightColor: string | null | undefined; // undefined means "inherit"
|
|
352
|
+
};
|
|
353
|
+
"leftright-right": {
|
|
354
|
+
type: "leftright-right";
|
|
355
|
+
mode: Mode;
|
|
356
|
+
loc?: SourceLocation | null | undefined;
|
|
357
|
+
delim: string;
|
|
358
|
+
color: string | null | undefined; // undefined means "inherit"
|
|
359
|
+
};
|
|
360
|
+
"mathchoice": {
|
|
361
|
+
type: "mathchoice";
|
|
362
|
+
mode: Mode;
|
|
363
|
+
loc?: SourceLocation | null | undefined;
|
|
364
|
+
display: AnyParseNode[];
|
|
365
|
+
text: AnyParseNode[];
|
|
366
|
+
script: AnyParseNode[];
|
|
367
|
+
scriptscript: AnyParseNode[];
|
|
368
|
+
};
|
|
369
|
+
"middle": {
|
|
370
|
+
type: "middle";
|
|
371
|
+
mode: Mode;
|
|
372
|
+
loc?: SourceLocation | null | undefined;
|
|
373
|
+
delim: string;
|
|
374
|
+
};
|
|
375
|
+
"mclass": {
|
|
376
|
+
type: "mclass";
|
|
377
|
+
mode: Mode;
|
|
378
|
+
loc?: SourceLocation | null | undefined;
|
|
379
|
+
mclass: string;
|
|
380
|
+
body: AnyParseNode[];
|
|
381
|
+
isCharacterBox: boolean;
|
|
382
|
+
};
|
|
383
|
+
"operatorname": {
|
|
384
|
+
type: "operatorname";
|
|
385
|
+
mode: Mode;
|
|
386
|
+
loc?: SourceLocation | null | undefined;
|
|
387
|
+
body: AnyParseNode[];
|
|
388
|
+
alwaysHandleSupSub: boolean;
|
|
389
|
+
limits: boolean;
|
|
390
|
+
parentIsSupSub: boolean;
|
|
391
|
+
};
|
|
392
|
+
"overline": {
|
|
393
|
+
type: "overline";
|
|
394
|
+
mode: Mode;
|
|
395
|
+
loc?: SourceLocation | null | undefined;
|
|
396
|
+
body: AnyParseNode;
|
|
397
|
+
};
|
|
398
|
+
"phantom": {
|
|
399
|
+
type: "phantom";
|
|
400
|
+
mode: Mode;
|
|
401
|
+
loc?: SourceLocation | null | undefined;
|
|
402
|
+
body: AnyParseNode[];
|
|
403
|
+
};
|
|
404
|
+
"hphantom": {
|
|
405
|
+
type: "hphantom";
|
|
406
|
+
mode: Mode;
|
|
407
|
+
loc?: SourceLocation | null | undefined;
|
|
408
|
+
body: AnyParseNode;
|
|
409
|
+
};
|
|
410
|
+
"vphantom": {
|
|
411
|
+
type: "vphantom";
|
|
412
|
+
mode: Mode;
|
|
413
|
+
loc?: SourceLocation | null | undefined;
|
|
414
|
+
body: AnyParseNode;
|
|
415
|
+
};
|
|
416
|
+
"pmb": {
|
|
417
|
+
type: "pmb";
|
|
418
|
+
mode: Mode;
|
|
419
|
+
loc?: SourceLocation | null | undefined;
|
|
420
|
+
mclass: string;
|
|
421
|
+
body: AnyParseNode[];
|
|
422
|
+
};
|
|
423
|
+
"raisebox": {
|
|
424
|
+
type: "raisebox";
|
|
425
|
+
mode: Mode;
|
|
426
|
+
loc?: SourceLocation | null | undefined;
|
|
427
|
+
dy: Measurement;
|
|
428
|
+
body: AnyParseNode;
|
|
429
|
+
};
|
|
430
|
+
"rule": {
|
|
431
|
+
type: "rule";
|
|
432
|
+
mode: Mode;
|
|
433
|
+
loc?: SourceLocation | null | undefined;
|
|
434
|
+
shift: Measurement | null | undefined;
|
|
435
|
+
width: Measurement;
|
|
436
|
+
height: Measurement;
|
|
437
|
+
};
|
|
438
|
+
"sizing": {
|
|
439
|
+
type: "sizing";
|
|
440
|
+
mode: Mode;
|
|
441
|
+
loc?: SourceLocation | null | undefined;
|
|
442
|
+
size: number;
|
|
443
|
+
body: AnyParseNode[];
|
|
444
|
+
};
|
|
445
|
+
"smash": {
|
|
446
|
+
type: "smash";
|
|
447
|
+
mode: Mode;
|
|
448
|
+
loc?: SourceLocation | null | undefined;
|
|
449
|
+
body: AnyParseNode;
|
|
450
|
+
smashHeight: boolean;
|
|
451
|
+
smashDepth: boolean;
|
|
452
|
+
};
|
|
453
|
+
"sqrt": {
|
|
454
|
+
type: "sqrt";
|
|
455
|
+
mode: Mode;
|
|
456
|
+
loc?: SourceLocation | null | undefined;
|
|
457
|
+
body: AnyParseNode;
|
|
458
|
+
index: AnyParseNode | null | undefined;
|
|
459
|
+
};
|
|
460
|
+
"underline": {
|
|
461
|
+
type: "underline";
|
|
462
|
+
mode: Mode;
|
|
463
|
+
loc?: SourceLocation | null | undefined;
|
|
464
|
+
body: AnyParseNode;
|
|
465
|
+
};
|
|
466
|
+
"vcenter": {
|
|
467
|
+
type: "vcenter";
|
|
468
|
+
mode: Mode;
|
|
469
|
+
loc?: SourceLocation | null | undefined;
|
|
470
|
+
body: AnyParseNode;
|
|
471
|
+
};
|
|
472
|
+
"xArrow": {
|
|
473
|
+
type: "xArrow";
|
|
474
|
+
mode: Mode;
|
|
475
|
+
loc?: SourceLocation | null | undefined;
|
|
476
|
+
label: string;
|
|
477
|
+
body: AnyParseNode;
|
|
478
|
+
below: AnyParseNode | null | undefined;
|
|
479
|
+
};
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Asserts that the node is of the given type and returns it with stricter
|
|
484
|
+
* typing. Throws if the node's type does not match.
|
|
485
|
+
*/
|
|
486
|
+
export function assertNodeType<NODETYPE extends NodeType>(
|
|
487
|
+
node: AnyParseNode | null | undefined,
|
|
488
|
+
type: NODETYPE,
|
|
489
|
+
): ParseNode<NODETYPE> {
|
|
490
|
+
if (!node || node.type !== type) {
|
|
491
|
+
throw new Error(
|
|
492
|
+
`Expected node of type ${type}, but got ` +
|
|
493
|
+
(node ? `node of type ${node.type}` : String(node)));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return node as ParseNode<NODETYPE>;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Returns the node more strictly typed iff it is of the given type. Otherwise,
|
|
501
|
+
* returns null.
|
|
502
|
+
*/
|
|
503
|
+
export function assertSymbolNodeType(node: AnyParseNode | null | undefined): SymbolParseNode {
|
|
504
|
+
const typedNode = checkSymbolNodeType(node);
|
|
505
|
+
if (!typedNode) {
|
|
506
|
+
throw new Error(
|
|
507
|
+
`Expected node of symbol group type, but got ` +
|
|
508
|
+
(node ? `node of type ${node.type}` : String(node)));
|
|
509
|
+
}
|
|
510
|
+
return typedNode;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Returns the node more strictly typed iff it is of the given type. Otherwise,
|
|
515
|
+
* returns null.
|
|
516
|
+
*/
|
|
517
|
+
export function checkSymbolNodeType(node: AnyParseNode | null | undefined): SymbolParseNode | null | undefined {
|
|
518
|
+
if (node && (node.type === "atom" || NON_ATOMS.hasOwnProperty(node.type))) {
|
|
519
|
+
return node as SymbolParseNode;
|
|
520
|
+
}
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/**
|
|
3
2
|
* Provides a single function for parsing an expression using a Parser
|
|
4
3
|
* TODO(emily): Remove this
|
|
@@ -14,11 +13,14 @@ import type {AnyParseNode} from "./parseNode";
|
|
|
14
13
|
/**
|
|
15
14
|
* Parses an expression using a Parser, then returns the parsed result.
|
|
16
15
|
*/
|
|
17
|
-
const parseTree = function(
|
|
16
|
+
const parseTree = function(
|
|
17
|
+
toParse: string | InstanceType<typeof String>,
|
|
18
|
+
settings: Settings,
|
|
19
|
+
): AnyParseNode[] {
|
|
18
20
|
if (!(typeof toParse === 'string' || toParse instanceof String)) {
|
|
19
21
|
throw new TypeError('KaTeX can only parse string typed expression');
|
|
20
22
|
}
|
|
21
|
-
const parser = new Parser(toParse, settings);
|
|
23
|
+
const parser = new Parser(toParse as string, settings);
|
|
22
24
|
|
|
23
25
|
// Blank out any \df@tag to avoid spurious "Duplicate \tag" errors
|
|
24
26
|
delete parser.gullet.macros.current["\\df@tag"];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/**
|
|
3
2
|
* Describes spaces between different classes of atoms.
|
|
4
3
|
*/
|
|
@@ -22,19 +21,19 @@ const thickspace: Measurement = {
|
|
|
22
21
|
// - https://github.com/facebook/flow/issues/5688
|
|
23
22
|
// However, since *all* fields are optional, $Shape<> works as suggested in 5688
|
|
24
23
|
// above.
|
|
25
|
-
export type Spacings =
|
|
26
|
-
mord: Measurement
|
|
27
|
-
mop: Measurement
|
|
28
|
-
mbin: Measurement
|
|
29
|
-
mrel: Measurement
|
|
30
|
-
mopen: Measurement
|
|
31
|
-
mclose: Measurement
|
|
32
|
-
mpunct: Measurement
|
|
33
|
-
minner: Measurement
|
|
24
|
+
export type Spacings = Partial<{
|
|
25
|
+
mord: Measurement;
|
|
26
|
+
mop: Measurement;
|
|
27
|
+
mbin: Measurement;
|
|
28
|
+
mrel: Measurement;
|
|
29
|
+
mopen: Measurement;
|
|
30
|
+
mclose: Measurement;
|
|
31
|
+
mpunct: Measurement;
|
|
32
|
+
minner: Measurement;
|
|
34
33
|
}> & {};
|
|
35
34
|
|
|
36
35
|
// Spacing relationships for display and text styles
|
|
37
|
-
export const spacings: {[
|
|
36
|
+
export const spacings: {[key in keyof Spacings]?: Spacings} = {
|
|
38
37
|
mord: {
|
|
39
38
|
mop: thinspace,
|
|
40
39
|
mbin: mediumspace,
|
|
@@ -87,7 +86,7 @@ export const spacings: {[$Keys<Spacings>]: Spacings} = {
|
|
|
87
86
|
};
|
|
88
87
|
|
|
89
88
|
// Spacing relationships for script and scriptscript styles
|
|
90
|
-
export const tightSpacings: {[
|
|
89
|
+
export const tightSpacings: {[key in keyof Spacings]?: Spacings} = {
|
|
91
90
|
mord: {
|
|
92
91
|
mop: thinspace,
|
|
93
92
|
},
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/**
|
|
3
2
|
* This file provides support to buildMathML.js and buildHTML.js
|
|
4
3
|
* for stretchy wide elements rendered from SVG files
|
|
@@ -14,7 +13,7 @@ import type Options from "./Options";
|
|
|
14
13
|
import type {ParseNode} from "./parseNode";
|
|
15
14
|
import type {DomSpan, HtmlDomNode, SvgSpan} from "./domTree";
|
|
16
15
|
|
|
17
|
-
const stretchyCodePoint:
|
|
16
|
+
const stretchyCodePoint: Record<string, string> = {
|
|
18
17
|
widehat: "^",
|
|
19
18
|
widecheck: "ˇ",
|
|
20
19
|
widetilde: "~",
|
|
@@ -115,7 +114,7 @@ export const stretchyMathML = function(label: string): MathNode {
|
|
|
115
114
|
// corresponds to 0.522 em inside the document.
|
|
116
115
|
|
|
117
116
|
const katexImagesData: {
|
|
118
|
-
[string]: ([string[], number, number] | [[string], number, number, string])
|
|
117
|
+
[key: string]: ([string[], number, number] | [[string], number, number, string])
|
|
119
118
|
} = {
|
|
120
119
|
// path(s), minWidth, height, align
|
|
121
120
|
overrightarrow: [["rightarrow"], 0.888, 522, "xMaxYMin"],
|
|
@@ -189,8 +188,8 @@ export const stretchySvg = function(
|
|
|
189
188
|
if (wideAccentLabels.has(label)) {
|
|
190
189
|
// Each type in the `if` statement corresponds to one of the ParseNode
|
|
191
190
|
// types below. This narrowing is required to access `grp.base`.
|
|
192
|
-
//
|
|
193
|
-
const grp
|
|
191
|
+
// TODO(ts)
|
|
192
|
+
const grp = group as ParseNode<"accent"> | ParseNode<"accentUnder">;
|
|
194
193
|
// There are four SVG images available for each function.
|
|
195
194
|
// Choose a taller image when there are more characters.
|
|
196
195
|
const numChars = grp.base.type === "ordgroup" ?
|
|
@@ -248,8 +247,9 @@ export const stretchySvg = function(
|
|
|
248
247
|
let widthClasses;
|
|
249
248
|
let aligns;
|
|
250
249
|
if (numSvgChildren === 1) {
|
|
251
|
-
//
|
|
252
|
-
const align1: string =
|
|
250
|
+
// TODO(ts): All these cases must be of the 4-tuple type.
|
|
251
|
+
const align1: string =
|
|
252
|
+
(data as [[string], number, number, string])[3];
|
|
253
253
|
widthClasses = ["hide-tail"];
|
|
254
254
|
aligns = [align1];
|
|
255
255
|
} else if (numSvgChildren === 2) {
|
package/src/styles/katex.scss
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
/* stylelint-disable font-family-no-missing-generic-family-keyword */
|
|
2
2
|
@use "sass:list";
|
|
3
3
|
@use "sass:math";
|
|
4
|
+
|
|
5
|
+
@forward "fonts.scss" with (
|
|
6
|
+
$font-folder: "../../fonts" !default,
|
|
7
|
+
$use-woff2: true !default,
|
|
8
|
+
$use-woff: true !default,
|
|
9
|
+
$use-ttf: true !default,
|
|
10
|
+
$font-display: block !default
|
|
11
|
+
);
|
|
12
|
+
|
|
4
13
|
@use "fonts.scss";
|
|
5
14
|
|
|
6
15
|
// The mu unit is defined as 1/18 em
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/**
|
|
3
2
|
* This file provides support to domTree.js and delimiter.js.
|
|
4
3
|
* It's a storehouse of path geometry for SVG images.
|
|
@@ -179,7 +178,7 @@ export const innerPath = function(name: string, height: number): string {
|
|
|
179
178
|
}
|
|
180
179
|
};
|
|
181
180
|
|
|
182
|
-
export const path:
|
|
181
|
+
export const path: Record<string, string> = {
|
|
183
182
|
// The doubleleftarrow geometry is from glyph U+21D0 in the font KaTeX Main
|
|
184
183
|
doubleleftarrow: `M262 157
|
|
185
184
|
l10-10c34-36 62.7-77 86-123 3.3-8 5-13.3 5-16 0-5.3-6.7-8-20-8-7.3
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/**
|
|
3
2
|
* This file holds a list of all no-argument functions and single-character
|
|
4
3
|
* symbols (like 'a' or ';').
|
|
@@ -40,12 +39,13 @@ export const NON_ATOMS = {
|
|
|
40
39
|
"textord": 1,
|
|
41
40
|
};
|
|
42
41
|
|
|
43
|
-
export type Atom =
|
|
44
|
-
export type NonAtom =
|
|
42
|
+
export type Atom = keyof typeof ATOMS;
|
|
43
|
+
export type NonAtom = keyof typeof NON_ATOMS;
|
|
45
44
|
export type Group = Atom | NonAtom;
|
|
46
|
-
type CharInfoMap = {[string]: {font: Font, group: Group, replace: ?string}};
|
|
47
45
|
|
|
48
|
-
|
|
46
|
+
type CharInfoMap = Record<string, {font: Font, group: Group, replace: string | null | undefined}>;
|
|
47
|
+
|
|
48
|
+
const symbols: Record<Mode, CharInfoMap> = {
|
|
49
49
|
"math": {},
|
|
50
50
|
"text": {},
|
|
51
51
|
};
|
|
@@ -56,7 +56,7 @@ export function defineSymbol(
|
|
|
56
56
|
mode: Mode,
|
|
57
57
|
font: Font,
|
|
58
58
|
group: Group,
|
|
59
|
-
replace:
|
|
59
|
+
replace: string | null | undefined,
|
|
60
60
|
name: string,
|
|
61
61
|
acceptUnicodeChar?: boolean,
|
|
62
62
|
) {
|