UNPKG

1.76 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: "overline",
11 names: ["\\overline"],
12 props: {
13 numArgs: 1,
14 },
15 handler({parser}, args) {
16 const body = args[0];
17 return {
18 type: "overline",
19 mode: parser.mode,
20 body,
21 };
22 },
23 htmlBuilder(group, options) {
24 // Overlines are handled in the TeXbook pg 443, Rule 9.
25
26 // Build the inner group in the cramped style.
27 const innerGroup = html.buildGroup(group.body,
28 options.havingCrampedStyle());
29
30 // Create the line above the body
31 const line = buildCommon.makeLineSpan("overline-line", options);
32
33 // Generate the vlist, with the appropriate kerns
34 const vlist = buildCommon.makeVList({
35 positionType: "firstBaseline",
36 children: [
37 {type: "elem", elem: innerGroup},
38 {type: "kern", size: 3 * line.height},
39 {type: "elem", elem: line},
40 {type: "kern", size: line.height},
41 ],
42 }, options);
43
44 return buildCommon.makeSpan(["mord", "overline"], [vlist], options);
45 },
46 mathmlBuilder(group, options) {
47 const operator = new mathMLTree.MathNode(
48 "mo", [new mathMLTree.TextNode("\u203e")]);
49 operator.setAttribute("stretchy", "true");
50
51 const node = new mathMLTree.MathNode(
52 "mover",
53 [mml.buildGroup(group.body, options), operator]);
54 node.setAttribute("accent", "true");
55
56 return node;
57 },
58});