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/functions/phantom.ts
CHANGED
|
@@ -9,10 +9,9 @@ import * as mml from "../buildMathML";
|
|
|
9
9
|
defineFunction({
|
|
10
10
|
type: "phantom",
|
|
11
11
|
names: ["\\phantom"],
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
12
|
+
numArgs: 1,
|
|
13
|
+
allowedInText: true,
|
|
14
|
+
|
|
16
15
|
handler: ({parser}, args) => {
|
|
17
16
|
const body = args[0];
|
|
18
17
|
return {
|
|
@@ -21,6 +20,7 @@ defineFunction({
|
|
|
21
20
|
body: ordargument(body),
|
|
22
21
|
};
|
|
23
22
|
},
|
|
23
|
+
|
|
24
24
|
htmlBuilder: (group, options) => {
|
|
25
25
|
const elements = html.buildExpression(
|
|
26
26
|
group.body,
|
|
@@ -43,10 +43,9 @@ defineMacro("\\hphantom", "\\smash{\\phantom{#1}}");
|
|
|
43
43
|
defineFunction({
|
|
44
44
|
type: "vphantom",
|
|
45
45
|
names: ["\\vphantom"],
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
46
|
+
numArgs: 1,
|
|
47
|
+
allowedInText: true,
|
|
48
|
+
|
|
50
49
|
handler: ({parser}, args) => {
|
|
51
50
|
const body = args[0];
|
|
52
51
|
return {
|
|
@@ -55,11 +54,12 @@ defineFunction({
|
|
|
55
54
|
body,
|
|
56
55
|
};
|
|
57
56
|
},
|
|
57
|
+
|
|
58
58
|
htmlBuilder: (group, options) => {
|
|
59
59
|
const inner = makeSpan(
|
|
60
|
-
["inner"],
|
|
60
|
+
["katex-inner"],
|
|
61
61
|
[html.buildGroup(group.body, options.withPhantom())]);
|
|
62
|
-
const fix = makeSpan(["fix"], []);
|
|
62
|
+
const fix = makeSpan(["katex-fix"], []);
|
|
63
63
|
return makeSpan(
|
|
64
64
|
["mord", "rlap"], [inner, fix], options);
|
|
65
65
|
},
|
package/src/functions/pmb.ts
CHANGED
|
@@ -5,7 +5,7 @@ import * as html from "../buildHTML";
|
|
|
5
5
|
import * as mml from "../buildMathML";
|
|
6
6
|
import {binrelClass} from "./mclass";
|
|
7
7
|
|
|
8
|
-
import type {ParseNode} from "../
|
|
8
|
+
import type {ParseNode} from "../types/nodes";
|
|
9
9
|
|
|
10
10
|
// \pmb is a simulation of bold font.
|
|
11
11
|
// The version of \pmb in ambsy.sty works by typesetting three copies
|
|
@@ -15,10 +15,9 @@ import type {ParseNode} from "../parseNode";
|
|
|
15
15
|
defineFunction({
|
|
16
16
|
type: "pmb",
|
|
17
17
|
names: ["\\pmb"],
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
18
|
+
numArgs: 1,
|
|
19
|
+
allowedInText: true,
|
|
20
|
+
|
|
22
21
|
handler({parser}, args) {
|
|
23
22
|
return {
|
|
24
23
|
type: "pmb",
|
|
@@ -27,6 +26,7 @@ defineFunction({
|
|
|
27
26
|
body: ordargument(args[0]),
|
|
28
27
|
};
|
|
29
28
|
},
|
|
29
|
+
|
|
30
30
|
htmlBuilder(group: ParseNode<"pmb">, options) {
|
|
31
31
|
const elements = html.buildExpression(group.body, options, true);
|
|
32
32
|
const node = makeSpan([group.mclass], elements, options);
|
|
@@ -11,11 +11,10 @@ import * as mml from "../buildMathML";
|
|
|
11
11
|
defineFunction({
|
|
12
12
|
type: "raisebox",
|
|
13
13
|
names: ["\\raisebox"],
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
14
|
+
numArgs: 2,
|
|
15
|
+
argTypes: ["size", "hbox"],
|
|
16
|
+
allowedInText: true,
|
|
17
|
+
|
|
19
18
|
handler({parser}, args) {
|
|
20
19
|
const amount = assertNodeType(args[0], "size").value;
|
|
21
20
|
const body = args[1];
|
|
@@ -26,6 +25,7 @@ defineFunction({
|
|
|
26
25
|
body,
|
|
27
26
|
};
|
|
28
27
|
},
|
|
28
|
+
|
|
29
29
|
htmlBuilder(group, options) {
|
|
30
30
|
const body = html.buildGroup(group.body, options);
|
|
31
31
|
const dy = calculateSize(group.dy, options);
|
package/src/functions/relax.ts
CHANGED
|
@@ -3,11 +3,10 @@ import defineFunction from "../defineFunction";
|
|
|
3
3
|
defineFunction({
|
|
4
4
|
type: "internal",
|
|
5
5
|
names: ["\\relax"],
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
6
|
+
numArgs: 0,
|
|
7
|
+
allowedInText: true,
|
|
8
|
+
allowedInArgument: true,
|
|
9
|
+
|
|
11
10
|
handler({parser}) {
|
|
12
11
|
return {
|
|
13
12
|
type: "internal",
|
package/src/functions/rule.ts
CHANGED
|
@@ -7,13 +7,12 @@ import {calculateSize, makeEm} from "../units";
|
|
|
7
7
|
defineFunction({
|
|
8
8
|
type: "rule",
|
|
9
9
|
names: ["\\rule"],
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
10
|
+
numArgs: 2,
|
|
11
|
+
numOptionalArgs: 1,
|
|
12
|
+
allowedInText: true,
|
|
13
|
+
allowedInMath: true,
|
|
14
|
+
argTypes: ["size", "size", "size"],
|
|
15
|
+
|
|
17
16
|
handler({parser}, args, optArgs) {
|
|
18
17
|
const shift = optArgs[0];
|
|
19
18
|
const width = assertNodeType(args[0], "size");
|
|
@@ -26,9 +25,10 @@ defineFunction({
|
|
|
26
25
|
height: height.value,
|
|
27
26
|
};
|
|
28
27
|
},
|
|
28
|
+
|
|
29
29
|
htmlBuilder(group, options) {
|
|
30
30
|
// Make an empty span for the rule
|
|
31
|
-
const rule = makeSpan(["mord", "rule"], [], options);
|
|
31
|
+
const rule = makeSpan(["mord", "katex-rule"], [], options);
|
|
32
32
|
|
|
33
33
|
// Calculate the shift, width, and height of the rule, and account for units
|
|
34
34
|
const width = calculateSize(group.width, options);
|
package/src/functions/sizing.ts
CHANGED
|
@@ -7,7 +7,7 @@ import * as html from "../buildHTML";
|
|
|
7
7
|
import * as mml from "../buildMathML";
|
|
8
8
|
|
|
9
9
|
import type Options from "../Options";
|
|
10
|
-
import type {AnyParseNode} from "../
|
|
10
|
+
import type {AnyParseNode} from "../types/nodes";
|
|
11
11
|
import type {HtmlBuilder} from "../defineFunction";
|
|
12
12
|
import type {documentFragment as HtmlDocumentFragment} from "../domTree";
|
|
13
13
|
|
|
@@ -22,7 +22,7 @@ export function sizingGroup(
|
|
|
22
22
|
// Add size-resetting classes to the inner list and set maxFontSize
|
|
23
23
|
// manually. Handle nested size changes.
|
|
24
24
|
for (let i = 0; i < inner.length; i++) {
|
|
25
|
-
const pos = inner[i].classes.indexOf("sizing");
|
|
25
|
+
const pos = inner[i].classes.indexOf("katex-sizing");
|
|
26
26
|
if (pos < 0) {
|
|
27
27
|
Array.prototype.push.apply(inner[i].classes,
|
|
28
28
|
options.sizingClasses(baseOptions));
|
|
@@ -43,7 +43,7 @@ export function sizingGroup(
|
|
|
43
43
|
const sizeFuncs = [
|
|
44
44
|
"\\tiny", "\\sixptsize", "\\scriptsize", "\\footnotesize", "\\small",
|
|
45
45
|
"\\normalsize", "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge",
|
|
46
|
-
];
|
|
46
|
+
] as const;
|
|
47
47
|
|
|
48
48
|
export const htmlBuilder: HtmlBuilder<"sizing"> = (group, options) => {
|
|
49
49
|
// Handle sizing operators like \Huge. Real TeX doesn't actually allow
|
|
@@ -56,10 +56,9 @@ export const htmlBuilder: HtmlBuilder<"sizing"> = (group, options) => {
|
|
|
56
56
|
defineFunction({
|
|
57
57
|
type: "sizing",
|
|
58
58
|
names: sizeFuncs,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
59
|
+
numArgs: 0,
|
|
60
|
+
allowedInText: true,
|
|
61
|
+
|
|
63
62
|
handler: ({breakOnTokenText, funcName, parser}, args) => {
|
|
64
63
|
const body = parser.parseExpression(false, breakOnTokenText);
|
|
65
64
|
|
|
@@ -71,6 +70,7 @@ defineFunction({
|
|
|
71
70
|
body,
|
|
72
71
|
};
|
|
73
72
|
},
|
|
73
|
+
|
|
74
74
|
htmlBuilder,
|
|
75
75
|
mathmlBuilder: (group, options) => {
|
|
76
76
|
const newOptions = options.havingSize(group.size);
|
package/src/functions/smash.ts
CHANGED
|
@@ -10,11 +10,10 @@ import * as mml from "../buildMathML";
|
|
|
10
10
|
defineFunction({
|
|
11
11
|
type: "smash",
|
|
12
12
|
names: ["\\smash"],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
13
|
+
numArgs: 1,
|
|
14
|
+
numOptionalArgs: 1,
|
|
15
|
+
allowedInText: true,
|
|
16
|
+
|
|
18
17
|
handler: ({parser}, args, optArgs) => {
|
|
19
18
|
let smashHeight = false;
|
|
20
19
|
let smashDepth = false;
|
|
@@ -51,6 +50,7 @@ defineFunction({
|
|
|
51
50
|
smashDepth,
|
|
52
51
|
};
|
|
53
52
|
},
|
|
53
|
+
|
|
54
54
|
htmlBuilder: (group, options) => {
|
|
55
55
|
const node = makeSpan(
|
|
56
56
|
[], [html.buildGroup(group.body, options)]);
|
|
@@ -69,7 +69,7 @@ defineFunction({
|
|
|
69
69
|
|
|
70
70
|
if (group.smashHeight && group.smashDepth) {
|
|
71
71
|
// Symmetric \smash can stay in inline layout.
|
|
72
|
-
return makeSpan(["mord", "smash"], [node], options);
|
|
72
|
+
return makeSpan(["mord", "katex-smash"], [node], options);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
// In order to influence makeVList for asymmetric smashing, we have to
|
package/src/functions/sqrt.ts
CHANGED
|
@@ -11,10 +11,9 @@ import * as mml from "../buildMathML";
|
|
|
11
11
|
defineFunction({
|
|
12
12
|
type: "sqrt",
|
|
13
13
|
names: ["\\sqrt"],
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
14
|
+
numArgs: 1,
|
|
15
|
+
numOptionalArgs: 1,
|
|
16
|
+
|
|
18
17
|
handler({parser}, args, optArgs) {
|
|
19
18
|
const index = optArgs[0];
|
|
20
19
|
const body = args[0];
|
|
@@ -25,6 +24,7 @@ defineFunction({
|
|
|
25
24
|
index,
|
|
26
25
|
};
|
|
27
26
|
},
|
|
27
|
+
|
|
28
28
|
htmlBuilder(group, options) {
|
|
29
29
|
// Square roots are handled in the TeXbook pg. 443, Rule 11.
|
|
30
30
|
|
|
@@ -104,7 +104,7 @@ defineFunction({
|
|
|
104
104
|
}, options);
|
|
105
105
|
// Add a class surrounding it so we can add on the appropriate
|
|
106
106
|
// kerning
|
|
107
|
-
const rootVListWrap = makeSpan(["root"], [rootVList]);
|
|
107
|
+
const rootVListWrap = makeSpan(["katex-root"], [rootVList]);
|
|
108
108
|
|
|
109
109
|
return makeSpan(["mord", "sqrt"],
|
|
110
110
|
[rootVListWrap, body], options);
|
package/src/functions/styling.ts
CHANGED
|
@@ -23,11 +23,10 @@ defineFunction({
|
|
|
23
23
|
"\\displaystyle", "\\textstyle", "\\scriptstyle",
|
|
24
24
|
"\\scriptscriptstyle",
|
|
25
25
|
],
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
26
|
+
numArgs: 0,
|
|
27
|
+
allowedInText: true,
|
|
28
|
+
primitive: true,
|
|
29
|
+
|
|
31
30
|
handler({breakOnTokenText, funcName, parser}, args) {
|
|
32
31
|
// parse out the implicit body
|
|
33
32
|
const body = parser.parseExpression(true, breakOnTokenText);
|
|
@@ -47,6 +46,7 @@ defineFunction({
|
|
|
47
46
|
body,
|
|
48
47
|
};
|
|
49
48
|
},
|
|
49
|
+
|
|
50
50
|
htmlBuilder(group, options) {
|
|
51
51
|
// Style changes are handled in the TeXbook on pg. 442, Rule 3.
|
|
52
52
|
const newStyle = styleMap[group.style];
|
package/src/functions/supsub.ts
CHANGED
|
@@ -14,7 +14,7 @@ import * as op from "./op";
|
|
|
14
14
|
import * as operatorname from "./operatorname";
|
|
15
15
|
|
|
16
16
|
import type Options from "../Options";
|
|
17
|
-
import type {ParseNode} from "../
|
|
17
|
+
import type {ParseNode} from "../types/nodes";
|
|
18
18
|
import type {HtmlBuilder} from "../defineFunction";
|
|
19
19
|
import type {MathNodeType} from "../mathMLTree";
|
|
20
20
|
|
|
@@ -4,7 +4,7 @@ import {MathNode} from "../mathMLTree";
|
|
|
4
4
|
|
|
5
5
|
import * as mml from "../buildMathML";
|
|
6
6
|
|
|
7
|
-
import type {ParseNode} from "../
|
|
7
|
+
import type {ParseNode} from "../types/nodes";
|
|
8
8
|
|
|
9
9
|
// "mathord" and "textord" ParseNodes created in Parser.js from symbol Groups in
|
|
10
10
|
// src/symbols.js.
|
|
@@ -18,7 +18,7 @@ const defaultVariant: Record<string, string> = {
|
|
|
18
18
|
defineFunctionBuilders({
|
|
19
19
|
type: "mathord",
|
|
20
20
|
htmlBuilder(group, options) {
|
|
21
|
-
return makeOrd(group, options
|
|
21
|
+
return makeOrd(group, options);
|
|
22
22
|
},
|
|
23
23
|
mathmlBuilder(group: ParseNode<"mathord">, options) {
|
|
24
24
|
const node = new MathNode(
|
|
@@ -36,7 +36,7 @@ defineFunctionBuilders({
|
|
|
36
36
|
defineFunctionBuilders({
|
|
37
37
|
type: "textord",
|
|
38
38
|
htmlBuilder(group, options) {
|
|
39
|
-
return makeOrd(group, options
|
|
39
|
+
return makeOrd(group, options);
|
|
40
40
|
},
|
|
41
41
|
mathmlBuilder(group: ParseNode<"textord">, options) {
|
|
42
42
|
const text = mml.makeText(group.text, group.mode, options);
|
|
@@ -4,40 +4,39 @@ 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.
|
|
39
38
|
if (group.mode === "text") {
|
|
40
|
-
const ord = makeOrd(group, options
|
|
39
|
+
const ord = makeOrd(group, options);
|
|
41
40
|
ord.classes.push(className);
|
|
42
41
|
return ord;
|
|
43
42
|
} else {
|
|
@@ -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/functions/text.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {makeSpan} from "../buildCommon";
|
|
|
5
5
|
import * as html from "../buildHTML";
|
|
6
6
|
import * as mml from "../buildMathML";
|
|
7
7
|
import type Options from "../Options";
|
|
8
|
-
import type {ParseNode} from "../
|
|
8
|
+
import type {ParseNode} from "../types/nodes";
|
|
9
9
|
|
|
10
10
|
// Non-mathy text, possibly in a font
|
|
11
11
|
const textFontFamilies: Record<string, TextFont | undefined> = {
|
|
@@ -54,12 +54,11 @@ defineFunction({
|
|
|
54
54
|
// Font Shapes
|
|
55
55
|
"\\textit", "\\textup", "\\emph",
|
|
56
56
|
],
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
57
|
+
numArgs: 1,
|
|
58
|
+
argTypes: ["text"],
|
|
59
|
+
allowedInArgument: true,
|
|
60
|
+
allowedInText: true,
|
|
61
|
+
|
|
63
62
|
handler({parser, funcName}, args) {
|
|
64
63
|
const body = args[0];
|
|
65
64
|
return {
|
|
@@ -69,6 +68,7 @@ defineFunction({
|
|
|
69
68
|
font: funcName,
|
|
70
69
|
};
|
|
71
70
|
},
|
|
71
|
+
|
|
72
72
|
htmlBuilder(group, options) {
|
|
73
73
|
const newOptions = optionsWithFont(group, options);
|
|
74
74
|
const inner = html.buildExpression(group.body, newOptions, true);
|
|
@@ -8,10 +8,9 @@ import * as mml from "../buildMathML";
|
|
|
8
8
|
defineFunction({
|
|
9
9
|
type: "underline",
|
|
10
10
|
names: ["\\underline"],
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
11
|
+
numArgs: 1,
|
|
12
|
+
allowedInText: true,
|
|
13
|
+
|
|
15
14
|
handler({parser}, args) {
|
|
16
15
|
return {
|
|
17
16
|
type: "underline",
|
|
@@ -19,6 +18,7 @@ defineFunction({
|
|
|
19
18
|
body: args[0],
|
|
20
19
|
};
|
|
21
20
|
},
|
|
21
|
+
|
|
22
22
|
htmlBuilder(group, options) {
|
|
23
23
|
// Underlines are handled in the TeXbook pg 443, Rule 10.
|
|
24
24
|
// Build the inner group.
|
|
@@ -40,7 +40,7 @@ defineFunction({
|
|
|
40
40
|
],
|
|
41
41
|
}, options);
|
|
42
42
|
|
|
43
|
-
return makeSpan(["mord", "underline"], [vlist], options);
|
|
43
|
+
return makeSpan(["mord", "katex-underline"], [vlist], options);
|
|
44
44
|
},
|
|
45
45
|
mathmlBuilder(group, options) {
|
|
46
46
|
const operator = new MathNode(
|
|
@@ -4,7 +4,7 @@ import {isCharacterBox} from "../../utils";
|
|
|
4
4
|
import type {StyleInterface} from "../../Style";
|
|
5
5
|
import type Options from "../../Options";
|
|
6
6
|
import type {DomSpan, SymbolNode} from "../../domTree";
|
|
7
|
-
import type {AnyParseNode} from "../../
|
|
7
|
+
import type {AnyParseNode} from "../../types/nodes";
|
|
8
8
|
import {makeEm} from "../../units";
|
|
9
9
|
|
|
10
10
|
// For an operator with limits, assemble the base, sup, and sub into a span.
|
package/src/functions/vcenter.ts
CHANGED
|
@@ -10,11 +10,10 @@ import * as mml from "../buildMathML";
|
|
|
10
10
|
defineFunction({
|
|
11
11
|
type: "vcenter",
|
|
12
12
|
names: ["\\vcenter"],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
13
|
+
numArgs: 1,
|
|
14
|
+
argTypes: ["original"], // In LaTeX, \vcenter can act only on a box.
|
|
15
|
+
allowedInText: false,
|
|
16
|
+
|
|
18
17
|
handler({parser}, args) {
|
|
19
18
|
return {
|
|
20
19
|
type: "vcenter",
|
|
@@ -22,6 +21,7 @@ defineFunction({
|
|
|
22
21
|
body: args[0],
|
|
23
22
|
};
|
|
24
23
|
},
|
|
24
|
+
|
|
25
25
|
htmlBuilder(group, options) {
|
|
26
26
|
const body = html.buildGroup(group.body, options);
|
|
27
27
|
const axisHeight = options.fontMetrics().axisHeight;
|
package/src/functions/verb.ts
CHANGED
|
@@ -3,15 +3,14 @@ import {makeSpan, makeSymbol, tryCombineChars} from "../buildCommon";
|
|
|
3
3
|
import {MathNode, TextNode} from "../mathMLTree";
|
|
4
4
|
import ParseError from "../ParseError";
|
|
5
5
|
|
|
6
|
-
import type {ParseNode} from "../
|
|
6
|
+
import type {ParseNode} from "../types/nodes";
|
|
7
7
|
|
|
8
8
|
defineFunction({
|
|
9
9
|
type: "verb",
|
|
10
10
|
names: ["\\verb"],
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
11
|
+
numArgs: 0,
|
|
12
|
+
allowedInText: true,
|
|
13
|
+
|
|
15
14
|
handler(context, args, optArgs) {
|
|
16
15
|
// \verb and \verb* are dealt with directly in Parser.js.
|
|
17
16
|
// If we end up here, it's because of a failure to match the two delimiters
|
|
@@ -20,6 +19,7 @@ defineFunction({
|
|
|
20
19
|
throw new ParseError(
|
|
21
20
|
"\\verb ended by end of line instead of matching delimiter");
|
|
22
21
|
},
|
|
22
|
+
|
|
23
23
|
htmlBuilder(group, options) {
|
|
24
24
|
const text = makeVerb(group);
|
|
25
25
|
const body = [];
|
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) {
|