forked from KaTeX/KaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
accentunder.js
60 lines (54 loc) · 1.88 KB
/
accentunder.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
// @flow
// Horizontal overlap functions
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import stretchy from "../stretchy";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type {ParseNode} from "../parseNode";
defineFunction({
type: "accentUnder",
names: [
"\\underleftarrow", "\\underrightarrow", "\\underleftrightarrow",
"\\undergroup", "\\underlinesegment", "\\utilde",
],
props: {
numArgs: 1,
},
handler: ({parser, funcName}, args) => {
const base = args[0];
return {
type: "accentUnder",
mode: parser.mode,
label: funcName,
base: base,
};
},
htmlBuilder: (group: ParseNode<"accentUnder">, options) => {
// Treat under accents much like underlines.
const innerGroup = html.buildGroup(group.base, options);
const accentBody = stretchy.svgSpan(group, options);
const kern = group.label === "\\utilde" ? 0.12 : 0;
// Generate the vlist, with the appropriate kerns
const vlist = buildCommon.makeVList({
positionType: "top",
positionData: innerGroup.height,
children: [
{type: "elem", elem: accentBody, wrapperClasses: ["svg-align"]},
{type: "kern", size: kern},
{type: "elem", elem: innerGroup},
],
}, options);
return buildCommon.makeSpan(["mord", "accentunder"], [vlist], options);
},
mathmlBuilder: (group, options) => {
const accentNode = stretchy.mathMLnode(group.label);
const node = new mathMLTree.MathNode(
"munder",
[mml.buildGroup(group.base, options), accentNode]
);
node.setAttribute("accentunder", "true");
return node;
},
});