mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-11 05:58:40 +00:00
Improve MathML for \rule (#1912)
* MathML for \rule * Pick up comments * Update rule.js
This commit is contained in:
@@ -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);
|
||||
|
||||
|
@@ -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;
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user