From a358c5a94c86a13bd3381334c9ad4ca23cd57781 Mon Sep 17 00:00:00 2001 From: Ron Kok Date: Wed, 13 Sep 2017 18:29:09 -0700 Subject: [PATCH] Use mpadded for \raisebox MathML (#876) * Use mpadded for \raisebox MathML * Add MathML snapshot --- src/buildHTML.js | 2 +- src/buildMathML.js | 10 +++++++--- src/functions.js | 3 ++- test/__snapshots__/mathml-spec.js.snap | 21 +++++++++++++++++++++ test/mathml-spec.js | 4 ++++ 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/buildHTML.js b/src/buildHTML.js index 5bd163fd..631f5f19 100644 --- a/src/buildHTML.js +++ b/src/buildHTML.js @@ -1640,7 +1640,7 @@ groupTypes.raisebox = function(group, options) { value: [{ type: "text", value: { - body: group.value.body, + body: group.value.value, font: "mathrm", // simulate \textrm }, }], diff --git a/src/buildMathML.js b/src/buildMathML.js index 5b27200a..c2607b13 100644 --- a/src/buildMathML.js +++ b/src/buildMathML.js @@ -604,9 +604,13 @@ groupTypes.mclass = function(group, options) { return new mathMLTree.MathNode("mstyle", inner); }; -// Transforms (translation/rotation) don't seem to have a representation -// in MathML, so just treat them like \text{...} -groupTypes.raisebox = groupTypes.text; +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; +}; /** * Takes a list of nodes, builds them, and returns a list of the generated diff --git a/src/functions.js b/src/functions.js index 4545070f..91c6a542 100644 --- a/src/functions.js +++ b/src/functions.js @@ -673,6 +673,7 @@ defineFunction(["\\raisebox"], { return { type: "raisebox", dy: amount, - body: ordargument(body), + body: body, + value: ordargument(body), }; }); diff --git a/test/__snapshots__/mathml-spec.js.snap b/test/__snapshots__/mathml-spec.js.snap index de5a4589..2b52ca14 100644 --- a/test/__snapshots__/mathml-spec.js.snap +++ b/test/__snapshots__/mathml-spec.js.snap @@ -74,6 +74,27 @@ exports[`A MathML builder should make prime operators into nodes 1`] = ` `; +exports[`A MathML builder should use for raisebox 1`] = ` + + + + + + + + b + + + + + + \\raisebox{0.25em}{b} + + + + +`; + exports[`A MathML builder should use for regular operators 1`] = ` diff --git a/test/mathml-spec.js b/test/mathml-spec.js index d9e00b91..6565c099 100644 --- a/test/mathml-spec.js +++ b/test/mathml-spec.js @@ -50,4 +50,8 @@ describe("A MathML builder", function() { it('should use for regular operators', () => { expect(getMathML("\\textstyle\\sum_a^b")).toMatchSnapshot(); }); + + it('should use for raisebox', () => { + expect(getMathML("\\raisebox{0.25em}{b}")).toMatchSnapshot(); + }); });