Fix #337 - Array/Matrix environments do not trim newlines#479
Fix #337 - Array/Matrix environments do not trim newlines#479k4b7 merged 1 commit intoKaTeX:masterfrom
Conversation
|
@cbreeden thanks for the pull request. I'll have a look at it tomorrow. Please sign the CLA, found at found at www.khanacademy.org/r/cla, so we can merge this in. |
|
To use the screenshotter, you'll need to either add a new entry in https://github.com/Khan/KaTeX/blob/master/test/screenshotter/ss_data.yaml or modify an existing entry. I think it makes sense to create a new one and label it appropriately so that people know that the test is looking for a particular behavior. After running |
|
@kevinbarabash Thanks! I filled out the CLA. Can we put a hold on this? I have been spending some time trying to write up a proposal AST which would take out a lot of the TeX logic from the BuildHTML with a few goals:
I started working on implementing The only reason I ask for the hold is that I believe I am almost complete with the proposal. I just need to finish two more tasks:
|
|
@cbreeden looking forward to your proposal. |
src/environments.js
Outdated
| if (body.length > 1 && lastRow.length === 1 | ||
| && lastRow[0].value.length === 0) { | ||
| body.pop(); | ||
| } |
There was a problem hiding this comment.
What happens if there are more extra trailing line breaks?
There was a problem hiding this comment.
Inside the macro for matrices, TeX leaves a \crcr for the last row which acts like a \cr, unless it follows a \cr in which case it does nothing. This is why the last \cr or \\ is optional with matrices. But this also means it trims at most the last row. See this reference
The following works: |
|
I see... extra |
|
@cbreeden friendly ping on updating/adding screenshots. |
|
Sorry. I'll make the screenshots when I get back next week. |
|
@cbreeden This PR recently reached its 1-year anniversary! It looks like this was almost done -- just needed screenshots. Let me know if you want help with those. |
de3da3f to
e4c7cd1
Compare
Indeed. There seems to be more nesting than I remember. I needed to add a few more |
|
@cbreeden thanks for updating. I can run the docker. I'll send you a PR with the screenshots. |
58702b6 to
7b5ce16
Compare
|
Ok not sure what those errors are about. I'll try getting docker working on my machine again and take a look. |
|
It's odd that it's only failing for Chrome. I can see why it might change though: |
|
@cbreeden I'll send you another PR with screenshots for |
7b5ce16 to
889ead5
Compare
|
I was able to get the docker to work again! 🥇 The When I ran docker locally, I had a sporadic failure for The This PR shouldn't affect this test since it doesn't have a trailing empty line, but just to be sure I inspected the HTML output for both with and without this PR and they were identical: https://gist.github.com/cbreeden/72ca53e6089b9d39f2fcc54bffcda3a5 |
|
Chrome is a little finicky with these tests. I wonder if the new headless API for chrome would help here. |
Something we might look into. I think we'd still want to do it inside a docker though b/c there's lots of variables that affect the rendering. |
|
@cbreeden thanks for PR. |
* 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!

This is an attempt to fix #337. With all my testing it appears to work as shown in the images below:
You should trim at most the last newline. This agrees with LaTeX:
Though there is one question that I was hoping to clear up. I wasn't able to trigger rowGaps to be anything other than
null. I'm not sure how they are supposed to be handled in the case for deleting a row.I also wasn't exactly sure how I should go about using the screenshooter. I was able to get the docker to run. Am I supposed to run some kind of image diff on the results with what you have on github?
EDIT: Sorry for the duplicate pull request. I wanted to work on something else so I needed to put these changes into a branch.