diff --git a/src/environments/array.js b/src/environments/array.js index 62d74696..679246e7 100644 --- a/src/environments/array.js +++ b/src/environments/array.js @@ -62,10 +62,10 @@ function parseArray( } else if (next === "\\end") { // Arrays terminate newlines with `\crcr` which consumes a `\cr` if // the last line is empty. - const lastRow = body[body.length - 1][0].value; + const lastRow = body[body.length - 1]; if (body.length > 1 - && lastRow.value.length === 1 - && lastRow.value[0].value.length === 0) { + && lastRow.length === 1 + && lastRow[0].value.value[0].value.length === 0) { body.pop(); } break; diff --git a/test/katex-spec.js b/test/katex-spec.js index 0e5ec5cd..77aaeaa0 100644 --- a/test/katex-spec.js +++ b/test/katex-spec.js @@ -1251,6 +1251,11 @@ describe("A begin/end parser", function() { it("should allow \\cr as a line terminator", function() { expect("\\begin{matrix}a&b\\cr c&d\\end{matrix}").toParse(); }); + + it("should eat a final newline", function() { + const m3 = getParsed("\\begin{matrix}a&b\\\\ c&d \\\\ \\end{matrix}")[0]; + expect(m3.value.body.length).toBe(2); + }); }); describe("A sqrt parser", function() { @@ -2409,6 +2414,10 @@ describe("An aligned environment", function() { .toNotParse(); }); + it("should not eat the last row when its first cell is empty", function() { + const ae = getParsed("\\begin{aligned}&E_1 & (1)\\\\&E_2 & (2)\\\\E_3 & (3)\\end{aligned}")[0]; + expect(ae.value.body.length).toBe(3); + }); }); describe("A parser that does not throw on unsupported commands", function() {