Improve MathML for fractions (#1882)

* Improve MathML for fractions

* Fix lint errors

* Revise arguments

* Reverting to previous arguments

* Revise arguments

* Pick up comment

* Change > to >=
This commit is contained in:
Ron Kok
2019-03-29 07:17:22 -07:00
committed by GitHub
parent e52f6859ec
commit 01a94d5f07

View File

@@ -11,24 +11,29 @@ import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import {calculateSize} from "../units";
const htmlBuilder = (group, options) => {
// Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
const adjustStyle = (size, originalStyle) => {
// Figure out what style this fraction should be in based on the
// function used
let style = options.style;
if (group.size === "display") {
let style = originalStyle;
if (size === "display") {
// Get display style as a default.
// If incoming style is sub/sup, use style.text() to get correct size.
style = style.id > 3 ? style.text() : Style.DISPLAY;
} else if (group.size === "text" &&
style = style.id >= Style.SCRIPT.id ? style.text() : Style.DISPLAY;
} else if (size === "text" &&
style.size === Style.DISPLAY.size) {
// We're in a \tfrac but incoming style is displaystyle, so:
style = Style.TEXT;
} else if (group.size === "script") {
} else if (size === "script") {
style = Style.SCRIPT;
} else if (group.size === "scriptscript") {
} else if (size === "scriptscript") {
style = Style.SCRIPTSCRIPT;
}
return style;
};
const htmlBuilder = (group, options) => {
// Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
const style = adjustStyle(group.size, options.style);
const nstyle = style.fracNum();
const dstyle = style.fracDen();
@@ -178,13 +183,21 @@ const htmlBuilder = (group, options) => {
};
const mathmlBuilder = (group, options) => {
const node = new mathMLTree.MathNode(
let node = new mathMLTree.MathNode(
"mfrac",
[
mml.buildGroup(group.numer, options),
mml.buildGroup(group.denom, options),
]);
const style = adjustStyle(group.size, options.style);
if (style.size !== options.style.size) {
node = new mathMLTree.MathNode("mstyle", [node]);
const isDisplay = (style.size === Style.DISPLAY.size) ? "true" : "false";
node.setAttribute("displaystyle", isDisplay);
node.setAttribute("scriptlevel", "0");
}
if (!group.hasBarLine) {
node.setAttribute("linethickness", "0px");
} else if (group.barSize) {