1 |
|
2 |
|
3 | import defineFunction from "../defineFunction";
|
4 | import buildCommon from "../buildCommon";
|
5 | import mathMLTree from "../mathMLTree";
|
6 |
|
7 | import * as html from "../buildHTML";
|
8 | import * as mml from "../buildMathML";
|
9 |
|
10 | defineFunction({
|
11 | type: "lap",
|
12 | names: ["\\mathllap", "\\mathrlap", "\\mathclap"],
|
13 | props: {
|
14 | numArgs: 1,
|
15 | allowedInText: true,
|
16 | },
|
17 | handler: ({parser, funcName}, args) => {
|
18 | const body = args[0];
|
19 | return {
|
20 | type: "lap",
|
21 | mode: parser.mode,
|
22 | alignment: funcName.slice(5),
|
23 | body,
|
24 | };
|
25 | },
|
26 | htmlBuilder: (group, options) => {
|
27 |
|
28 | let inner;
|
29 | if (group.alignment === "clap") {
|
30 |
|
31 | inner = buildCommon.makeSpan(
|
32 | [], [html.buildGroup(group.body, options)]);
|
33 |
|
34 | inner = buildCommon.makeSpan(["inner"], [inner], options);
|
35 | } else {
|
36 | inner = buildCommon.makeSpan(
|
37 | ["inner"], [html.buildGroup(group.body, options)]);
|
38 | }
|
39 | const fix = buildCommon.makeSpan(["fix"], []);
|
40 | let node = buildCommon.makeSpan(
|
41 | [group.alignment], [inner, fix], options);
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | const strut = buildCommon.makeSpan(["strut"]);
|
48 | strut.style.height = (node.height + node.depth) + "em";
|
49 | strut.style.verticalAlign = -node.depth + "em";
|
50 | node.children.unshift(strut);
|
51 |
|
52 |
|
53 | node = buildCommon.makeVList({
|
54 | positionType: "firstBaseline",
|
55 | children: [{type: "elem", elem: node}],
|
56 | }, options);
|
57 |
|
58 |
|
59 | return buildCommon.makeSpan(["mord"], [node], options);
|
60 | },
|
61 | mathmlBuilder: (group, options) => {
|
62 |
|
63 | const node = new mathMLTree.MathNode(
|
64 | "mpadded", [mml.buildGroup(group.body, options)]);
|
65 |
|
66 | if (group.alignment !== "rlap") {
|
67 | const offset = (group.alignment === "llap" ? "-1" : "-0.5");
|
68 | node.setAttribute("lspace", offset + "width");
|
69 | }
|
70 | node.setAttribute("width", "0px");
|
71 |
|
72 | return node;
|
73 | },
|
74 | });
|