forked from KaTeX/KaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lap.js
74 lines (68 loc) · 2.61 KB
/
lap.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
// @flow
// Horizontal overlap functions
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import {makeEm} from "../units";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "lap",
names: ["\\mathllap", "\\mathrlap", "\\mathclap"],
props: {
numArgs: 1,
allowedInText: true,
},
handler: ({parser, funcName}, args) => {
const body = args[0];
return {
type: "lap",
mode: parser.mode,
alignment: funcName.slice(5),
body,
};
},
htmlBuilder: (group, options) => {
// mathllap, mathrlap, mathclap
let inner;
if (group.alignment === "clap") {
// ref: https://www.math.lsu.edu/~aperlis/publications/mathclap/
inner = buildCommon.makeSpan(
[], [html.buildGroup(group.body, options)]);
// wrap, since CSS will center a .clap > .inner > span
inner = buildCommon.makeSpan(["inner"], [inner], options);
} else {
inner = buildCommon.makeSpan(
["inner"], [html.buildGroup(group.body, options)]);
}
const fix = buildCommon.makeSpan(["fix"], []);
let node = buildCommon.makeSpan(
[group.alignment], [inner, fix], options);
// At this point, we have correctly set horizontal alignment of the
// two items involved in the lap.
// Next, use a strut to set the height of the HTML bounding box.
// Otherwise, a tall argument may be misplaced.
// This code resolved issue #1153
const strut = buildCommon.makeSpan(["strut"]);
strut.style.height = makeEm(node.height + node.depth);
if (node.depth) {
strut.style.verticalAlign = makeEm(-node.depth);
}
node.children.unshift(strut);
// Next, prevent vertical misplacement when next to something tall.
// This code resolves issue #1234
node = buildCommon.makeSpan(["thinbox"], [node], options);
return buildCommon.makeSpan(["mord", "vbox"], [node], options);
},
mathmlBuilder: (group, options) => {
// mathllap, mathrlap, mathclap
const node = new mathMLTree.MathNode(
"mpadded", [mml.buildGroup(group.body, options)]);
if (group.alignment !== "rlap") {
const offset = (group.alignment === "llap" ? "-1" : "-0.5");
node.setAttribute("lspace", offset + "width");
}
node.setAttribute("width", "0px");
return node;
},
});