mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 19:28:39 +00:00
Implements \mathchoice command (#969)
This PR implements `\mathchoice` function. I once created PR on the wrong branch. Sorry for the mess. This is particularly useful when one defines custom macro for "big operators". For example: ```latex \newcommand{\infdisj}{% \mathop{% \mathchoice{% display \bigvee\hspace{-2ex}\bigvee% }{ % inline \bigvee\hspace{-1.75ex}\bigvee% }{ % script \bigvee\hspace{-1.4ex}\bigvee% }{ % scriptscript \bigvee\hspace{-1ex}\bigvee% }}} ```
This commit is contained in:
committed by
Erik Demaine
parent
2d32263998
commit
6f1661f7da
@@ -2660,3 +2660,31 @@ describe("The maxSize setting", function() {
|
||||
expect(built.style.borderTopWidth).toEqual("0em");
|
||||
});
|
||||
});
|
||||
|
||||
describe("The \\mathchoice function", function() {
|
||||
const cmd = "\\sum_{k = 0}^{\\infty} x^k";
|
||||
|
||||
it("should render as if there is nothing other in display math", function() {
|
||||
const plain = getBuilt("\\displaystyle" + cmd)[0];
|
||||
const built = getBuilt(`\\displaystyle\\mathchoice{${cmd}}{T}{S}{SS}`)[0];
|
||||
expect(built).toEqual(plain);
|
||||
});
|
||||
|
||||
it("should render as if there is nothing other in text", function() {
|
||||
const plain = getBuilt(cmd)[0];
|
||||
const built = getBuilt(`\\mathchoice{D}{${cmd}}{S}{SS}`)[0];
|
||||
expect(built).toEqual(plain);
|
||||
});
|
||||
|
||||
it("should render as if there is nothing other in scriptstyle", function() {
|
||||
const plain = getBuilt(`x_{${cmd}}`)[0];
|
||||
const built = getBuilt(`x_{\\mathchoice{D}{T}{${cmd}}{SS}}`)[0];
|
||||
expect(built).toEqual(plain);
|
||||
});
|
||||
|
||||
it("should render as if there is nothing other in scriptscriptstyle", function() {
|
||||
const plain = getBuilt(`x_{y_{${cmd}}}`)[0];
|
||||
const built = getBuilt(`x_{y_{\\mathchoice{D}{T}{S}{${cmd}}}}`)[0];
|
||||
expect(built).toEqual(plain);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user