Improve MathML for \rule (#1912)

* MathML for \rule

* Pick up comments

* Update rule.js
This commit is contained in:
Ron Kok
2019-03-29 06:59:21 -07:00
committed by ylemkimon
parent 32b25cd5cf
commit e52f6859ec
2 changed files with 22 additions and 10 deletions

View File

@@ -22,7 +22,8 @@ const htmlBuilder = (group, options) => {
};
const mathmlBuilder = (group, options) => {
const inner = mml.buildExpression(group.body, options);
const inner = mml.buildExpression(group.body,
options.withColor(group.color));
const node = new mathMLTree.MathNode("mstyle", inner);

View File

@@ -30,13 +30,9 @@ defineFunction({
const rule = buildCommon.makeSpan(["mord", "rule"], [], options);
// Calculate the shift, width, and height of the rule, and account for units
let shift = 0;
if (group.shift) {
shift = calculateSize(group.shift, options);
}
const width = calculateSize(group.width, options);
const height = calculateSize(group.height, options);
const shift = (group.shift) ? calculateSize(group.shift, options) : 0;
// Style the rule to the right size
rule.style.borderRightWidth = width + "em";
@@ -55,10 +51,25 @@ defineFunction({
return rule;
},
mathmlBuilder(group, options) {
// TODO(emily): Figure out if there's an actual way to draw black boxes
// in MathML.
const node = new mathMLTree.MathNode("mrow");
const width = calculateSize(group.width, options);
const height = calculateSize(group.height, options);
const shift = (group.shift) ? calculateSize(group.shift, options) : 0;
const color = options.color && options.getColor() || "black";
return node;
const rule = new mathMLTree.MathNode("mspace");
rule.setAttribute("mathbackground", color);
rule.setAttribute("width", width + "em");
rule.setAttribute("height", height + "em");
const wrapper = new mathMLTree.MathNode("mpadded", [rule]);
if (shift >= 0) {
wrapper.setAttribute("height", "+" + shift + "em");
} else {
wrapper.setAttribute("height", shift + "em");
wrapper.setAttribute("depth", "+" + (-shift) + "em");
}
wrapper.setAttribute("voffset", shift + "em");
return wrapper;
},
});