mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 11:48:41 +00:00
fix: Correctly parse \ followed by whitespace (#2877)
* fix: Correctly parse \ followed by whitespace LaTeX parses `\` followed by whitespace including up to one newline as equivalent to `\ `. (With multiple newlines, you get paragraph breaks.) Fix #2860. * Improve comments * Avoid second RegExp match in control words * Document capturing groups Co-authored-by: Ron Kok <ronkok@comcast.net>
This commit is contained in:
@@ -678,7 +678,7 @@ describe("A text parser", function() {
|
||||
const noBraceTextExpression = r`\text x`;
|
||||
const nestedTextExpression =
|
||||
r`\text{a {b} \blue{c} \textcolor{#fff}{x} \llap{x}}`;
|
||||
const spaceTextExpression = r`\text{ a \ }`;
|
||||
const spaceTextExpression = r`\text{ a \ }`;
|
||||
const leadingSpaceTextExpression = r`\text {moo}`;
|
||||
const badTextExpression = r`\text{a b%}`;
|
||||
const badFunctionExpression = r`\text{\sqrt{x}}`;
|
||||
@@ -722,12 +722,17 @@ describe("A text parser", function() {
|
||||
const parse = getParsed(spaceTextExpression)[0];
|
||||
const group = parse.body;
|
||||
|
||||
expect(group.length).toEqual(4);
|
||||
expect(group[0].type).toEqual("spacing");
|
||||
expect(group[1].type).toEqual("textord");
|
||||
expect(group[2].type).toEqual("spacing");
|
||||
expect(group[3].type).toEqual("spacing");
|
||||
});
|
||||
|
||||
it("should handle backslash followed by newline", () => {
|
||||
expect("\\text{\\ \t\r \n \t\r }").toParseLike("\\text{\\ }");
|
||||
});
|
||||
|
||||
it("should accept math mode tokens after its argument", function() {
|
||||
expect(mathTokenAfterText).toParse();
|
||||
});
|
||||
|
Reference in New Issue
Block a user