Skip to content

Commit

Permalink
Fix #946 (#949)
Browse files Browse the repository at this point in the history
* 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!
  • Loading branch information
ronkok authored and kevinbarabash committed Nov 12, 2017
1 parent 991bfd5 commit 3e34453
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/environments/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions test/katex-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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];

This comment has been minimized.

Copy link
@ccorn

ccorn Nov 12, 2017

Contributor

Shouldn't there be an & before the E_3?

This comment has been minimized.

Copy link
@kevinbarabash

kevinbarabash Nov 12, 2017

Member

I thought the bug was just for the first cell in the first row. I should've looked at the bug report more closely. @ccorn thanks for catching this.

expect(ae.value.body.length).toBe(3);
});
});

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

0 comments on commit 3e34453

Please sign in to comment.