Support \bmod, \pmod, \pod, and \mod.

This commit is contained in:
Eddie Kohler
2016-12-08 16:09:13 -05:00
committed by Kevin Barabash
parent f742fbf9f2
commit 7c83021009
9 changed files with 131 additions and 3 deletions

View File

@@ -915,6 +915,59 @@ groupTypes.op = function(group, options) {
}
};
groupTypes.mod = function(group, options) {
var inner = [];
if (group.value.modType === "bmod") {
// “\nonscript\mskip-\medmuskip\mkern5mu”
if (!options.style.isTight()) {
inner.push(makeSpan(
["mspace", "negativemediumspace"], [], options));
}
inner.push(makeSpan(["mspace", "thickspace"], [], options));
} else if (options.style.size === Style.DISPLAY.size) {
inner.push(makeSpan(["mspace", "quad"], [], options));
} else if (group.value.modType === "mod") {
inner.push(makeSpan(["mspace", "twelvemuspace"], [], options));
} else {
inner.push(makeSpan(["mspace", "eightmuspace"], [], options));
}
if (group.value.modType === "pod" || group.value.modType === "pmod") {
inner.push(buildCommon.mathsym("(", group.mode));
}
if (group.value.modType !== "pod") {
var modInner = [
buildCommon.mathsym("m", group.mode),
buildCommon.mathsym("o", group.mode),
buildCommon.mathsym("d", group.mode)];
if (group.value.modType === "bmod") {
inner.push(makeSpan(["mbin"], modInner, options));
// “\mkern5mu\nonscript\mskip-\medmuskip”
inner.push(makeSpan(["mspace", "thickspace"], [], options));
if (!options.style.isTight()) {
inner.push(makeSpan(
["mspace", "negativemediumspace"], [], options));
}
} else {
Array.prototype.push.apply(inner, modInner);
inner.push(makeSpan(["mspace", "sixmuspace"], [], options));
}
}
if (group.value.value) {
Array.prototype.push.apply(inner,
buildExpression(group.value.value, options, false));
}
if (group.value.modType === "pod" || group.value.modType === "pmod") {
inner.push(buildCommon.mathsym(")", group.mode));
}
return buildCommon.makeFragment(inner);
};
groupTypes.katex = function(group, options) {
// The KaTeX logo. The offsets for the K and a were chosen to look
// good, but the offsets for the T, E, and X were taken from the

View File

@@ -348,6 +348,31 @@ groupTypes.op = function(group, options) {
return node;
};
groupTypes.mod = function(group, options) {
var 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) {
var 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) {
var node = new mathMLTree.MathNode(
"mtext", [new mathMLTree.TextNode("KaTeX")]);

View File

@@ -279,6 +279,28 @@ defineFunction("\\stackrel", {
};
});
// \mod-type functions
defineFunction("\\bmod", {
numArgs: 0,
}, function(context, args) {
return {
type: "mod",
modType: "bmod",
value: null,
};
});
defineFunction(["\\pod", "\\pmod", "\\mod"], {
numArgs: 1,
}, function(context, args) {
var body = args[0];
return {
type: "mod",
modType: context.funcName.substr(1),
value: ordargument(body),
};
});
// Extra data needed for the delimiter handler down below
var delimiterSizes = {
"\\bigl" : {mclass: "mopen", size: 1},