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

feat: Support {CD} #2396

Merged
merged 32 commits into from
Dec 27, 2020
Merged

feat: Support {CD} #2396

merged 32 commits into from
Dec 27, 2020

Conversation

ronkok
Copy link
Collaborator

@ronkok ronkok commented Aug 9, 2020

This PR implements the AMS {CD} environment and therefore it is a partial response to #1834. Authors really want something more capable than {CD}, but this is doable now. Here's a screenshot showing the various arrows and labels.
CD

I have not yet done type annotations. If PR #2326 is going to merge soon, I may wait and try my hand at TypeScript instead of Flow.

@codecov-commenter
Copy link

codecov-commenter commented Aug 11, 2020

Codecov Report

Merging #2396 into master will increase coverage by 0.06%.
The diff coverage is 94.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2396      +/-   ##
==========================================
+ Coverage   93.83%   93.89%   +0.06%     
==========================================
  Files          84       85       +1     
  Lines        6145     6277     +132     
  Branches     1260     1288      +28     
==========================================
+ Hits         5766     5894     +128     
- Misses        348      353       +5     
+ Partials       31       30       -1     
Impacted Files Coverage Δ
contrib/render-a11y-string/render-a11y-string.js 84.07% <0.00%> (-1.01%) ⬇️
src/functions.js 100.00% <ø> (ø)
src/parseNode.js 73.33% <ø> (ø)
src/environments/cd.js 97.41% <97.41%> (ø)
src/environments/array.js 98.08% <100.00%> (+0.03%) ⬆️
src/functions/arrow.js 95.55% <100.00%> (+7.46%) ⬆️
src/stretchy.js 89.13% <100.00%> (+0.11%) ⬆️

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 e0ba19d...fc1a96e. Read the comment docs.

@ronkok ronkok changed the title [WIP]feat: Support {CD} feat: Support {CD} Aug 11, 2020
@ronkok
Copy link
Collaborator Author

ronkok commented Aug 12, 2020

Okay, I've added type annotations and resolved my little merge problem. This PR is ready for review.

@ronkok
Copy link
Collaborator Author

ronkok commented Dec 26, 2020

@kevinbarabash Thank you for an excellent review. It really helped me to clarify what the code is doing. I've picked up comments in the code but I have not yet written the new tests. More to come.

Also, there's a good description of CD at https://www.jmilne.org/not/Mamscd.pdf.

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.

Thanks for refactoring parseCD and adding all sorts of detailed comments. It makes it very easy to understand what's going on. 🎉

display="block"
>
<semantics>
<mtable rowspacing="0.24999999999999992em"
Copy link
Member

Choose a reason for hiding this comment

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

nit: why not 0.25em?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a computed number from https://github.com/KaTeX/KaTeX/blob/master/src/environments/array.js#L514-L519.

I'll add code that will round it to 4 places after the decimal.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine to leave this as is for now and handle it as part of #2460.

scriptlevel="1"
>
<mpadded width="0"
lspace="-1width"
Copy link
Member

Choose a reason for hiding this comment

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

Is width supposed to be a number here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's correct as is. The "-" prefix tells a lspace attribute that the value is an increment. And lspace accepts "1width" as a variable, which is a good thing because we don't know the numeric width.

So this <mpadded> creates a right-justified label.

scriptlevel="1"
>
<mpadded width="0"
lspace="-1width"
Copy link
Member

Choose a reason for hiding this comment

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

same

Comment on lines 2813 to 2821
it("should fail if not is display mode", function() {
expect(`\\begin{CD}A @X<a<< B @>>b> C @>>> D\\\\@. @| @AcAA @VVdV \\\\@. E @= F @>>> G\\end{CD}`).not.toParse(
new Settings({displayMode: false})
);
});
const displaySettings = new Settings({displayMode: true});
it("should fail if the character after '@' is not in <>AV=|.", function() {
expect(`\\begin{CD}A @X<a<< B @>>b> C @>>> D\\\\@. @| @AcAA @VVdV \\\\@. E @= F @>>> G\\end{CD}`).not.toParse(displaySettings);
});
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to have a successfully test here as well. It looks like the display mode test also has an issue with the X coming after @. Having a successfully test case would help when determine which part of the other test cases are causing them not parse.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do.

Comment on lines 73 to 74
const firstLabel = {type: "ordgroup", mode: "math", body: []};
const secondLabel = {type: "ordgroup", mode: "math", body: []};
Copy link
Member

Choose a reason for hiding this comment

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

I've been using TypeScript for another project recently and it requires more of the types to be explicitly specified.

return parent;
},
mathmlBuilder(group, options) {
return new mathMLTree.MathNode("mrow",
Copy link
Member

Choose a reason for hiding this comment

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

super style nit: extra space

@kevinbarabash
Copy link
Member

This looks good to go. I'll merge it once the automated checks complete.

@kevinbarabash kevinbarabash merged commit 75a3af9 into KaTeX:master Dec 27, 2020
@edemaine
Copy link
Member

Awesome work guys! Very cool to have commutative diagrams of some form in KaTeX!

@ronkok ronkok deleted the CD branch December 27, 2020 19:50
jedbrown added a commit to CEED/libCEED that referenced this pull request Dec 30, 2020
This (newly-merged feature) gets us nicer formatting for the commutative
diagram in examples/solids and will likely come in handy elsewhere.

KaTeX/KaTeX#2396
jedbrown added a commit to CEED/libCEED that referenced this pull request Dec 30, 2020
This (newly-merged feature) gets us nicer formatting for the commutative
diagram in examples/solids and will likely come in handy elsewhere.

KaTeX/KaTeX#2396
karenlstengel pushed a commit to CEED/libCEED that referenced this pull request Feb 17, 2021
This (newly-merged feature) gets us nicer formatting for the commutative
diagram in examples/solids and will likely come in handy elsewhere.

KaTeX/KaTeX#2396
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.

None yet

6 participants