Migrate genfrac, lap, smash, op, mod, and katex into their own files in src/functions (#871)

Fixes #869
This commit is contained in:
Kevin Barabash
2017-11-11 17:45:44 -05:00
committed by GitHub
parent 25db6095a1
commit 632f5af1c3
10 changed files with 859 additions and 752 deletions

View File

@@ -247,49 +247,6 @@ groupTypes.supsub = function(group, options) {
return node;
};
groupTypes.genfrac = function(group, options) {
const node = new mathMLTree.MathNode(
"mfrac",
[
buildGroup(group.value.numer, options),
buildGroup(group.value.denom, options),
]);
if (!group.value.hasBarLine) {
node.setAttribute("linethickness", "0px");
}
if (group.value.leftDelim != null || group.value.rightDelim != null) {
const withDelims = [];
if (group.value.leftDelim != null) {
const leftOp = new mathMLTree.MathNode(
"mo", [new mathMLTree.TextNode(group.value.leftDelim)]);
leftOp.setAttribute("fence", "true");
withDelims.push(leftOp);
}
withDelims.push(node);
if (group.value.rightDelim != null) {
const rightOp = new mathMLTree.MathNode(
"mo", [new mathMLTree.TextNode(group.value.rightDelim)]);
rightOp.setAttribute("fence", "true");
withDelims.push(rightOp);
}
const outerNode = new mathMLTree.MathNode("mrow", withDelims);
return outerNode;
}
return node;
};
groupTypes.sqrt = function(group, options) {
let node;
if (group.value.index) {
@@ -341,66 +298,6 @@ groupTypes.spacing = function(group) {
return node;
};
groupTypes.op = function(group, options) {
let node;
// TODO(emily): handle big operators using the `largeop` attribute
if (group.value.symbol) {
// This is a symbol. Just add the symbol.
node = new mathMLTree.MathNode(
"mo", [makeText(group.value.body, group.mode)]);
} else if (group.value.value) {
// This is an operator with children. Add them.
node = new mathMLTree.MathNode(
"mo", buildExpression(group.value.value, options));
} else {
// This is a text operator. Add all of the characters from the
// operator's name.
// TODO(emily): Add a space in the middle of some of these
// operators, like \limsup.
node = new mathMLTree.MathNode(
"mi", [new mathMLTree.TextNode(group.value.body.slice(1))]);
// TODO(ron): Append an <mo>&ApplyFunction;</mo> as in \operatorname
// ref: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.2
}
return node;
};
groupTypes.mod = function(group, options) {
let inner = [];
if (group.value.modType === "pod" || group.value.modType === "pmod") {
inner.push(new mathMLTree.MathNode(
"mo", [makeText("(", group.mode)]));
}
if (group.value.modType !== "pod") {
inner.push(new mathMLTree.MathNode(
"mo", [makeText("mod", group.mode)]));
}
if (group.value.value) {
const space = new mathMLTree.MathNode("mspace");
space.setAttribute("width", "0.333333em");
inner.push(space);
inner = inner.concat(buildExpression(group.value.value, options));
}
if (group.value.modType === "pod" || group.value.modType === "pmod") {
inner.push(new mathMLTree.MathNode(
"mo", [makeText(")", group.mode)]));
}
return new mathMLTree.MathNode("mo", inner);
};
groupTypes.katex = function(group) {
const node = new mathMLTree.MathNode(
"mtext", [new mathMLTree.TextNode("KaTeX")]);
return node;
};
groupTypes.font = function(group, options) {
const font = group.value.font;
return buildGroup(group.value.body, options.withFont(font));
@@ -578,35 +475,6 @@ groupTypes.kern = function(group) {
return node;
};
groupTypes.lap = function(group, options) {
// mathllap, mathrlap, mathclap
const node = new mathMLTree.MathNode(
"mpadded", [buildGroup(group.value.body, options)]);
if (group.value.alignment !== "rlap") {
const offset = (group.value.alignment === "llap" ? "-1" : "-0.5");
node.setAttribute("lspace", offset + "width");
}
node.setAttribute("width", "0px");
return node;
};
groupTypes.smash = function(group, options) {
const node = new mathMLTree.MathNode(
"mpadded", [buildGroup(group.value.body, options)]);
if (group.value.smashHeight) {
node.setAttribute("height", "0px");
}
if (group.value.smashDepth) {
node.setAttribute("depth", "0px");
}
return node;
};
groupTypes.mclass = function(group, options) {
const inner = buildExpression(group.value.value, options);
return new mathMLTree.MathNode("mstyle", inner);