Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #946 #949

Merged
merged 5 commits into from
Nov 12, 2017
Merged

Fix #946 #949

merged 5 commits into from
Nov 12, 2017

Conversation

ronkok
Copy link
Collaborator

@ronkok ronkok commented Oct 24, 2017

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.

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.
@kevinbarabash
Copy link
Member

I wonder if we can test some these behaviors with unit tests that verify that one {aligned} snipped parses the same as another.

@ronkok
Copy link
Collaborator Author

ronkok commented Oct 25, 2017

I put in the test case from #946 into the screenshotter tests. I haven't thought of a more elegant way to test the parse comparison.

@edemaine
Copy link
Member

I was hoping the following added tests in test/katex-spec.js would work, but I can't even get the second one to work on master (though it should)... must be a small difference in the parse tree.

describe("An aligned environment", function() {
    ...
    it("should eliminate final newline 1", function() {
        expect("\\begin{aligned}x&y\\\\&z\\\\\\end{aligned}")
            .toParseLike("\\begin{aligned}x&y\\\\&w\\end{aligned}");
    });

    it("should eliminate final newline 2", function() {
        expect("\\begin{aligned}x&y\\\\z&w\\\\\\end{aligned}")
            .toParseLike("\\begin{aligned}x&y\\\\z&w\\end{aligned}");
    });

I guess we could add a test that confirms the right number of rows in the parsed align table.

@kevinbarabash
Copy link
Member

@edemaine thanks for checking that. I would've expected that to work. :\

@ronkok
Copy link
Collaborator Author

ronkok commented Oct 26, 2017

The code that that removes a trailing \\ is located in array.js, not in Parser.js. We can't expect a unit test on the parse tree to tell us anything useful about the handling of a trailing \\.

Maybe I can think of a unit test that works on buildTree or on even on buildMathML. I'll look into it.

Not right away though. My next few days are pretty booked up. If someone would like to suggest a test sooner than that, feel free.

@kevinbarabash
Copy link
Member

The code that that removes a trailing \ is located in array.js, not in Parser.js. We can't expect a unit test on the parse tree to tell us anything useful about the handling of a trailing \.

But the Parser.js imports environments.js which imports array.js and we do call the handler for a particular environment when we encounter it from Parser.js. I'd be interested in seeing how those parse trees diff for those case where we expect them to be the same.

@ronkok
Copy link
Collaborator Author

ronkok commented Nov 10, 2017

The most recent commit fixes a bug and adds two tests that confirm the correct number of rows.

@ronkok
Copy link
Collaborator Author

ronkok commented Nov 11, 2017

Can anyone suggest why Travis has not completed its check? Or what I can try to get it working?

When I ran jest locally, the tests all ran well.

@kevinbarabash
Copy link
Member

@ronkok not sure why. I'm going to "update branch" and see if that does anything.

Copy link
Member

@kevinbarabash kevinbarabash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in reviewing this. Code changes look good, requesting a minor update to one of the tests. See inline comments for details.

@@ -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];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the TeX code be:

\\begin{matrix}a&b\\\\ c&d \\\\ \\end{matrix}

to include the extra newline that's supposed to get eaten?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right you are. I'll make the change and resubmit.

&& lastRow.value.length === 1
&& lastRow.value[0].value.length === 0) {
&& lastRow.length === 1
&& lastRow[0].value.value[0].value.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this... I wish our parse tree was nicer.

@ronkok
Copy link
Collaborator Author

ronkok commented Nov 11, 2017

@kevinbarabash Thank you. That did the trick.

Copy link
Member

@kevinbarabash kevinbarabash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevinbarabash
Copy link
Member

@ronkok thanks for fixing that test.

@kevinbarabash kevinbarabash merged commit 3e34453 into KaTeX:master Nov 12, 2017
@edemaine
Copy link
Member

FWIW, I think this rather significant bug fix is worth a release. Thanks guys for making it happen!

@ccorn
Copy link
Contributor

ccorn commented Nov 12, 2017

Thanks too, though to me it seems that the 2nd test misses an & and thus would let the unfixed version pass as well. Update: Fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants