Skip to content

feat: support {equation}, {equation*}, and {split} - #2369

Merged
ylemkimon merged 21 commits into
KaTeX:masterfrom
ronkok:equation
Aug 3, 2020
Merged

ylemkimon merged 21 commits into
KaTeX:masterfrom
ronkok:equation

Conversation

@ronkok

@ronkok ronkok commented Aug 1, 2020 •

Copy link
Copy Markdown
Collaborator

Three more AMS environments.

In AMS LaTeX, the {split} environment is allowed only inside certain other environments, like {equation} or {gather}. I've set it so that in KaTeX, the {split} environment is allowed only inside {equation}. That's where it will be most valuable. If we get requests for other nesting, we can revisit this code at some later time.

Here's a screenshot:
Equation

@codecov-commenter

codecov-commenter commented Aug 1, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #2369 into master will increase coverage by 0.01%.
The diff coverage is 90.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2369      +/-   ##
==========================================
+ Coverage   93.96%   93.97%   +0.01%     
==========================================
  Files          84       84              
  Lines        5434     5444      +10     
  Branches      959      961       +2     
==========================================
+ Hits         5106     5116      +10     
  Misses        297      297              
  Partials       31       31              
Impacted Files Coverage Δ
src/environments/array.js 97.82% <90.47%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1263681...8ada471. Read the comment docs.

@ylemkimon

ylemkimon commented Aug 2, 2020 •

Copy link
Copy Markdown
Member

Isn't KaTeX assumed to be in equation* environment by default?

@ronkok

ronkok commented Aug 2, 2020

Copy link
Copy Markdown
Collaborator Author

No, KaTeX is in math mode by default. {equation*} only allows one line and one column. It will return an error if the input includes a & or a \cr and it will eat a \\.

@ylemkimon

Copy link
Copy Markdown
Member

One of default delimiters in auto-render is \[ and \], which are AFAIK macro to equation* environment:

{left: "\\[", right: "\\]", display: true},

I think we should allow split at the outermost (top) level.

@ronkok

ronkok commented Aug 2, 2020

Copy link
Copy Markdown
Collaborator Author

You have a point. It seems that \[…\] is indeed equivalent to {equation*}. On the other hand, $$…$$ is not equivalent to {equation*}. $$…$$ does not allow {split} at the top level.

That makes things a little awkward. The KaTeX option for displayMode does not distinguish between \[…\] and $$…$$ and I really do not want to create yet another KaTeX option. That means we have to make KaTeX {split} behavior agree with either \[…\] or $$…$$ but not both.

So I agree to fall in with your views. I'll rewrite {split} so that it is allowed at the top level whenever displayMode is set to true. That simplifies the code, which is an added benefit. {split} becomes just a version of {align*} with a restriction to no more than two columns.

If anyone has an objection to this plan, please let me know.

After this PR comes multline and after that PR, I'll turn in a documentation PR that tries to convey all these nuances.

@edemaine

edemaine commented Aug 2, 2020

Copy link
Copy Markdown
Member

I believe the only reason that $$ doesn't support split is that it's (nearly) impossible (for amsmath) to redefine $$'s behavior in TeX. So I think it's fine to err on the side of allowing things, as if $$ were in fact \[.

Comment thread src/environments/array.js Resolved
Comment thread src/parseNode.js Resolved
Comment thread src/environments/array.js Resolved
Comment thread src/environments/array.js Resolved
Comment thread src/environments/array.js Resolved
@ronkok

ronkok commented Aug 2, 2020

Copy link
Copy Markdown
Collaborator Author

Well, I have screenshotter problems and CircleCI tells me that "This job has no artifacts." I'm stumped. And things were going so well.

Any suggestions would be welcome.

@ronkok

ronkok commented Aug 3, 2020

Copy link
Copy Markdown
Collaborator Author

This PR now contains a breaking change in the {array} environment. If the environment body contains more columns than specified in the first argument, this PR now throws a ParseError (as does LaTeX). Before this PR, KaTeX went ahead and created the rest of the columns and centered them.

This was driven home to me because one of the screenshotter {array} tests threw a ParseError. It thoroughly messed up the screenshotter tests.

Is LaTeX purity worth a breaking change?

@edemaine

edemaine commented Aug 3, 2020

Copy link
Copy Markdown
Member

Perhaps a strict call would be more appropriate than throwing an error? (That's kinda what it's there for: things that don't work in LaTeX but are easy to support.) Further evidence for this is that MathJax silently accepts more columns than there are column specs.

@ronkok

ronkok commented Aug 3, 2020 •

Copy link
Copy Markdown
Collaborator Author

Perhaps a strict call...?

That seems reasonable for {array}. How about {equation} (max 1 column) and {split} (max 2 columns)? I'm not sure why, but I think they maybe really should get a ParseError.

@ylemkimon ylemkimon changed the title Support {equation}, {equation*}, and {split} feat: support {equation}, {equation*}, and {split} Aug 3, 2020
@ronkok

ronkok commented Aug 3, 2020

Copy link
Copy Markdown
Collaborator Author

I'm not sure that the eslint check is working. I had to do a yarn install to get this commit to work. When I run yarn test:lint, I get a message:

Error: eslint-plugin-flowtype tried to access babel-eslint, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

@ylemkimon

Copy link
Copy Markdown
Member

@ronkok You can safely ignore the error (actually, a warning).

@ronkok

ronkok commented Aug 3, 2020

Copy link
Copy Markdown
Collaborator Author

Then this PR is ready for review.

Comment thread src/environments/array.js Resolved
Comment thread src/environments/array.js Resolved

@ylemkimon ylemkimon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the PR! This was one of the most requested feature in KaTeX.

@ylemkimon
ylemkimon merged commit ab5936a into KaTeX:master Aug 3, 2020
@ronkok

ronkok commented Aug 3, 2020

Copy link
Copy Markdown
Collaborator Author

Thank you for the review!

I'll mention here that I no longer intend to submit a PR for the {multline} environment, for two reasons. (1) No one has ever requested it, and (2) I don't know how to reconcile our overlapping \tag problem with lines that are justified left or justified right.

So I will submit no more environments any time soon. I do have some documentation to submit.

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