Skip to content

Commit 3e34453

Browse files
ronkokk4b7
authored andcommitted
Fix #946 (#949)
* Fix #946 Issue #946 identified a case in which `array.js` ate the final row of a well-written `aligned` environment. This PR modifies code from PR #479 to fix this problem and to also continue to eat a trailing `\\` submitted to any environment. * Fix bug and add tests * Add final newline to test. Doh!
1 parent 991bfd5 commit 3e34453

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/environments/array.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ function parseArray(
6262
} else if (next === "\\end") {
6363
// Arrays terminate newlines with `\crcr` which consumes a `\cr` if
6464
// the last line is empty.
65-
const lastRow = body[body.length - 1][0].value;
65+
const lastRow = body[body.length - 1];
6666
if (body.length > 1
67-
&& lastRow.value.length === 1
68-
&& lastRow.value[0].value.length === 0) {
67+
&& lastRow.length === 1
68+
&& lastRow[0].value.value[0].value.length === 0) {
6969
body.pop();
7070
}
7171
break;

test/katex-spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,11 @@ describe("A begin/end parser", function() {
12511251
it("should allow \\cr as a line terminator", function() {
12521252
expect("\\begin{matrix}a&b\\cr c&d\\end{matrix}").toParse();
12531253
});
1254+
1255+
it("should eat a final newline", function() {
1256+
const m3 = getParsed("\\begin{matrix}a&b\\\\ c&d \\\\ \\end{matrix}")[0];
1257+
expect(m3.value.body.length).toBe(2);
1258+
});
12541259
});
12551260

12561261
describe("A sqrt parser", function() {
@@ -2409,6 +2414,10 @@ describe("An aligned environment", function() {
24092414
.toNotParse();
24102415
});
24112416

2417+
it("should not eat the last row when its first cell is empty", function() {
2418+
const ae = getParsed("\\begin{aligned}&E_1 & (1)\\\\&E_2 & (2)\\\\E_3 & (3)\\end{aligned}")[0];
2419+
expect(ae.value.body.length).toBe(3);
2420+
});
24122421
});
24132422

24142423
describe("A parser that does not throw on unsupported commands", function() {

0 commit comments

Comments
 (0)