Move "raisebox" into functions/raisebox.js. (#1331)

This commit is contained in:
Ashish Myles
2018-05-19 21:53:51 -04:00
committed by Kevin Barabash
parent ea7003ff6e
commit 35d6181a95
5 changed files with 58 additions and 44 deletions

View File

@@ -247,7 +247,7 @@ type ParseNodeTypes = {
|},
"raisebox": {|
type: "raisebox",
dy: ParseNode<*>,
dy: ParseNode<"size">,
body: ParseNode<*>,
value: ParseNode<*>[],
|},

View File

@@ -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);
},
};
/**

View File

@@ -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", [

View File

@@ -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";

56
src/functions/raisebox.js Normal file
View File

@@ -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;
},
});