diff --git a/src/ParseNode.js b/src/ParseNode.js index b865f29f..9e41460c 100644 --- a/src/ParseNode.js +++ b/src/ParseNode.js @@ -247,7 +247,7 @@ type ParseNodeTypes = { |}, "raisebox": {| type: "raisebox", - dy: ParseNode<*>, + dy: ParseNode<"size">, body: ParseNode<*>, value: ParseNode<*>[], |}, diff --git a/src/buildHTML.js b/src/buildHTML.js index f36915e0..805a4b04 100644 --- a/src/buildHTML.js +++ b/src/buildHTML.js @@ -12,7 +12,6 @@ import Style from "./Style"; import buildCommon from "./buildCommon"; import domTree from "./domTree"; -import { calculateSize } from "./units"; import utils from "./utils"; import stretchy from "./stretchy"; import {spacings, tightSpacings} from "./spacingData"; @@ -570,25 +569,6 @@ export const groupTypes = { return makeSpan(["mrel", "x-arrow"], [vlist], options); }, - - raisebox(group, options) { - const body = groupTypes.sizing({value: { - value: [{ - type: "text", - value: { - body: group.value.value, - font: "mathrm", // simulate \textrm - }, - }], - size: 6, // simulate \normalsize - }}, options); - const dy = calculateSize(group.value.dy.value, options); - return buildCommon.makeVList({ - positionType: "shift", - positionData: -dy, - children: [{type: "elem", elem: body}], - }, options); - }, }; /** diff --git a/src/buildMathML.js b/src/buildMathML.js index 7621419b..b1502802 100644 --- a/src/buildMathML.js +++ b/src/buildMathML.js @@ -304,14 +304,6 @@ groupTypes.xArrow = function(group, options) { return node; }; -groupTypes.raisebox = function(group, options) { - const node = new mathMLTree.MathNode( - "mpadded", [buildGroup(group.value.body, options)]); - const dy = group.value.dy.value.number + group.value.dy.value.unit; - node.setAttribute("voffset", dy); - return node; -}; - groupTypes.tag = function(group, options) { const table = new mathMLTree.MathNode("mtable", [ new mathMLTree.MathNode("mlabeledtr", [ diff --git a/src/functions.js b/src/functions.js index f431e3ed..84231662 100644 --- a/src/functions.js +++ b/src/functions.js @@ -2,7 +2,6 @@ /** Include this to ensure that all functions are defined. */ import { default as _defineFunction, - ordargument, _functions, } from "./defineFunction"; @@ -124,20 +123,7 @@ import "./functions/cr"; import "./functions/environment"; // Box manipulation -defineFunction("raisebox", ["\\raisebox"], { - numArgs: 2, - argTypes: ["size", "text"], - allowedInText: true, -}, function(context, args) { - const amount = args[0]; - const body = args[1]; - return { - type: "raisebox", - dy: amount, - body: body, - value: ordargument(body), - }; -}); +import "./functions/raisebox"; import "./functions/verb"; diff --git a/src/functions/raisebox.js b/src/functions/raisebox.js new file mode 100644 index 00000000..7182ed31 --- /dev/null +++ b/src/functions/raisebox.js @@ -0,0 +1,56 @@ +// @flow +import defineFunction, {ordargument} from "../defineFunction"; +import buildCommon from "../buildCommon"; +import mathMLTree from "../mathMLTree"; +import {assertNodeType} from "../ParseNode"; +import {calculateSize} from "../units"; + +import * as html from "../buildHTML"; +import * as mml from "../buildMathML"; + +// Box manipulation +defineFunction({ + type: "raisebox", + names: ["\\raisebox"], + props: { + numArgs: 2, + argTypes: ["size", "text"], + allowedInText: true, + }, + handler(context, args) { + const amount = assertNodeType(args[0], "size"); + const body = args[1]; + return { + type: "raisebox", + dy: amount, + body: body, + value: ordargument(body), + }; + }, + htmlBuilder(group, options) { + const body = html.groupTypes.sizing({value: { + value: [{ + type: "text", + value: { + body: group.value.value, + font: "mathrm", // simulate \textrm + }, + }], + size: 6, // simulate \normalsize + }}, options); + const dy = calculateSize(group.value.dy.value, options); + return buildCommon.makeVList({ + positionType: "shift", + positionData: -dy, + children: [{type: "elem", elem: body}], + }, options); + }, + mathmlBuilder(group, options) { + const node = new mathMLTree.MathNode( + "mpadded", [mml.buildGroup(group.value.body, options)]); + const dy = group.value.dy.value.number + group.value.dy.value.unit; + node.setAttribute("voffset", dy); + return node; + }, +}); +