mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-08 12:38:39 +00:00
Support \bmod, \pmod, \pod, and \mod.
This commit is contained in:
committed by
Kevin Barabash
parent
f742fbf9f2
commit
7c83021009
@@ -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) {
|
groupTypes.katex = function(group, options) {
|
||||||
// The KaTeX logo. The offsets for the K and a were chosen to look
|
// 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
|
// good, but the offsets for the T, E, and X were taken from the
|
||||||
|
@@ -348,6 +348,31 @@ groupTypes.op = function(group, options) {
|
|||||||
return node;
|
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) {
|
groupTypes.katex = function(group) {
|
||||||
var node = new mathMLTree.MathNode(
|
var node = new mathMLTree.MathNode(
|
||||||
"mtext", [new mathMLTree.TextNode("KaTeX")]);
|
"mtext", [new mathMLTree.TextNode("KaTeX")]);
|
||||||
|
@@ -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
|
// Extra data needed for the delimiter handler down below
|
||||||
var delimiterSizes = {
|
var delimiterSizes = {
|
||||||
"\\bigl" : {mclass: "mopen", size: 1},
|
"\\bigl" : {mclass: "mopen", size: 1},
|
||||||
|
@@ -105,9 +105,9 @@
|
|||||||
@ptperem: 10.0;
|
@ptperem: 10.0;
|
||||||
@nulldelimiterspace: 1.2em / @ptperem;
|
@nulldelimiterspace: 1.2em / @ptperem;
|
||||||
|
|
||||||
@thinspace: 0.16667em;
|
@thinspace: 0.16667em; // 3mu
|
||||||
@mediumspace: 0.22222em;
|
@mediumspace: 0.22222em; // 4mu
|
||||||
@thickspace: 0.27778em;
|
@thickspace: 0.27778em; // 5mu
|
||||||
|
|
||||||
// These spacings apply in textstyle and displaystyle.
|
// These spacings apply in textstyle and displaystyle.
|
||||||
.mord {
|
.mord {
|
||||||
@@ -300,6 +300,10 @@
|
|||||||
width: @thinspace;
|
width: @thinspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.negativemediumspace {
|
||||||
|
margin-left: -@mediumspace;
|
||||||
|
}
|
||||||
|
|
||||||
&.mediumspace {
|
&.mediumspace {
|
||||||
width: @mediumspace;
|
width: @mediumspace;
|
||||||
}
|
}
|
||||||
@@ -308,10 +312,22 @@
|
|||||||
width: @thickspace;
|
width: @thickspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.sixmuspace {
|
||||||
|
width: 0.333333em;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.eightmuspace {
|
||||||
|
width: 0.444444em;
|
||||||
|
}
|
||||||
|
|
||||||
&.enspace {
|
&.enspace {
|
||||||
width: 0.5em;
|
width: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.twelvemuspace {
|
||||||
|
width: 0.666667em;
|
||||||
|
}
|
||||||
|
|
||||||
&.quad {
|
&.quad {
|
||||||
width: 1em;
|
width: 1em;
|
||||||
}
|
}
|
||||||
|
BIN
test/screenshotter/images/Mod-chrome.png
Normal file
BIN
test/screenshotter/images/Mod-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
BIN
test/screenshotter/images/Mod-firefox.png
Normal file
BIN
test/screenshotter/images/Mod-firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
BIN
test/screenshotter/images/ModScript-chrome.png
Normal file
BIN
test/screenshotter/images/ModScript-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
test/screenshotter/images/ModScript-firefox.png
Normal file
BIN
test/screenshotter/images/ModScript-firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
@@ -92,6 +92,18 @@ MathRm: \mathrm{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
|||||||
MathSf: \mathsf{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
MathSf: \mathsf{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
||||||
MathScr: \mathscr{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
MathScr: \mathscr{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
||||||
MathTt: \mathtt{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
MathTt: \mathtt{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
||||||
|
Mod: |
|
||||||
|
\begin{array}{cc}
|
||||||
|
a \bmod 2 & b \pod 3 \\
|
||||||
|
c \pmod{4} & d \mod{56} \\
|
||||||
|
\displaystyle a\bmod 2 & \displaystyle b \pod 3 \\
|
||||||
|
\displaystyle c\pmod{4} & \displaystyle d \mod{56}
|
||||||
|
\end{array}
|
||||||
|
ModScript: |
|
||||||
|
\begin{array}{cc}
|
||||||
|
\scriptstyle a\bmod 2 & \scriptstyle b \pod 3 \\
|
||||||
|
\scriptstyle c\pmod{4} & \scriptstyle d \mod{56}
|
||||||
|
\end{array}
|
||||||
NegativeSpaceBetweenRel: A =\!= B
|
NegativeSpaceBetweenRel: A =\!= B
|
||||||
NestedFractions: |
|
NestedFractions: |
|
||||||
\dfrac{\frac{a}{b}}{\frac{c}{d}}\dfrac{\dfrac{a}{b}}
|
\dfrac{\frac{a}{b}}{\frac{c}{d}}\dfrac{\dfrac{a}{b}}
|
||||||
|
Reference in New Issue
Block a user