mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 19:28:39 +00:00
fix: space should prevent optional argument to \\ (#3746)
Fix `src/functions/cr.js`'s definition of `\\` to manually look for an optional argument via `future()` instead of `numOptionalArgs`, so that it does *not* skip over spaces. This matches the existing behavior of `\\` in `src/environments/array.js` and AMSMath's behavior of `\math@cr` via `\new@ifnextchar`. Fixes #3745 Co-authored-by: Ron Kok <ronkok@comcast.net>
This commit is contained in:
@@ -13,13 +13,13 @@ defineFunction({
|
|||||||
names: ["\\\\"],
|
names: ["\\\\"],
|
||||||
props: {
|
props: {
|
||||||
numArgs: 0,
|
numArgs: 0,
|
||||||
numOptionalArgs: 1,
|
numOptionalArgs: 0,
|
||||||
argTypes: ["size"],
|
|
||||||
allowedInText: true,
|
allowedInText: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
handler({parser}, args, optArgs) {
|
handler({parser}, args, optArgs) {
|
||||||
const size = optArgs[0];
|
const size = parser.gullet.future().text === "[" ?
|
||||||
|
parser.parseSizeGroup(true) : null;
|
||||||
const newLine = !parser.settings.displayMode ||
|
const newLine = !parser.settings.displayMode ||
|
||||||
!parser.settings.useStrictBehavior(
|
!parser.settings.useStrictBehavior(
|
||||||
"newLineInDisplayMode", "In LaTeX, \\\\ or \\newline " +
|
"newLineInDisplayMode", "In LaTeX, \\\\ or \\newline " +
|
||||||
|
@@ -1309,6 +1309,11 @@ describe("A begin/end parser", function() {
|
|||||||
expect`\begin{matrix}a&b\cr[c]&d\end{matrix}`.toParse();
|
expect`\begin{matrix}a&b\cr[c]&d\end{matrix}`.toParse();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not treat [ after space as optional argument to \\\\", function() {
|
||||||
|
expect`\begin{matrix}a&b\\ [c]&d\end{matrix}`.toParse();
|
||||||
|
expect`a\\ [b]`.toParse();
|
||||||
|
});
|
||||||
|
|
||||||
it("should eat a final newline", function() {
|
it("should eat a final newline", function() {
|
||||||
const m3 = getParsed`\begin{matrix}a&b\\ c&d \\ \end{matrix}`[0];
|
const m3 = getParsed`\begin{matrix}a&b\\ c&d \\ \end{matrix}`[0];
|
||||||
expect(m3.body).toHaveLength(2);
|
expect(m3.body).toHaveLength(2);
|
||||||
|
Reference in New Issue
Block a user