UNPKG

1.77 kBJavaScriptView Raw
1// @flow
2import defineFunction from "../defineFunction";
3import buildCommon from "../buildCommon";
4import mathMLTree from "../mathMLTree";
5
6import * as html from "../buildHTML";
7import * as mml from "../buildMathML";
8
9defineFunction({
10 type: "underline",
11 names: ["\\underline"],
12 props: {
13 numArgs: 1,
14 allowedInText: true,
15 },
16 handler({parser}, args) {
17 return {
18 type: "underline",
19 mode: parser.mode,
20 body: args[0],
21 };
22 },
23 htmlBuilder(group, options) {
24 // Underlines are handled in the TeXbook pg 443, Rule 10.
25 // Build the inner group.
26 const innerGroup = html.buildGroup(group.body, options);
27
28 // Create the line to go below the body
29 const line = buildCommon.makeLineSpan("underline-line", options);
30
31 // Generate the vlist, with the appropriate kerns
32 const vlist = buildCommon.makeVList({
33 positionType: "top",
34 positionData: innerGroup.height,
35 children: [
36 {type: "kern", size: line.height},
37 {type: "elem", elem: line},
38 {type: "kern", size: 3 * line.height},
39 {type: "elem", elem: innerGroup},
40 ],
41 }, options);
42
43 return buildCommon.makeSpan(["mord", "underline"], [vlist], options);
44 },
45 mathmlBuilder(group, options) {
46 const operator = new mathMLTree.MathNode(
47 "mo", [new mathMLTree.TextNode("\u203e")]);
48 operator.setAttribute("stretchy", "true");
49
50 const node = new mathMLTree.MathNode(
51 "munder",
52 [mml.buildGroup(group.body, options), operator]);
53 node.setAttribute("accentunder", "true");
54
55 return node;
56 },
57});