UNPKG

1.94 kBJavaScriptView Raw
1// @flow
2// Horizontal overlap functions
3import defineFunction from "../defineFunction";
4import buildCommon from "../buildCommon";
5import mathMLTree from "../mathMLTree";
6import stretchy from "../stretchy";
7
8import * as html from "../buildHTML";
9import * as mml from "../buildMathML";
10
11import type {ParseNode} from "../parseNode";
12
13defineFunction({
14 type: "accentUnder",
15 names: [
16 "\\underleftarrow", "\\underrightarrow", "\\underleftrightarrow",
17 "\\undergroup", "\\underlinesegment", "\\utilde",
18 ],
19 props: {
20 numArgs: 1,
21 },
22 handler: ({parser, funcName}, args) => {
23 const base = args[0];
24 return {
25 type: "accentUnder",
26 mode: parser.mode,
27 label: funcName,
28 base: base,
29 };
30 },
31 htmlBuilder: (group: ParseNode<"accentUnder">, options) => {
32 // Treat under accents much like underlines.
33 const innerGroup = html.buildGroup(group.base, options);
34
35 const accentBody = stretchy.svgSpan(group, options);
36 const kern = group.label === "\\utilde" ? 0.12 : 0;
37
38 // Generate the vlist, with the appropriate kerns
39 const vlist = buildCommon.makeVList({
40 positionType: "bottom",
41 positionData: accentBody.height + kern,
42 children: [
43 {type: "elem", elem: accentBody, wrapperClasses: ["svg-align"]},
44 {type: "kern", size: kern},
45 {type: "elem", elem: innerGroup},
46 ],
47 }, options);
48
49 return buildCommon.makeSpan(["mord", "accentunder"], [vlist], options);
50 },
51 mathmlBuilder: (group, options) => {
52 const accentNode = stretchy.mathMLnode(group.label);
53 const node = new mathMLTree.MathNode(
54 "munder",
55 [mml.buildGroup(group.base, options), accentNode]
56 );
57 node.setAttribute("accentunder", "true");
58 return node;
59 },
60});