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/hbox.ts
CHANGED
|
@@ -13,12 +13,11 @@ import * as mml from "../buildMathML";
|
|
|
13
13
|
defineFunction({
|
|
14
14
|
type: "hbox",
|
|
15
15
|
names: ["\\hbox"],
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
16
|
+
numArgs: 1,
|
|
17
|
+
argTypes: ["text"],
|
|
18
|
+
allowedInText: true,
|
|
19
|
+
primitive: true,
|
|
20
|
+
|
|
22
21
|
handler({parser}, args) {
|
|
23
22
|
return {
|
|
24
23
|
type: "hbox",
|
|
@@ -26,6 +25,7 @@ defineFunction({
|
|
|
26
25
|
body: ordargument(args[0]),
|
|
27
26
|
};
|
|
28
27
|
},
|
|
28
|
+
|
|
29
29
|
htmlBuilder(group, options) {
|
|
30
30
|
const elements = html.buildExpression(group.body, options.withFont(''), false);
|
|
31
31
|
return makeFragment(elements);
|
|
@@ -9,7 +9,7 @@ import * as html from "../buildHTML";
|
|
|
9
9
|
import * as mml from "../buildMathML";
|
|
10
10
|
|
|
11
11
|
import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";
|
|
12
|
-
import type {ParseNode} from "../
|
|
12
|
+
import type {ParseNode} from "../types/nodes";
|
|
13
13
|
|
|
14
14
|
// NOTE: Unlike most `htmlBuilder`s, this one handles not only "horizBrace", but
|
|
15
15
|
// also "supsub" since an over/underbrace can affect super/subscripting.
|
|
@@ -117,9 +117,8 @@ const mathmlBuilder: MathMLBuilder<"horizBrace"> = (group, options) => {
|
|
|
117
117
|
defineFunction({
|
|
118
118
|
type: "horizBrace",
|
|
119
119
|
names: ["\\overbrace", "\\underbrace", "\\overbracket", "\\underbracket"],
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
},
|
|
120
|
+
numArgs: 1,
|
|
121
|
+
|
|
123
122
|
handler({parser, funcName}, args) {
|
|
124
123
|
return {
|
|
125
124
|
type: "horizBrace",
|
|
@@ -129,6 +128,7 @@ defineFunction({
|
|
|
129
128
|
base: args[0],
|
|
130
129
|
};
|
|
131
130
|
},
|
|
131
|
+
|
|
132
132
|
htmlBuilder,
|
|
133
133
|
mathmlBuilder,
|
|
134
134
|
});
|
package/src/functions/href.ts
CHANGED
|
@@ -5,16 +5,15 @@ import {MathNode} from "../mathMLTree";
|
|
|
5
5
|
|
|
6
6
|
import * as html from "../buildHTML";
|
|
7
7
|
import * as mml from "../buildMathML";
|
|
8
|
-
import type {ParseNode} from "../
|
|
8
|
+
import type {ParseNode} from "../types/nodes";
|
|
9
9
|
|
|
10
10
|
defineFunction({
|
|
11
11
|
type: "href",
|
|
12
12
|
names: ["\\href"],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
13
|
+
numArgs: 2,
|
|
14
|
+
argTypes: ["url", "original"],
|
|
15
|
+
allowedInText: true,
|
|
16
|
+
|
|
18
17
|
handler: ({parser}, args) => {
|
|
19
18
|
const body = args[1];
|
|
20
19
|
const href = assertNodeType(args[0], "url").url;
|
|
@@ -33,6 +32,7 @@ defineFunction({
|
|
|
33
32
|
body: ordargument(body),
|
|
34
33
|
};
|
|
35
34
|
},
|
|
35
|
+
|
|
36
36
|
htmlBuilder: (group, options) => {
|
|
37
37
|
const elements = html.buildExpression(group.body, options, false);
|
|
38
38
|
return makeAnchor(group.href, [], elements, options);
|
|
@@ -50,11 +50,10 @@ defineFunction({
|
|
|
50
50
|
defineFunction({
|
|
51
51
|
type: "href",
|
|
52
52
|
names: ["\\url"],
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
53
|
+
numArgs: 1,
|
|
54
|
+
argTypes: ["url"],
|
|
55
|
+
allowedInText: true,
|
|
56
|
+
|
|
58
57
|
handler: ({parser}, args) => {
|
|
59
58
|
const href = assertNodeType(args[0], "url").url;
|
|
60
59
|
|
package/src/functions/html.ts
CHANGED
|
@@ -10,11 +10,10 @@ import type {AnyTrustContext} from "../Settings";
|
|
|
10
10
|
defineFunction({
|
|
11
11
|
type: "html",
|
|
12
12
|
names: ["\\htmlClass", "\\htmlId", "\\htmlStyle", "\\htmlData"],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
13
|
+
numArgs: 2,
|
|
14
|
+
argTypes: ["raw", "original"],
|
|
15
|
+
allowedInText: true,
|
|
16
|
+
|
|
18
17
|
handler: ({parser, funcName, token}, args) => {
|
|
19
18
|
const value = assertNodeType(args[0], "raw").string;
|
|
20
19
|
const body = args[1];
|
|
@@ -83,6 +82,7 @@ defineFunction({
|
|
|
83
82
|
body: ordargument(body),
|
|
84
83
|
};
|
|
85
84
|
},
|
|
85
|
+
|
|
86
86
|
htmlBuilder: (group, options) => {
|
|
87
87
|
const elements = html.buildExpression(group.body, options, false);
|
|
88
88
|
|
|
@@ -92,9 +92,9 @@ defineFunction({
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
const span = makeSpan(classes, elements, options);
|
|
95
|
-
for (const attr
|
|
96
|
-
if (attr !== "class"
|
|
97
|
-
span.setAttribute(attr,
|
|
95
|
+
for (const [attr, value] of Object.entries(group.attributes)) {
|
|
96
|
+
if (attr !== "class") {
|
|
97
|
+
span.setAttribute(attr, value);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
return span;
|
|
@@ -7,11 +7,10 @@ import * as mml from "../buildMathML";
|
|
|
7
7
|
defineFunction({
|
|
8
8
|
type: "htmlmathml",
|
|
9
9
|
names: ["\\html@mathml"],
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
10
|
+
numArgs: 2,
|
|
11
|
+
allowedInArgument: true,
|
|
12
|
+
allowedInText: true,
|
|
13
|
+
|
|
15
14
|
handler: ({parser}, args) => {
|
|
16
15
|
return {
|
|
17
16
|
type: "htmlmathml",
|
|
@@ -20,6 +19,7 @@ defineFunction({
|
|
|
20
19
|
mathml: ordargument(args[1]),
|
|
21
20
|
};
|
|
22
21
|
},
|
|
22
|
+
|
|
23
23
|
htmlBuilder: (group, options) => {
|
|
24
24
|
const elements = html.buildExpression(
|
|
25
25
|
group.html,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import defineFunction from "../defineFunction";
|
|
2
|
-
import type {Measurement} from "../units";
|
|
3
2
|
import {calculateSize, validUnit, makeEm} from "../units";
|
|
4
3
|
import ParseError from "../ParseError";
|
|
5
4
|
import {Img} from "../domTree";
|
|
6
5
|
import {MathNode} from "../mathMLTree";
|
|
7
6
|
import {assertNodeType} from "../parseNode";
|
|
8
7
|
import type {CssStyle} from "../domTree";
|
|
8
|
+
import type {Measurement} from "../types";
|
|
9
9
|
|
|
10
10
|
const sizeData = function(str: string): Measurement {
|
|
11
11
|
if (/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(str)) {
|
|
@@ -33,12 +33,11 @@ const sizeData = function(str: string): Measurement {
|
|
|
33
33
|
defineFunction({
|
|
34
34
|
type: "includegraphics",
|
|
35
35
|
names: ["\\includegraphics"],
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
36
|
+
numArgs: 1,
|
|
37
|
+
numOptionalArgs: 1,
|
|
38
|
+
argTypes: ["raw", "url"],
|
|
39
|
+
allowedInText: false,
|
|
40
|
+
|
|
42
41
|
handler: ({parser}, args, optArgs) => {
|
|
43
42
|
let width = {number: 0, unit: "em"};
|
|
44
43
|
let height = {number: 0.9, unit: "em"}; // sorta character sized.
|
|
@@ -101,6 +100,7 @@ defineFunction({
|
|
|
101
100
|
src: src,
|
|
102
101
|
};
|
|
103
102
|
},
|
|
103
|
+
|
|
104
104
|
htmlBuilder: (group, options) => {
|
|
105
105
|
const height = calculateSize(group.height, options);
|
|
106
106
|
let depth = 0;
|
package/src/functions/kern.ts
CHANGED
|
@@ -11,12 +11,11 @@ import {assertNodeType} from "../parseNode";
|
|
|
11
11
|
defineFunction({
|
|
12
12
|
type: "kern",
|
|
13
13
|
names: ["\\kern", "\\mkern", "\\hskip", "\\mskip"],
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
14
|
+
numArgs: 1,
|
|
15
|
+
argTypes: ["size"],
|
|
16
|
+
primitive: true,
|
|
17
|
+
allowedInText: true,
|
|
18
|
+
|
|
20
19
|
handler({parser, funcName}, args) {
|
|
21
20
|
const size = assertNodeType(args[0], "size");
|
|
22
21
|
if (parser.settings.strict) {
|
|
@@ -45,6 +44,7 @@ defineFunction({
|
|
|
45
44
|
dimension: size.value,
|
|
46
45
|
};
|
|
47
46
|
},
|
|
47
|
+
|
|
48
48
|
htmlBuilder(group, options) {
|
|
49
49
|
return makeGlue(group.dimension, options);
|
|
50
50
|
},
|
package/src/functions/lap.ts
CHANGED
|
@@ -10,10 +10,9 @@ import * as mml from "../buildMathML";
|
|
|
10
10
|
defineFunction({
|
|
11
11
|
type: "lap",
|
|
12
12
|
names: ["\\mathllap", "\\mathrlap", "\\mathclap"],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
13
|
+
numArgs: 1,
|
|
14
|
+
allowedInText: true,
|
|
15
|
+
|
|
17
16
|
handler: ({parser, funcName}, args) => {
|
|
18
17
|
const body = args[0];
|
|
19
18
|
return {
|
|
@@ -23,6 +22,7 @@ defineFunction({
|
|
|
23
22
|
body,
|
|
24
23
|
};
|
|
25
24
|
},
|
|
25
|
+
|
|
26
26
|
htmlBuilder: (group, options) => {
|
|
27
27
|
// mathllap, mathrlap, mathclap
|
|
28
28
|
let inner;
|
|
@@ -30,13 +30,13 @@ defineFunction({
|
|
|
30
30
|
// ref: https://www.math.lsu.edu/~aperlis/publications/mathclap/
|
|
31
31
|
inner = makeSpan(
|
|
32
32
|
[], [html.buildGroup(group.body, options)]);
|
|
33
|
-
// wrap, since CSS will center a .clap > .inner > span
|
|
34
|
-
inner = makeSpan(["inner"], [inner], options);
|
|
33
|
+
// wrap, since CSS will center a .clap > .katex-inner > span
|
|
34
|
+
inner = makeSpan(["katex-inner"], [inner], options);
|
|
35
35
|
} else {
|
|
36
36
|
inner = makeSpan(
|
|
37
|
-
["inner"], [html.buildGroup(group.body, options)]);
|
|
37
|
+
["katex-inner"], [html.buildGroup(group.body, options)]);
|
|
38
38
|
}
|
|
39
|
-
const fix = makeSpan(["fix"], []);
|
|
39
|
+
const fix = makeSpan(["katex-fix"], []);
|
|
40
40
|
let node = makeSpan(
|
|
41
41
|
[group.alignment], [inner, fix], options);
|
|
42
42
|
|
|
@@ -45,7 +45,7 @@ defineFunction({
|
|
|
45
45
|
// Next, use a strut to set the height of the HTML bounding box.
|
|
46
46
|
// Otherwise, a tall argument may be misplaced.
|
|
47
47
|
// This code resolved issue #1153
|
|
48
|
-
const strut = makeSpan(["strut"]);
|
|
48
|
+
const strut = makeSpan(["katex-strut"]);
|
|
49
49
|
strut.style.height = makeEm(node.height + node.depth);
|
|
50
50
|
if (node.depth) {
|
|
51
51
|
strut.style.verticalAlign = makeEm(-node.depth);
|
|
@@ -54,8 +54,8 @@ defineFunction({
|
|
|
54
54
|
|
|
55
55
|
// Next, prevent vertical misplacement when next to something tall.
|
|
56
56
|
// This code resolves issue #1234
|
|
57
|
-
node = makeSpan(["thinbox"], [node], options);
|
|
58
|
-
return makeSpan(["mord", "vbox"], [node], options);
|
|
57
|
+
node = makeSpan(["katex-thinbox"], [node], options);
|
|
58
|
+
return makeSpan(["mord", "katex-vbox"], [node], options);
|
|
59
59
|
},
|
|
60
60
|
mathmlBuilder: (group, options) => {
|
|
61
61
|
// mathllap, mathrlap, mathclap
|
package/src/functions/math.ts
CHANGED
|
@@ -5,11 +5,10 @@ import ParseError from "../ParseError";
|
|
|
5
5
|
defineFunction({
|
|
6
6
|
type: "styling",
|
|
7
7
|
names: ["\\(", "$"],
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
8
|
+
numArgs: 0,
|
|
9
|
+
allowedInText: true,
|
|
10
|
+
allowedInMath: false,
|
|
11
|
+
|
|
13
12
|
handler({funcName, parser}, args) {
|
|
14
13
|
const outerMode = parser.mode;
|
|
15
14
|
parser.switchMode("math");
|
|
@@ -31,11 +30,10 @@ defineFunction({
|
|
|
31
30
|
defineFunction({
|
|
32
31
|
type: "text", // Doesn't matter what this is.
|
|
33
32
|
names: ["\\)", "\\]"],
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
},
|
|
33
|
+
numArgs: 0,
|
|
34
|
+
allowedInText: true,
|
|
35
|
+
allowedInMath: false,
|
|
36
|
+
|
|
39
37
|
handler(context, args) {
|
|
40
38
|
throw new ParseError(`Mismatched ${context.funcName}`);
|
|
41
39
|
},
|
|
@@ -6,7 +6,7 @@ import * as html from "../buildHTML";
|
|
|
6
6
|
import * as mml from "../buildMathML";
|
|
7
7
|
|
|
8
8
|
import type Options from "../Options";
|
|
9
|
-
import type {ParseNode} from "../
|
|
9
|
+
import type {ParseNode} from "../types/nodes";
|
|
10
10
|
|
|
11
11
|
const chooseMathStyle = (group: ParseNode<"mathchoice">, options: Options) => {
|
|
12
12
|
switch (options.style.size) {
|
|
@@ -21,10 +21,9 @@ const chooseMathStyle = (group: ParseNode<"mathchoice">, options: Options) => {
|
|
|
21
21
|
defineFunction({
|
|
22
22
|
type: "mathchoice",
|
|
23
23
|
names: ["\\mathchoice"],
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
24
|
+
numArgs: 4,
|
|
25
|
+
primitive: true,
|
|
26
|
+
|
|
28
27
|
handler: ({parser}, args) => {
|
|
29
28
|
return {
|
|
30
29
|
type: "mathchoice",
|
|
@@ -35,6 +34,7 @@ defineFunction({
|
|
|
35
34
|
scriptscript: ordargument(args[3]),
|
|
36
35
|
};
|
|
37
36
|
},
|
|
37
|
+
|
|
38
38
|
htmlBuilder: (group, options) => {
|
|
39
39
|
const body = chooseMathStyle(group, options);
|
|
40
40
|
const elements = html.buildExpression(
|
package/src/functions/mclass.ts
CHANGED
|
@@ -2,13 +2,13 @@ import defineFunction, {ordargument} from "../defineFunction";
|
|
|
2
2
|
import {makeSpan} from "../buildCommon";
|
|
3
3
|
import {isCharacterBox} from "../utils";
|
|
4
4
|
import {MathNode} from "../mathMLTree";
|
|
5
|
-
import type {AnyParseNode} from "../
|
|
5
|
+
import type {AnyParseNode, ParseNode} from "../types/nodes";
|
|
6
6
|
|
|
7
7
|
import * as html from "../buildHTML";
|
|
8
8
|
import * as mml from "../buildMathML";
|
|
9
9
|
|
|
10
10
|
import type Options from "../Options";
|
|
11
|
-
import type {
|
|
11
|
+
import type {MathClass, Slice5} from "../types";
|
|
12
12
|
|
|
13
13
|
function htmlBuilder(group: ParseNode<"mclass">, options: Options) {
|
|
14
14
|
const elements = html.buildExpression(group.body, options, true);
|
|
@@ -47,9 +47,6 @@ function mathmlBuilder(group: ParseNode<"mclass">, options: Options) {
|
|
|
47
47
|
} else if (group.mclass === "mopen" || group.mclass === "mclose") {
|
|
48
48
|
node.attributes.lspace = "0em";
|
|
49
49
|
node.attributes.rspace = "0em";
|
|
50
|
-
} else if (group.mclass === "minner") {
|
|
51
|
-
node.attributes.lspace = "0.0556em"; // 1 mu is the most likely option
|
|
52
|
-
node.attributes.width = "+0.1111em";
|
|
53
50
|
}
|
|
54
51
|
// MathML <mo> default space is 5/18 em, so <mrel> needs no action.
|
|
55
52
|
// Ref: https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo
|
|
@@ -64,32 +61,31 @@ defineFunction({
|
|
|
64
61
|
"\\mathord", "\\mathbin", "\\mathrel", "\\mathopen",
|
|
65
62
|
"\\mathclose", "\\mathpunct", "\\mathinner",
|
|
66
63
|
],
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
primitive: true,
|
|
70
|
-
},
|
|
64
|
+
numArgs: 1,
|
|
65
|
+
primitive: true,
|
|
71
66
|
handler({parser, funcName}, args) {
|
|
72
67
|
const body = args[0];
|
|
73
68
|
return {
|
|
74
69
|
type: "mclass",
|
|
75
70
|
mode: parser.mode,
|
|
76
|
-
mclass:
|
|
71
|
+
mclass: `m${funcName.slice(5) as Slice5<typeof funcName>}`,
|
|
77
72
|
body: ordargument(body),
|
|
78
73
|
isCharacterBox: isCharacterBox(body),
|
|
79
74
|
};
|
|
80
75
|
},
|
|
76
|
+
|
|
81
77
|
htmlBuilder,
|
|
82
78
|
mathmlBuilder,
|
|
83
79
|
});
|
|
84
80
|
|
|
85
|
-
export const binrelClass = (arg: AnyParseNode):
|
|
81
|
+
export const binrelClass = (arg: AnyParseNode): MathClass => {
|
|
86
82
|
// \binrel@ spacing varies with (bin|rel|ord) of the atom in the argument.
|
|
87
83
|
// (by rendering separately and with {}s before and after, and measuring
|
|
88
84
|
// the change in spacing). We'll do roughly the same by detecting the
|
|
89
85
|
// atom type directly.
|
|
90
86
|
const atom = (arg.type === "ordgroup" && arg.body.length ? arg.body[0] : arg);
|
|
91
87
|
if (atom.type === "atom" && (atom.family === "bin" || atom.family === "rel")) {
|
|
92
|
-
return
|
|
88
|
+
return `m${atom.family}`;
|
|
93
89
|
} else {
|
|
94
90
|
return "mord";
|
|
95
91
|
}
|
|
@@ -100,9 +96,8 @@ export const binrelClass = (arg: AnyParseNode): string => {
|
|
|
100
96
|
defineFunction({
|
|
101
97
|
type: "mclass",
|
|
102
98
|
names: ["\\@binrel"],
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
},
|
|
99
|
+
numArgs: 2,
|
|
100
|
+
|
|
106
101
|
handler({parser}, args) {
|
|
107
102
|
return {
|
|
108
103
|
type: "mclass",
|
|
@@ -118,14 +113,13 @@ defineFunction({
|
|
|
118
113
|
defineFunction({
|
|
119
114
|
type: "mclass",
|
|
120
115
|
names: ["\\stackrel", "\\overset", "\\underset"],
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
},
|
|
116
|
+
numArgs: 2,
|
|
117
|
+
|
|
124
118
|
handler({parser, funcName}, args) {
|
|
125
119
|
const baseArg = args[1];
|
|
126
120
|
const shiftedArg = args[0];
|
|
127
121
|
|
|
128
|
-
let mclass;
|
|
122
|
+
let mclass: MathClass;
|
|
129
123
|
if (funcName !== "\\stackrel") {
|
|
130
124
|
// LaTeX applies \binrel spacing to \overset and \underset.
|
|
131
125
|
mclass = binrelClass(baseArg);
|
|
@@ -144,13 +138,9 @@ defineFunction({
|
|
|
144
138
|
body: ordargument(baseArg),
|
|
145
139
|
};
|
|
146
140
|
|
|
147
|
-
const supsub: ParseNode<"supsub"> =
|
|
148
|
-
type: "supsub",
|
|
149
|
-
mode: shiftedArg.mode,
|
|
150
|
-
base: baseOp,
|
|
151
|
-
sup: funcName === "\\underset" ? null : shiftedArg,
|
|
152
|
-
sub: funcName === "\\underset" ? shiftedArg : null,
|
|
153
|
-
};
|
|
141
|
+
const supsub: ParseNode<"supsub"> = funcName === "\\underset"
|
|
142
|
+
? {type: "supsub", mode: shiftedArg.mode, base: baseOp, sub: shiftedArg}
|
|
143
|
+
: {type: "supsub", mode: shiftedArg.mode, base: baseOp, sup: shiftedArg};
|
|
154
144
|
|
|
155
145
|
return {
|
|
156
146
|
type: "mclass",
|
|
@@ -160,6 +150,4 @@ defineFunction({
|
|
|
160
150
|
isCharacterBox: isCharacterBox(supsub),
|
|
161
151
|
};
|
|
162
152
|
},
|
|
163
|
-
htmlBuilder,
|
|
164
|
-
mathmlBuilder,
|
|
165
153
|
});
|
package/src/functions/op.ts
CHANGED
|
@@ -12,7 +12,7 @@ import * as html from "../buildHTML";
|
|
|
12
12
|
import * as mml from "../buildMathML";
|
|
13
13
|
|
|
14
14
|
import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";
|
|
15
|
-
import type {ParseNode} from "../
|
|
15
|
+
import type {ParseNode} from "../types/nodes";
|
|
16
16
|
|
|
17
17
|
// Most operators have a large successor symbol, but these don't.
|
|
18
18
|
const noSuccessor = new Set([
|
|
@@ -200,11 +200,10 @@ defineFunction({
|
|
|
200
200
|
"\u2210", "\u2211", "\u22c0", "\u22c1", "\u22c2", "\u22c3", "\u2a00",
|
|
201
201
|
"\u2a01", "\u2a02", "\u2a04", "\u2a06",
|
|
202
202
|
],
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
},
|
|
203
|
+
numArgs: 0,
|
|
204
|
+
|
|
206
205
|
handler: ({parser, funcName}, args) => {
|
|
207
|
-
let fName = funcName;
|
|
206
|
+
let fName: string = funcName;
|
|
208
207
|
if (fName.length === 1) {
|
|
209
208
|
fName = singleCharBigOps[fName];
|
|
210
209
|
}
|
|
@@ -217,19 +216,17 @@ defineFunction({
|
|
|
217
216
|
name: fName,
|
|
218
217
|
};
|
|
219
218
|
},
|
|
219
|
+
|
|
220
220
|
htmlBuilder,
|
|
221
221
|
mathmlBuilder,
|
|
222
222
|
});
|
|
223
223
|
|
|
224
|
-
// Note: calling defineFunction with a type that's already been defined only
|
|
225
|
-
// works because the same htmlBuilder and mathmlBuilder are being used.
|
|
226
224
|
defineFunction({
|
|
227
225
|
type: "op",
|
|
228
226
|
names: ["\\mathop"],
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
},
|
|
227
|
+
numArgs: 1,
|
|
228
|
+
primitive: true,
|
|
229
|
+
|
|
233
230
|
handler: ({parser}, args) => {
|
|
234
231
|
const body = args[0];
|
|
235
232
|
return {
|
|
@@ -241,8 +238,6 @@ defineFunction({
|
|
|
241
238
|
body: ordargument(body),
|
|
242
239
|
};
|
|
243
240
|
},
|
|
244
|
-
htmlBuilder,
|
|
245
|
-
mathmlBuilder,
|
|
246
241
|
});
|
|
247
242
|
|
|
248
243
|
// There are 2 flags for operators; whether they produce limits in
|
|
@@ -267,9 +262,8 @@ defineFunction({
|
|
|
267
262
|
"\\hom", "\\ker", "\\lg", "\\ln", "\\log", "\\sec", "\\sin",
|
|
268
263
|
"\\sinh", "\\sh", "\\tan", "\\tanh", "\\tg", "\\th",
|
|
269
264
|
],
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
},
|
|
265
|
+
numArgs: 0,
|
|
266
|
+
|
|
273
267
|
handler({parser, funcName}) {
|
|
274
268
|
return {
|
|
275
269
|
type: "op",
|
|
@@ -280,8 +274,6 @@ defineFunction({
|
|
|
280
274
|
name: funcName,
|
|
281
275
|
};
|
|
282
276
|
},
|
|
283
|
-
htmlBuilder,
|
|
284
|
-
mathmlBuilder,
|
|
285
277
|
});
|
|
286
278
|
|
|
287
279
|
// Limits, not symbols
|
|
@@ -290,9 +282,8 @@ defineFunction({
|
|
|
290
282
|
names: [
|
|
291
283
|
"\\det", "\\gcd", "\\inf", "\\lim", "\\max", "\\min", "\\Pr", "\\sup",
|
|
292
284
|
],
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
},
|
|
285
|
+
numArgs: 0,
|
|
286
|
+
|
|
296
287
|
handler({parser, funcName}) {
|
|
297
288
|
return {
|
|
298
289
|
type: "op",
|
|
@@ -303,8 +294,6 @@ defineFunction({
|
|
|
303
294
|
name: funcName,
|
|
304
295
|
};
|
|
305
296
|
},
|
|
306
|
-
htmlBuilder,
|
|
307
|
-
mathmlBuilder,
|
|
308
297
|
});
|
|
309
298
|
|
|
310
299
|
// No limits, symbols
|
|
@@ -314,12 +303,11 @@ defineFunction({
|
|
|
314
303
|
"\\int", "\\iint", "\\iiint", "\\oint", "\\oiint", "\\oiiint",
|
|
315
304
|
"\u222b", "\u222c", "\u222d", "\u222e", "\u222f", "\u2230",
|
|
316
305
|
],
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
},
|
|
306
|
+
numArgs: 0,
|
|
307
|
+
allowedInArgument: true,
|
|
308
|
+
|
|
321
309
|
handler({parser, funcName}) {
|
|
322
|
-
let fName = funcName;
|
|
310
|
+
let fName: string = funcName;
|
|
323
311
|
if (fName.length === 1) {
|
|
324
312
|
fName = singleCharIntegrals[fName];
|
|
325
313
|
}
|
|
@@ -332,6 +320,4 @@ defineFunction({
|
|
|
332
320
|
name: fName,
|
|
333
321
|
};
|
|
334
322
|
},
|
|
335
|
-
htmlBuilder,
|
|
336
|
-
mathmlBuilder,
|
|
337
323
|
});
|
|
@@ -10,7 +10,7 @@ import * as html from "../buildHTML";
|
|
|
10
10
|
import * as mml from "../buildMathML";
|
|
11
11
|
|
|
12
12
|
import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";
|
|
13
|
-
import type {AnyParseNode, ParseNode} from "../
|
|
13
|
+
import type {AnyParseNode, ParseNode} from "../types/nodes";
|
|
14
14
|
|
|
15
15
|
// NOTE: Unlike most `htmlBuilder`s, this one handles not only
|
|
16
16
|
// "operatorname", but also "supsub" since \operatorname* can
|
|
@@ -139,9 +139,8 @@ const mathmlBuilder: MathMLBuilder<"operatorname"> = (group, options) => {
|
|
|
139
139
|
defineFunction({
|
|
140
140
|
type: "operatorname",
|
|
141
141
|
names: ["\\operatorname@", "\\operatornamewithlimits"],
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
},
|
|
142
|
+
numArgs: 1,
|
|
143
|
+
|
|
145
144
|
handler: ({parser, funcName}, args) => {
|
|
146
145
|
const body = args[0];
|
|
147
146
|
return {
|
|
@@ -153,6 +152,7 @@ defineFunction({
|
|
|
153
152
|
parentIsSupSub: false,
|
|
154
153
|
};
|
|
155
154
|
},
|
|
155
|
+
|
|
156
156
|
htmlBuilder,
|
|
157
157
|
mathmlBuilder,
|
|
158
158
|
});
|
|
@@ -8,9 +8,8 @@ import * as mml from "../buildMathML";
|
|
|
8
8
|
defineFunction({
|
|
9
9
|
type: "overline",
|
|
10
10
|
names: ["\\overline"],
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
11
|
+
numArgs: 1,
|
|
12
|
+
|
|
14
13
|
handler({parser}, args) {
|
|
15
14
|
const body = args[0];
|
|
16
15
|
return {
|
|
@@ -19,6 +18,7 @@ defineFunction({
|
|
|
19
18
|
body,
|
|
20
19
|
};
|
|
21
20
|
},
|
|
21
|
+
|
|
22
22
|
htmlBuilder(group, options) {
|
|
23
23
|
// Overlines are handled in the TeXbook pg 443, Rule 9.
|
|
24
24
|
|
|
@@ -41,7 +41,7 @@ defineFunction({
|
|
|
41
41
|
],
|
|
42
42
|
}, options);
|
|
43
43
|
|
|
44
|
-
return makeSpan(["mord", "overline"], [vlist], options);
|
|
44
|
+
return makeSpan(["mord", "katex-overline"], [vlist], options);
|
|
45
45
|
},
|
|
46
46
|
mathmlBuilder(group, options) {
|
|
47
47
|
const operator = new MathNode(
|