katex 0.17.0 → 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 +3 -3
- 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/dist/README.md +3 -3
- 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 +259 -420
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +259 -420
- package/package.json +12 -16
- package/src/MacroExpander.ts +10 -7
- package/src/Namespace.ts +16 -20
- package/src/Options.ts +2 -2
- package/src/Parser.ts +2 -2
- package/src/atoms.ts +22 -22
- package/src/buildCommon.ts +2 -2
- package/src/buildHTML.ts +8 -8
- package/src/buildMathML.ts +3 -3
- package/src/environments/array.ts +3 -3
- package/src/fontMetrics.ts +2 -4
- package/src/functions/accent.ts +2 -2
- package/src/functions/cr.ts +1 -1
- package/src/functions/enclose.ts +1 -1
- package/src/functions/environment.ts +1 -1
- package/src/functions/html.ts +3 -3
- package/src/functions/lap.ts +7 -7
- package/src/functions/overline.ts +1 -1
- package/src/functions/phantom.ts +2 -2
- package/src/functions/rule.ts +1 -1
- package/src/functions/sizing.ts +1 -1
- package/src/functions/smash.ts +1 -1
- package/src/functions/sqrt.ts +1 -1
- package/src/functions/symbolsSpacing.ts +20 -21
- package/src/functions/underline.ts +1 -1
- package/src/macros.ts +3 -3
- package/src/mathMLTree.ts +6 -10
- package/src/parseNode.ts +4 -4
- package/src/stretchy.ts +2 -2
- package/src/styles/katex.scss +31 -37
- package/src/wide-character.ts +2 -2
|
@@ -4,35 +4,34 @@ import {MathNode, TextNode} from "../mathMLTree";
|
|
|
4
4
|
import ParseError from "../ParseError";
|
|
5
5
|
|
|
6
6
|
// A map of CSS-based spacing functions to their CSS class.
|
|
7
|
-
const cssSpace
|
|
8
|
-
"\\nobreak"
|
|
9
|
-
"\\allowbreak"
|
|
10
|
-
|
|
7
|
+
const cssSpace = new Map<string, string>([
|
|
8
|
+
["\\nobreak", "nobreak"],
|
|
9
|
+
["\\allowbreak", "allowbreak"],
|
|
10
|
+
]);
|
|
11
11
|
|
|
12
12
|
// A lookup table to determine whether a spacing function/symbol should be
|
|
13
13
|
// treated like a regular space character. If a symbol or command is a key
|
|
14
14
|
// in this table, then it should be a regular space character. Furthermore,
|
|
15
15
|
// the associated value may have a `className` specifying an extra CSS class
|
|
16
16
|
// to add to the created `span`.
|
|
17
|
-
const regularSpace
|
|
18
|
-
" "
|
|
19
|
-
"\\ "
|
|
20
|
-
"~":
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
"\\nobreakspace": {
|
|
25
|
-
className: "nobreak",
|
|
26
|
-
},
|
|
27
|
-
};
|
|
17
|
+
const regularSpace = new Map<string, {className?: string}>([
|
|
18
|
+
[" ", {}],
|
|
19
|
+
["\\ ", {}],
|
|
20
|
+
["~", {className: "nobreak"}],
|
|
21
|
+
["\\space", {}],
|
|
22
|
+
["\\nobreakspace", {className: "nobreak"}],
|
|
23
|
+
]);
|
|
28
24
|
|
|
29
25
|
// ParseNode<"spacing"> created in Parser.js from the "spacing" symbol Groups in
|
|
30
26
|
// src/symbols.js.
|
|
31
27
|
defineFunctionBuilders({
|
|
32
28
|
type: "spacing",
|
|
33
29
|
htmlBuilder(group, options) {
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const regularSpaceItem = regularSpace.get(group.text);
|
|
31
|
+
const cssSpaceClass = cssSpace.get(group.text);
|
|
32
|
+
|
|
33
|
+
if (regularSpaceItem) {
|
|
34
|
+
const className = regularSpaceItem.className || "";
|
|
36
35
|
// Spaces are generated by adding an actual space. Each of these
|
|
37
36
|
// things has an entry in the symbols table, so these will be turned
|
|
38
37
|
// into appropriate outputs.
|
|
@@ -45,10 +44,10 @@ defineFunctionBuilders({
|
|
|
45
44
|
[mathsym(group.text, group.mode, options)],
|
|
46
45
|
options);
|
|
47
46
|
}
|
|
48
|
-
} else if (
|
|
47
|
+
} else if (cssSpaceClass) {
|
|
49
48
|
// Spaces based on just a CSS class.
|
|
50
49
|
return makeSpan(
|
|
51
|
-
["mspace",
|
|
50
|
+
["mspace", cssSpaceClass],
|
|
52
51
|
[], options);
|
|
53
52
|
} else {
|
|
54
53
|
throw new ParseError(`Unknown type of space "${group.text}"`);
|
|
@@ -57,10 +56,10 @@ defineFunctionBuilders({
|
|
|
57
56
|
mathmlBuilder(group, options) {
|
|
58
57
|
let node;
|
|
59
58
|
|
|
60
|
-
if (regularSpace.
|
|
59
|
+
if (regularSpace.has(group.text)) {
|
|
61
60
|
node = new MathNode(
|
|
62
61
|
"mtext", [new TextNode("\u00a0")]);
|
|
63
|
-
} else if (cssSpace.
|
|
62
|
+
} else if (cssSpace.has(group.text)) {
|
|
64
63
|
// CSS-based MathML spaces (\nobreak, \allowbreak) are ignored
|
|
65
64
|
return new MathNode("mspace");
|
|
66
65
|
} else {
|
package/src/macros.ts
CHANGED
|
@@ -14,7 +14,7 @@ import symbols from "./symbols";
|
|
|
14
14
|
import {makeEm} from "./units";
|
|
15
15
|
import ParseError from "./ParseError";
|
|
16
16
|
|
|
17
|
-
import type {MacroContextInterface} from "./defineMacro";
|
|
17
|
+
import type {MacroContextInterface, MacroExpansion} from "./defineMacro";
|
|
18
18
|
|
|
19
19
|
//////////////////////////////////////////////////////////////////////
|
|
20
20
|
// macro tools
|
|
@@ -916,7 +916,7 @@ defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
|
|
|
916
916
|
defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
|
|
917
917
|
defineMacro("\\Bra", "\\left\\langle#1\\right|");
|
|
918
918
|
defineMacro("\\Ket", "\\left|#1\\right\\rangle");
|
|
919
|
-
const braketHelper = (one: boolean) => (context: MacroContextInterface) => {
|
|
919
|
+
const braketHelper = (one: boolean) => (context: MacroContextInterface): MacroExpansion => {
|
|
920
920
|
const left = context.consumeArg().tokens;
|
|
921
921
|
const middle = context.consumeArg().tokens;
|
|
922
922
|
const middleDouble = context.consumeArg().tokens;
|
|
@@ -924,7 +924,7 @@ const braketHelper = (one: boolean) => (context: MacroContextInterface) => {
|
|
|
924
924
|
const oldMiddle = context.macros.get("|");
|
|
925
925
|
const oldMiddleDouble = context.macros.get("\\|");
|
|
926
926
|
context.macros.beginGroup();
|
|
927
|
-
const midMacro = (double: boolean) => (context: MacroContextInterface) => {
|
|
927
|
+
const midMacro = (double: boolean) => (context: MacroContextInterface): MacroExpansion => {
|
|
928
928
|
if (one) {
|
|
929
929
|
// Only modify the first instance of | or \|
|
|
930
930
|
context.macros.set("|", oldMiddle);
|
package/src/mathMLTree.ts
CHANGED
|
@@ -83,10 +83,8 @@ export class MathNode implements MathDomNode {
|
|
|
83
83
|
const node = document.createElementNS(
|
|
84
84
|
"http://www.w3.org/1998/Math/MathML", this.type);
|
|
85
85
|
|
|
86
|
-
for (const attr
|
|
87
|
-
|
|
88
|
-
node.setAttribute(attr, this.attributes[attr]);
|
|
89
|
-
}
|
|
86
|
+
for (const [attr, value] of Object.entries(this.attributes)) {
|
|
87
|
+
node.setAttribute(attr, value);
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
if (this.classes.length > 0) {
|
|
@@ -118,12 +116,10 @@ export class MathNode implements MathDomNode {
|
|
|
118
116
|
let markup = "<" + this.type;
|
|
119
117
|
|
|
120
118
|
// Add the attributes
|
|
121
|
-
for (const attr
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
markup += "\"";
|
|
126
|
-
}
|
|
119
|
+
for (const [attr, value] of Object.entries(this.attributes)) {
|
|
120
|
+
markup += " " + attr + "=\"";
|
|
121
|
+
markup += escape(value);
|
|
122
|
+
markup += "\"";
|
|
127
123
|
}
|
|
128
124
|
|
|
129
125
|
if (this.classes.length > 0) {
|
package/src/parseNode.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {NonAtoms} from "./atoms";
|
|
2
2
|
import type {AnyParseNode, NodeType, ParseNode, SymbolParseNode} from "./types/nodes";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -22,7 +22,7 @@ export function assertNodeType<NODETYPE extends NodeType>(
|
|
|
22
22
|
* Returns the node more strictly typed iff it is of the given type. Otherwise,
|
|
23
23
|
* returns null.
|
|
24
24
|
*/
|
|
25
|
-
export function assertSymbolNodeType(node: AnyParseNode
|
|
25
|
+
export function assertSymbolNodeType(node: AnyParseNode): SymbolParseNode {
|
|
26
26
|
const typedNode = checkSymbolNodeType(node);
|
|
27
27
|
if (!typedNode) {
|
|
28
28
|
throw new Error(
|
|
@@ -36,8 +36,8 @@ export function assertSymbolNodeType(node: AnyParseNode | null | undefined): Sym
|
|
|
36
36
|
* Returns the node more strictly typed if it is of the given type. Otherwise,
|
|
37
37
|
* returns null.
|
|
38
38
|
*/
|
|
39
|
-
export function checkSymbolNodeType(node: AnyParseNode
|
|
40
|
-
if (node
|
|
39
|
+
export function checkSymbolNodeType(node: AnyParseNode): SymbolParseNode | null {
|
|
40
|
+
if (node.type === "atom" || NonAtoms.has(node.type)) {
|
|
41
41
|
return node as SymbolParseNode;
|
|
42
42
|
}
|
|
43
43
|
return null;
|
package/src/stretchy.ts
CHANGED
|
@@ -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();
|
package/src/styles/katex.scss
CHANGED
|
@@ -58,13 +58,13 @@ $display-margin: 1em 0 !default;
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
.katex-html {
|
|
61
|
-
/* \newline is an empty block at top level, between .base elements */
|
|
62
|
-
> .newline {
|
|
61
|
+
/* \newline is an empty block at top level, between .katex-base elements */
|
|
62
|
+
> .katex-newline {
|
|
63
63
|
display: block;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
.base {
|
|
67
|
+
.katex-base {
|
|
68
68
|
position: relative;
|
|
69
69
|
display: inline-block;
|
|
70
70
|
white-space: nowrap;
|
|
@@ -73,7 +73,7 @@ $display-margin: 1em 0 !default;
|
|
|
73
73
|
width: min-content;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
.strut {
|
|
76
|
+
.katex-strut {
|
|
77
77
|
display: inline-block;
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -242,19 +242,13 @@ $display-margin: 1em 0 !default;
|
|
|
242
242
|
min-width: 2px;
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
.vbox {
|
|
245
|
+
.katex-vbox {
|
|
246
246
|
display: inline-flex;
|
|
247
247
|
flex-direction: column;
|
|
248
248
|
align-items: baseline;
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
-
.
|
|
252
|
-
display: inline-flex;
|
|
253
|
-
flex-direction: row;
|
|
254
|
-
width: 100%;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
.thinbox {
|
|
251
|
+
.katex-thinbox {
|
|
258
252
|
display: inline-flex;
|
|
259
253
|
flex-direction: row;
|
|
260
254
|
width: 0;
|
|
@@ -279,11 +273,11 @@ $display-margin: 1em 0 !default;
|
|
|
279
273
|
|
|
280
274
|
// Prevent Chrome from disappearing frac-lines, rules, etc.
|
|
281
275
|
.mfrac .frac-line,
|
|
282
|
-
.overline .overline-line,
|
|
283
|
-
.underline .underline-line,
|
|
284
|
-
.hline,
|
|
285
|
-
.hdashline,
|
|
286
|
-
.rule {
|
|
276
|
+
.katex-overline .overline-line,
|
|
277
|
+
.katex-underline .underline-line,
|
|
278
|
+
.katex-hline,
|
|
279
|
+
.katex-hdashline,
|
|
280
|
+
.katex-rule {
|
|
287
281
|
min-height: 1px;
|
|
288
282
|
}
|
|
289
283
|
|
|
@@ -291,7 +285,7 @@ $display-margin: 1em 0 !default;
|
|
|
291
285
|
display: inline-block;
|
|
292
286
|
}
|
|
293
287
|
|
|
294
|
-
.smash {
|
|
288
|
+
.katex-smash {
|
|
295
289
|
display: inline;
|
|
296
290
|
line-height: 0;
|
|
297
291
|
}
|
|
@@ -302,51 +296,51 @@ $display-margin: 1em 0 !default;
|
|
|
302
296
|
width: 0;
|
|
303
297
|
position: relative;
|
|
304
298
|
|
|
305
|
-
> .inner {
|
|
299
|
+
> .katex-inner {
|
|
306
300
|
position: absolute;
|
|
307
301
|
}
|
|
308
302
|
|
|
309
|
-
> .fix {
|
|
303
|
+
> .katex-fix {
|
|
310
304
|
display: inline-block;
|
|
311
305
|
}
|
|
312
306
|
}
|
|
313
307
|
|
|
314
|
-
.llap > .inner {
|
|
308
|
+
.llap > .katex-inner {
|
|
315
309
|
right: 0;
|
|
316
310
|
}
|
|
317
311
|
|
|
318
|
-
.rlap > .inner,
|
|
319
|
-
.clap > .inner {
|
|
312
|
+
.rlap > .katex-inner,
|
|
313
|
+
.clap > .katex-inner {
|
|
320
314
|
left: 0;
|
|
321
315
|
}
|
|
322
316
|
|
|
323
|
-
.clap > .inner > span {
|
|
317
|
+
.clap > .katex-inner > span {
|
|
324
318
|
margin-left: -50%;
|
|
325
319
|
margin-right: 50%;
|
|
326
320
|
}
|
|
327
321
|
|
|
328
|
-
.rule {
|
|
322
|
+
.katex-rule {
|
|
329
323
|
display: inline-block;
|
|
330
324
|
border: solid 0;
|
|
331
325
|
position: relative;
|
|
332
326
|
}
|
|
333
327
|
|
|
334
|
-
.overline .overline-line,
|
|
335
|
-
.underline .underline-line,
|
|
336
|
-
.hline {
|
|
328
|
+
.katex-overline .overline-line,
|
|
329
|
+
.katex-underline .underline-line,
|
|
330
|
+
.katex-hline {
|
|
337
331
|
display: inline-block;
|
|
338
332
|
width: 100%;
|
|
339
333
|
border-bottom-style: solid;
|
|
340
334
|
}
|
|
341
335
|
|
|
342
|
-
.hdashline {
|
|
336
|
+
.katex-hdashline {
|
|
343
337
|
display: inline-block;
|
|
344
338
|
width: 100%;
|
|
345
339
|
border-bottom-style: dashed;
|
|
346
340
|
}
|
|
347
341
|
|
|
348
342
|
.sqrt {
|
|
349
|
-
> .root {
|
|
343
|
+
> .katex-root {
|
|
350
344
|
/* These values are taken from the definition of `\r@@t`,
|
|
351
345
|
`\mkern 5mu` and `\mkern -10mu`. */
|
|
352
346
|
/* stylelint-disable-next-line declaration-property-value-no-unknown */
|
|
@@ -356,7 +350,7 @@ $display-margin: 1em 0 !default;
|
|
|
356
350
|
}
|
|
357
351
|
}
|
|
358
352
|
|
|
359
|
-
.sizing,
|
|
353
|
+
.katex-sizing,
|
|
360
354
|
.fontsize-ensurer {
|
|
361
355
|
$sizes: 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.2, 1.44, 1.728, 2.074, 2.488;
|
|
362
356
|
|
|
@@ -414,7 +408,7 @@ $display-margin: 1em 0 !default;
|
|
|
414
408
|
}
|
|
415
409
|
}
|
|
416
410
|
|
|
417
|
-
.accent {
|
|
411
|
+
.katex-accent {
|
|
418
412
|
> .vlist-t {
|
|
419
413
|
text-align: center;
|
|
420
414
|
}
|
|
@@ -430,7 +424,7 @@ $display-margin: 1em 0 !default;
|
|
|
430
424
|
}
|
|
431
425
|
}
|
|
432
426
|
|
|
433
|
-
.overlay {
|
|
427
|
+
.katex-overlay {
|
|
434
428
|
display: block;
|
|
435
429
|
}
|
|
436
430
|
|
|
@@ -503,7 +497,7 @@ $display-margin: 1em 0 !default;
|
|
|
503
497
|
}
|
|
504
498
|
|
|
505
499
|
// Define CSS for image whose width will match its span width.
|
|
506
|
-
.stretchy {
|
|
500
|
+
.katex-stretchy {
|
|
507
501
|
width: 100%;
|
|
508
502
|
display: block;
|
|
509
503
|
position: relative;
|
|
@@ -591,7 +585,7 @@ $display-margin: 1em 0 !default;
|
|
|
591
585
|
margin-right: -0.2em; // Apply negative margin to correct for 0.2em padding
|
|
592
586
|
} // inside the \cancel group.
|
|
593
587
|
|
|
594
|
-
.sout {
|
|
588
|
+
.katex-sout {
|
|
595
589
|
border-bottom-style: solid;
|
|
596
590
|
border-bottom-width: 0.08em;
|
|
597
591
|
}
|
|
@@ -656,7 +650,7 @@ $display-margin: 1em 0 !default;
|
|
|
656
650
|
display: block;
|
|
657
651
|
position: relative;
|
|
658
652
|
|
|
659
|
-
> .tag {
|
|
653
|
+
> .katex-tag {
|
|
660
654
|
position: absolute;
|
|
661
655
|
right: 0;
|
|
662
656
|
}
|
|
@@ -665,7 +659,7 @@ $display-margin: 1em 0 !default;
|
|
|
665
659
|
}
|
|
666
660
|
|
|
667
661
|
// Left-justified tags (default is right-justified)
|
|
668
|
-
.katex-display.leqno > .katex > .katex-html > .tag {
|
|
662
|
+
.katex-display.leqno > .katex > .katex-html > .katex-tag {
|
|
669
663
|
left: 0;
|
|
670
664
|
right: auto;
|
|
671
665
|
}
|
package/src/wide-character.ts
CHANGED
|
@@ -110,7 +110,7 @@ const wideLatinLetterData = [
|
|
|
110
110
|
italicSansSerif, italicSansSerif, // A-Z, a-z
|
|
111
111
|
noFont, noFont, // A-Z bold italic sans, a-z bold italic sans - no font
|
|
112
112
|
monospace, monospace, // A-Z, a-z
|
|
113
|
-
] as const;
|
|
113
|
+
] as const satisfies readonly WideChar[];
|
|
114
114
|
|
|
115
115
|
const wideNumeralData = [
|
|
116
116
|
boldUpright, // 0-9
|
|
@@ -118,7 +118,7 @@ const wideNumeralData = [
|
|
|
118
118
|
sansSerif, // 0-9
|
|
119
119
|
boldSansSerif, // 0-9
|
|
120
120
|
monospace, // 0-9
|
|
121
|
-
] as const;
|
|
121
|
+
] as const satisfies readonly WideChar[];
|
|
122
122
|
|
|
123
123
|
export const wideCharacterFont = (
|
|
124
124
|
wideChar: string,
|