katex 0.16.47 → 0.17.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.
Files changed (80) hide show
  1. package/README.md +5 -10
  2. package/contrib/copy-tex/README.md +2 -2
  3. package/contrib/mathtex-script-type/README.md +5 -5
  4. package/contrib/mhchem/README.md +1 -1
  5. package/contrib/render-a11y-string/render-a11y-string.ts +1 -1
  6. package/dist/README.md +5 -10
  7. package/dist/katex-swap.css +1 -1
  8. package/dist/katex-swap.min.css +1 -1
  9. package/dist/katex.css +1 -1
  10. package/dist/katex.js +254 -433
  11. package/dist/katex.min.css +1 -1
  12. package/dist/katex.min.js +1 -1
  13. package/dist/katex.mjs +242 -414
  14. package/katex.ts +1 -1
  15. package/package.json +1 -1
  16. package/src/MacroExpander.ts +1 -1
  17. package/src/Namespace.ts +1 -1
  18. package/src/ParseError.ts +1 -1
  19. package/src/Parser.ts +42 -48
  20. package/src/Settings.ts +1 -1
  21. package/src/SourceLocation.ts +2 -2
  22. package/src/buildCommon.ts +6 -6
  23. package/src/buildHTML.ts +4 -5
  24. package/src/buildMathML.ts +1 -1
  25. package/src/buildTree.ts +1 -1
  26. package/src/defineEnvironment.ts +1 -2
  27. package/src/defineFunction.ts +104 -112
  28. package/src/environments/array.ts +8 -12
  29. package/src/environments/cd.ts +8 -8
  30. package/src/functions/accent.ts +10 -13
  31. package/src/functions/accentunder.ts +4 -4
  32. package/src/functions/arrow.ts +5 -5
  33. package/src/functions/char.ts +3 -4
  34. package/src/functions/color.ts +10 -13
  35. package/src/functions/cr.ts +3 -5
  36. package/src/functions/def.ts +15 -19
  37. package/src/functions/delimsizing.ts +23 -23
  38. package/src/functions/enclose.ts +22 -33
  39. package/src/functions/environment.ts +4 -5
  40. package/src/functions/font.ts +15 -27
  41. package/src/functions/genfrac.ts +19 -23
  42. package/src/functions/hbox.ts +6 -6
  43. package/src/functions/horizBrace.ts +4 -4
  44. package/src/functions/href.ts +10 -11
  45. package/src/functions/html.ts +5 -5
  46. package/src/functions/htmlmathml.ts +5 -5
  47. package/src/functions/includegraphics.ts +7 -7
  48. package/src/functions/kern.ts +6 -6
  49. package/src/functions/lap.ts +4 -4
  50. package/src/functions/math.ts +8 -10
  51. package/src/functions/mathchoice.ts +5 -5
  52. package/src/functions/mclass.ts +16 -28
  53. package/src/functions/op.ts +16 -30
  54. package/src/functions/operatorname.ts +4 -4
  55. package/src/functions/overline.ts +3 -3
  56. package/src/functions/phantom.ts +8 -8
  57. package/src/functions/pmb.ts +5 -5
  58. package/src/functions/raisebox.ts +5 -5
  59. package/src/functions/relax.ts +4 -5
  60. package/src/functions/rule.ts +7 -7
  61. package/src/functions/sizing.ts +6 -6
  62. package/src/functions/smash.ts +5 -5
  63. package/src/functions/sqrt.ts +4 -4
  64. package/src/functions/styling.ts +5 -5
  65. package/src/functions/supsub.ts +1 -1
  66. package/src/functions/symbolsOrd.ts +3 -3
  67. package/src/functions/symbolsSpacing.ts +1 -1
  68. package/src/functions/text.ts +7 -7
  69. package/src/functions/underline.ts +4 -4
  70. package/src/functions/utils/assembleSupSub.ts +1 -1
  71. package/src/functions/vcenter.ts +5 -5
  72. package/src/functions/verb.ts +5 -5
  73. package/src/parseNode.ts +2 -476
  74. package/src/parseTree.ts +1 -6
  75. package/src/spacingData.ts +2 -1
  76. package/src/stretchy.ts +1 -1
  77. package/src/types/index.ts +12 -0
  78. package/src/types/nodes.ts +456 -0
  79. package/src/units.ts +1 -2
  80. package/src/utils.ts +1 -1
@@ -0,0 +1,456 @@
1
+ import type SourceLocation from "../SourceLocation";
2
+ import type {DelimiterSize, MathClass, Measurement, Mode, Side, StyleStr} from "./index";
3
+ import type {AlignSpec, ColSeparationType} from "../environments/array";
4
+ import type {Atom} from "../atoms";
5
+ import type {MathFont} from "./fonts";
6
+ import type {Token} from "../Token";
7
+
8
+ // ParseNode from `Parser.formatUnsupportedCmd`
9
+ export type UnsupportedCmdParseNode = ColorNode;
10
+
11
+ export type NodeType = AnyParseNode["type"];
12
+
13
+ export type ParseNode<T extends NodeType> = ParseNodeMap[T];
14
+
15
+ export type AnyParseNode =
16
+ | ArrayNode
17
+ | CommutativeDiagramLabelNode
18
+ | CommutativeDiagramLabelParentNode
19
+ | ColorNode
20
+ | ColorTokenNode
21
+ | OperatorNode
22
+ | OrdinaryGroupNode
23
+ | RawNode
24
+ | SizeNode
25
+ | StylingNode
26
+ | SupSubNode
27
+ | TagNode
28
+ | TextNode
29
+ | UrlNode
30
+ | VerbatimNode
31
+ | AtomNode
32
+ | MathOrdinaryNode
33
+ | TextOrdinaryNode
34
+ | SpacingNode
35
+ | AccentTokenNode
36
+ | OperatorTokenNode
37
+ | AccentNode
38
+ | AccentUnderNode
39
+ | CarriageReturnNode
40
+ | DelimiterSizingNode
41
+ | EncloseNode
42
+ | EnvironmentNode
43
+ | FontNode
44
+ | GeneralizedFractionNode
45
+ | HorizontalBoxNode
46
+ | HorizontalBraceNode
47
+ | HrefNode
48
+ | HtmlNode
49
+ | HtmlMathmlNode
50
+ | IncludeGraphicsNode
51
+ | InfixNode
52
+ | InternalNode
53
+ | KernNode
54
+ | LapNode
55
+ | LeftRightNode
56
+ | ClosingDelimiterNode
57
+ | MathChoiceNode
58
+ | MiddleNode
59
+ | MathClassNode
60
+ | OperatorNameNode
61
+ | OverlineNode
62
+ | UnderlineNode
63
+ | PhantomNode
64
+ | VerticalPhantomNode
65
+ | PoorMansBoldNode
66
+ | RaiseBoxNode
67
+ | RuleNode
68
+ | SizingNode
69
+ | SmashNode
70
+ | SqrtNode
71
+ | VerticalCenterNode
72
+ | ExtensibleArrowNode;
73
+
74
+ // ParseNode's corresponding to Symbol `Group`s in symbols.js.
75
+ export type SymbolParseNode =
76
+ ParseNode<"atom"> |
77
+ ParseNode<"accent-token"> |
78
+ ParseNode<"mathord"> |
79
+ ParseNode<"op-token"> |
80
+ ParseNode<"spacing"> |
81
+ ParseNode<"textord">;
82
+
83
+ type ParseNodeMap = {
84
+ [K in NodeType]: Extract<AnyParseNode, {type: K}>;
85
+ };
86
+
87
+ type BaseNode = {
88
+ mode: Mode;
89
+ loc?: SourceLocation | null;
90
+ };
91
+
92
+ type ArrayNode = BaseNode & {
93
+ type: "array";
94
+ colSeparationType?: ColSeparationType;
95
+ hskipBeforeAndAfter?: boolean;
96
+ addJot?: boolean;
97
+ cols?: AlignSpec[];
98
+ arraystretch: number;
99
+ body: AnyParseNode[][];
100
+ // List of rows in the (2D) array.
101
+ rowGaps: (Measurement | null)[];
102
+ hLinesBeforeRow: boolean[][];
103
+ // Whether each row should be automatically numbered, or an explicit tag
104
+ tags?: (boolean | AnyParseNode[])[];
105
+ leqno?: boolean;
106
+ };
107
+
108
+ type CommutativeDiagramLabelNode = BaseNode & {
109
+ type: "cdlabel";
110
+ side: Side;
111
+ label: AnyParseNode;
112
+ };
113
+
114
+ type CommutativeDiagramLabelParentNode = BaseNode & {
115
+ type: "cdlabelparent";
116
+ fragment: AnyParseNode;
117
+ }
118
+
119
+ type ColorNode = BaseNode & {
120
+ type: "color";
121
+ color: string;
122
+ body: AnyParseNode[];
123
+ }
124
+
125
+ type ColorTokenNode = BaseNode & {
126
+ type: "color-token";
127
+ color: string;
128
+ }
129
+
130
+ type OperatorNodeBase = BaseNode & {
131
+ type: "op";
132
+ limits: boolean;
133
+ alwaysHandleSupSub?: boolean;
134
+ suppressBaseShift?: boolean;
135
+ parentIsSupSub: boolean;
136
+ }
137
+
138
+ type OperatorNode =
139
+ | OperatorNodeBase & {symbol: true; name: string; body?: never;}
140
+ | OperatorNodeBase & {symbol: false; body: AnyParseNode[]; name?: never;}
141
+ | OperatorNodeBase & {symbol: false; name: string; body?: never;};
142
+
143
+ type OrdinaryGroupNode = BaseNode & {
144
+ type: "ordgroup";
145
+ body: AnyParseNode[];
146
+ semisimple?: boolean;
147
+ }
148
+
149
+ type RawNode = BaseNode & {
150
+ type: "raw";
151
+ string: string;
152
+ }
153
+
154
+ type SizeNode = BaseNode & {
155
+ type: "size";
156
+ value: Measurement;
157
+ isBlank: boolean;
158
+ }
159
+
160
+ type StylingNode = BaseNode & {
161
+ type: "styling";
162
+ style: StyleStr;
163
+ resetFont?: boolean;
164
+ body: AnyParseNode[];
165
+ }
166
+
167
+ type SupSubNode = BaseNode & {
168
+ type: "supsub";
169
+ base: AnyParseNode | null;
170
+ } & (
171
+ | {sup: AnyParseNode; sub?: AnyParseNode;}
172
+ | {sup?: AnyParseNode; sub: AnyParseNode;}
173
+ );
174
+
175
+ type TagNode = BaseNode & {
176
+ type: "tag";
177
+ body: AnyParseNode[];
178
+ tag: AnyParseNode[];
179
+ }
180
+
181
+ type TextNode = BaseNode & {
182
+ type: "text";
183
+ body: AnyParseNode[];
184
+ font?: string;
185
+ }
186
+
187
+ type UrlNode = BaseNode & {
188
+ type: "url";
189
+ url: string;
190
+ }
191
+
192
+ type VerbatimNode = BaseNode & {
193
+ type: "verb";
194
+ body: string;
195
+ star: boolean;
196
+ }
197
+
198
+ type SymbolNode = BaseNode & {
199
+ text: string;
200
+ }
201
+
202
+ type AtomNode = SymbolNode & {
203
+ type: "atom";
204
+ family: Atom;
205
+ }
206
+
207
+ type MathOrdinaryNode = SymbolNode & {
208
+ type: "mathord";
209
+ }
210
+
211
+ type TextOrdinaryNode = SymbolNode & {
212
+ type: "textord";
213
+ }
214
+
215
+ type SpacingNode = SymbolNode & {
216
+ type: "spacing";
217
+ }
218
+
219
+ type AccentTokenNode = SymbolNode & {
220
+ type: "accent-token";
221
+ }
222
+
223
+ type OperatorTokenNode = SymbolNode & {
224
+ type: "op-token";
225
+ }
226
+
227
+ type AccentBaseNode = BaseNode & {
228
+ label: string;
229
+ isStretchy?: boolean;
230
+ isShifty?: boolean;
231
+ base: AnyParseNode;
232
+ }
233
+
234
+ type AccentNode = AccentBaseNode & {
235
+ type: "accent";
236
+ }
237
+
238
+ type AccentUnderNode = AccentBaseNode & {
239
+ type: "accentUnder";
240
+ }
241
+
242
+ type CarriageReturnNode = BaseNode & {
243
+ type: "cr";
244
+ newLine: boolean;
245
+ size: Measurement | null;
246
+ }
247
+
248
+ type DelimiterSizingNode = BaseNode & {
249
+ type: "delimsizing";
250
+ size: DelimiterSize;
251
+ mclass: "mopen" | "mclose" | "mrel" | "mord";
252
+ delim: string;
253
+ }
254
+
255
+ type EncloseNode = BaseNode & {
256
+ type: "enclose";
257
+ body: AnyParseNode;
258
+ label: string;
259
+ backgroundColor?: string;
260
+ borderColor?: string;
261
+ }
262
+
263
+ type EnvironmentNode = BaseNode & {
264
+ type: "environment";
265
+ name: string;
266
+ nameGroup: AnyParseNode;
267
+ }
268
+
269
+ type FontNode = BaseNode & {
270
+ type: "font";
271
+ font: Exclude<MathFont, "">;
272
+ body: AnyParseNode;
273
+ }
274
+
275
+ type GeneralizedFractionNode = BaseNode & {
276
+ type: "genfrac";
277
+ continued: boolean;
278
+ numer: AnyParseNode;
279
+ denom: AnyParseNode;
280
+ hasBarLine: boolean;
281
+ leftDelim: string | null;
282
+ rightDelim: string | null;
283
+ barSize: Measurement | null;
284
+ }
285
+
286
+ type HorizontalBoxNode = BaseNode & {
287
+ type: "hbox";
288
+ body: AnyParseNode[];
289
+ }
290
+
291
+ type HorizontalBraceNode = BaseNode & {
292
+ type: "horizBrace";
293
+ label: string;
294
+ isOver: boolean;
295
+ base: AnyParseNode;
296
+ }
297
+
298
+ type HrefNode = BaseNode & {
299
+ type: "href";
300
+ href: string;
301
+ body: AnyParseNode[];
302
+ }
303
+
304
+ type HtmlNode = BaseNode & {
305
+ type: "html";
306
+ attributes: Record<string, string>;
307
+ body: AnyParseNode[];
308
+ }
309
+
310
+ type HtmlMathmlNode = BaseNode & {
311
+ type: "htmlmathml";
312
+ html: AnyParseNode[];
313
+ mathml: AnyParseNode[];
314
+ }
315
+
316
+ type IncludeGraphicsNode = BaseNode & {
317
+ type: "includegraphics";
318
+ alt: string;
319
+ width: Measurement;
320
+ height: Measurement;
321
+ totalheight: Measurement;
322
+ src: string;
323
+ }
324
+
325
+ type InfixNode = BaseNode & {
326
+ type: "infix";
327
+ replaceWith: string;
328
+ size?: Measurement;
329
+ token?: Token;
330
+ }
331
+
332
+ type InternalNode = BaseNode & {
333
+ type: "internal";
334
+ }
335
+
336
+ type KernNode = BaseNode & {
337
+ type: "kern";
338
+ dimension: Measurement;
339
+ }
340
+
341
+ type LapNode = BaseNode & {
342
+ type: "lap";
343
+ alignment: string;
344
+ body: AnyParseNode;
345
+ }
346
+ type LeftRightNode = BaseNode & {
347
+ type: "leftright";
348
+ body: AnyParseNode[];
349
+ left: string;
350
+ right: string;
351
+ rightColor?: string;
352
+ }
353
+
354
+ type ClosingDelimiterNode = BaseNode & {
355
+ type: "leftright-right";
356
+ delim: string;
357
+ color?: string;
358
+ }
359
+
360
+ type MathChoiceNode = BaseNode & {
361
+ type: "mathchoice";
362
+ display: AnyParseNode[];
363
+ text: AnyParseNode[];
364
+ script: AnyParseNode[];
365
+ scriptscript: AnyParseNode[];
366
+ }
367
+
368
+ type MiddleNode = BaseNode & {
369
+ type: "middle";
370
+ delim: string;
371
+ }
372
+
373
+ type MathClassNode = BaseNode & {
374
+ type: "mclass";
375
+ mclass: MathClass;
376
+ body: AnyParseNode[];
377
+ isCharacterBox: boolean;
378
+ }
379
+
380
+ type OperatorNameNode = BaseNode & {
381
+ type: "operatorname";
382
+ body: AnyParseNode[];
383
+ alwaysHandleSupSub: boolean;
384
+ limits: boolean;
385
+ parentIsSupSub: boolean;
386
+ }
387
+
388
+ type OverlineNode = BaseNode & {
389
+ type: "overline";
390
+ body: AnyParseNode;
391
+ }
392
+
393
+ type UnderlineNode = BaseNode & {
394
+ type: "underline";
395
+ body: AnyParseNode;
396
+ }
397
+
398
+ type PhantomNode = BaseNode & {
399
+ type: "phantom";
400
+ body: AnyParseNode[];
401
+ }
402
+
403
+ type VerticalPhantomNode = BaseNode & {
404
+ type: "vphantom";
405
+ body: AnyParseNode;
406
+ }
407
+
408
+ type PoorMansBoldNode = BaseNode & {
409
+ type: "pmb";
410
+ mclass: MathClass;
411
+ body: AnyParseNode[];
412
+ }
413
+
414
+ type RaiseBoxNode = BaseNode & {
415
+ type: "raisebox";
416
+ dy: Measurement;
417
+ body: AnyParseNode;
418
+ }
419
+
420
+ type RuleNode = BaseNode & {
421
+ type: "rule";
422
+ shift: Measurement | null | undefined;
423
+ width: Measurement;
424
+ height: Measurement;
425
+ }
426
+
427
+ type SizingNode = BaseNode & {
428
+ type: "sizing";
429
+ size: number;
430
+ body: AnyParseNode[];
431
+ }
432
+
433
+ type SmashNode = BaseNode & {
434
+ type: "smash";
435
+ body: AnyParseNode;
436
+ smashHeight: boolean;
437
+ smashDepth: boolean;
438
+ }
439
+
440
+ type SqrtNode = BaseNode & {
441
+ type: "sqrt";
442
+ body: AnyParseNode;
443
+ index: AnyParseNode | null;
444
+ }
445
+
446
+ type VerticalCenterNode = BaseNode & {
447
+ type: "vcenter";
448
+ body: AnyParseNode;
449
+ }
450
+
451
+ type ExtensibleArrowNode = BaseNode & {
452
+ type: "xArrow";
453
+ label: string;
454
+ body: AnyParseNode;
455
+ below: AnyParseNode | null;
456
+ }
package/src/units.ts CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  import ParseError from "./ParseError";
7
7
  import Options from "./Options";
8
+ import type {Measurement} from "./types";
8
9
 
9
10
  // This table gives the number of TeX pts in one of each *absolute* TeX unit.
10
11
  // Thus, multiplying a length by this number converts the length from units
@@ -35,8 +36,6 @@ const relativeUnit = {
35
36
  "mu": true,
36
37
  };
37
38
 
38
- export type Measurement = { number: number, unit: string };
39
-
40
39
  /**
41
40
  * Determine whether the specified unit (either a string defining the unit
42
41
  * or a "size" parse node containing a unit field) is valid.
package/src/utils.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * files.
4
4
  */
5
5
 
6
- import type {AnyParseNode} from "./parseNode";
6
+ import type {AnyParseNode} from "./types/nodes";
7
7
 
8
8
  // hyphenate and escape adapted from Facebook's React under Apache 2 license
9
9
  const uppercase = /([A-Z])/g;