forked from KaTeX/KaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phantom.js
113 lines (106 loc) · 3.12 KB
/
phantom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "phantom",
names: ["\\phantom"],
props: {
numArgs: 1,
allowedInText: true,
},
handler: ({parser}, args) => {
const body = args[0];
return {
type: "phantom",
mode: parser.mode,
body: ordargument(body),
};
},
htmlBuilder: (group, options) => {
const elements = html.buildExpression(
group.body,
options.withPhantom(),
false
);
// \phantom isn't supposed to affect the elements it contains.
// See "color" for more details.
return buildCommon.makeFragment(elements);
},
mathmlBuilder: (group, options) => {
const inner = mml.buildExpression(group.body, options);
return new mathMLTree.MathNode("mphantom", inner);
},
});
defineFunction({
type: "hphantom",
names: ["\\hphantom"],
props: {
numArgs: 1,
allowedInText: true,
},
handler: ({parser}, args) => {
const body = args[0];
return {
type: "hphantom",
mode: parser.mode,
body,
};
},
htmlBuilder: (group, options) => {
let node = buildCommon.makeSpan(
[], [html.buildGroup(group.body, options.withPhantom())]);
node.height = 0;
node.depth = 0;
if (node.children) {
for (let i = 0; i < node.children.length; i++) {
node.children[i].height = 0;
node.children[i].depth = 0;
}
}
// See smash for comment re: use of makeVList
node = buildCommon.makeVList({
positionType: "firstBaseline",
children: [{type: "elem", elem: node}],
}, options);
return node;
},
mathmlBuilder: (group, options) => {
const inner = mml.buildExpression(ordargument(group.body), options);
const node = new mathMLTree.MathNode("mphantom", inner);
node.setAttribute("height", "0px");
return node;
},
});
defineFunction({
type: "vphantom",
names: ["\\vphantom"],
props: {
numArgs: 1,
allowedInText: true,
},
handler: ({parser}, args) => {
const body = args[0];
return {
type: "vphantom",
mode: parser.mode,
body,
};
},
htmlBuilder: (group, options) => {
const inner = buildCommon.makeSpan(
["inner"],
[html.buildGroup(group.body, options.withPhantom())]);
const fix = buildCommon.makeSpan(["fix"], []);
return buildCommon.makeSpan(
["mord", "rlap"], [inner, fix], options);
},
mathmlBuilder: (group, options) => {
const inner = mml.buildExpression(ordargument(group.body), options);
const node = new mathMLTree.MathNode("mphantom", inner);
node.setAttribute("width", "0px");
return node;
},
});