UNPKG

1.74 kBJavaScriptView Raw
1// @flow
2import defineFunction, {ordargument} from "../defineFunction";
3import buildCommon from "../buildCommon";
4import mathMLTree from "../mathMLTree";
5import {assertNodeType} from "../parseNode";
6import {calculateSize} from "../units";
7
8import * as mml from "../buildMathML";
9import * as sizing from "./sizing";
10
11// Box manipulation
12defineFunction({
13 type: "raisebox",
14 names: ["\\raisebox"],
15 props: {
16 numArgs: 2,
17 argTypes: ["size", "text"],
18 allowedInText: true,
19 },
20 handler({parser}, args) {
21 const amount = assertNodeType(args[0], "size").value;
22 const body = args[1];
23 return {
24 type: "raisebox",
25 mode: parser.mode,
26 dy: amount,
27 body,
28 };
29 },
30 htmlBuilder(group, options) {
31 const text = {
32 type: "text",
33 mode: group.mode,
34 body: ordargument(group.body),
35 font: "mathrm", // simulate \textrm
36 };
37 const sizedText = {
38 type: "sizing",
39 mode: group.mode,
40 body: [text],
41 size: 6, // simulate \normalsize
42 };
43 const body = sizing.htmlBuilder(sizedText, options);
44 const dy = calculateSize(group.dy, options);
45 return buildCommon.makeVList({
46 positionType: "shift",
47 positionData: -dy,
48 children: [{type: "elem", elem: body}],
49 }, options);
50 },
51 mathmlBuilder(group, options) {
52 const node = new mathMLTree.MathNode(
53 "mpadded", [mml.buildGroup(group.body, options)]);
54 const dy = group.dy.number + group.dy.unit;
55 node.setAttribute("voffset", dy);
56 return node;
57 },
58});
59