-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support Reaction Arrows #1078
Support Reaction Arrows #1078
Conversation
This PR is written to supply reaction arrows for a future `mhchem` extension. `mhchem` uses seven reaction arrows. Four of them correspond to extensible arrows already available in KaTeX. This PR creates the other three. These arrows will also be useful to chemists writing about reactions when `mhchem` is unavailable. Three new extensible arrows are introduced: `\xrightleftarrows`, `\xrightequilibrium`, and `\xleftequilibrium`. These names are not `mhchem`’s user-facing function names. In `mhchem`, users would call these arrows with syntax such as: `\ce{A<-->B}`, or `\ce{A<=>>B}`, or `\ce{A<<=>B}`. I’ve provided names that look more like the other extensible arrow names. That’s probably worth some discussion.
One can get a sense of how these arrows can be used by looking at pages here or here. Also, the typography on those pages point out why There are also places that would benefit from |
I would appreciate a review from @mhchem as to the arrow rendering. The usual review from @kevinbarabash or @edemaine is also in order. |
That sounds good. The harpoon arrow heads are much larger than the normal arrow heads. Is that intended and consistent? I created 42 test cases.
Could you create a high-res rendering of those for me to review (as above). If you want to see what that means, you could paste that at the bottom of the MathJax/mhchem manual for a rough idea. (In detail MathJax's arrow typography has room for improvement). |
@mhchem Re: harpoon sizes: Yes, mine are large by design, but that can be changed. I get my harpoon geometry from KaTeX font glyphs. Two harpoon sizes are available. The harpoons from KaTeX_Main are larger than the KaTeX_AMS harpoons. I can show you the difference. Below is how the As you can see,
Now I was thinking that you would use the existing KaTeX function |
generate screenshots for ReactionArrows
@ronkok I would be fine with the larger harpoon arrows. The only thing I would ask for is consistency between all 3 versions of harpoon arrows. |
@mhchem we don't support the |
@mhchem If you don't mind the large harpoons, then I am going to keep the ones already submitted in this PR. That way, you can use the already existing It's true that this PR does not support |
@kevinbarabash Yes, completely understand that. There is no I rephrase my question: I'd like to get a feeling of the arrow consistency. Could you please provide renderings of all 6 relevant arrow types, in 7 possible states? Here is an example how this could look like for the first arrow (this is NOT KaTeX). (If you had a live demo system with this pull request, I could test it myself. But, please excuse, I don't have the time to go through installing/building/configuring/fiddling with/cherry-picking/merging the sources.) |
Cool! |
@mhchem, I captured the screen shots below from a local build using this PR. |
The source code for all those screens shots is:
|
@ronkok I noticed that the output of |
@kevinbarabash I agree. I have the KaTeX_Main, KaTeX_AMS, KaTeX_Size1, and KaTeX_Size4 fonts installed as system fonts. That's probably the only reason I get any decent renderings at all. Anything that strays from those fonts is unavailable to me in a local build. |
Thanks a lot. The arrow look fine and good to use. I would predict that he following arrows would touch the text.
|
@mhchem Thank you for the review. I'm glad that the arrows look good to you. @kevinbarabash Now we move on to the next step.
I'm okay with that general idea. I anticipated that you would be hesitant to create a new function name where none existed before. But I have questions about what "private" means. (1) Is it enough to omit the proposed names from the function support page? Or (2) do you mean to programmatically prevent anything except the future If it is (2), then I'll need some help. I have not the vaguest idea of how to accomplish that. |
@ronkok I was thinking more along the lines of option 2. In #794, @edemaine added |
@kevinbarabash My first, most straightforward attempt did not work. If I edit
... and then replace "xrightleftarrows" with "qwertyuiop" in |
Okay, let's do that. Once |
To prevent a small gap when rendering in very large font sizes.
@ronkok Ooops, I meant the other one, where the short arrow is on top. |
You may be correct about that short arrow. I'd like to test it, but at the moment, I can't. After issue #1052 is resolved, I'll take a look. |
@mhchem You were correct about an interference between a short harpoon and a descender. So I've made an adjustment to the upper text vertical alignment. |
@kevinbarabash, I've added a warning to the code in It seems that you have delayed PR #1083 until I finished this one, thereby taking onto yourself the burden of rebasing the conflicts. That's very considerate of you. And I think this is ready for updated screenshots and final review.. |
One final thought for final review. That vertical adjustment that I just made to the upper text is now applied to all extensible arrows. But the adjustment is really only needed for |
How much work is it? If it's a lot, leave a TODO. If it's not much, could you do it as part of this PR? |
Done. |
Thanks. I'll regenerate the screenshots later tonight. |
regenerate screenshots for reaction arrows
// The next three arrows are from the mhchem package. | ||
// In mhchem.sty, min-length is 2.0em. But these arrows might appear in the | ||
// document as \xrightarrow or \xrightleftharpoons. Those have | ||
// min-length = 1.75em, so we set min-length on these next three to match. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. Wouldn't we want these commands to match mhchem.sty
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that I'm trying to use one arrow to emulate both mathtools
and mhchem
. Those two packages both render a double-ended harpoon, and they are close, but not quite identical. mathtools
uses a larger arrow head. mhchem
has a longer min-length
.
My motivation has been to minimize the amount of code in svgGeometry.js
. If you don't mind adding another dozen lines of code, then I could get a closer match to the original mhchem
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new arrows are only using new geometry in svgGeometry.js. There doesn't seem to be any sharing of geometry between these new arrows and existing arrows. Could we modify the new geometry that you already added? What would need to be added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two issues here:
-
I need to retract part of what I said before. The
min-length
is independent of thepath
geometry insvgGeometry.js
. So, yes, I can give all themhchem
reaction arrows the 2.0emmin-length
defined in the originalmhchem
package. To do that, I have to invent another four brand-new function names, then in thekatexImagesData
object, I can define themin-length
as we want. That adds eight lines of code. But no new paths are necessary for min-length. -
mhchem
has seven reaction arrows, not just the three new ones in this PR. For the others, the proposedmhchem
extension can make calls to extensible arrows that already exist. That's the code sharing I was referring to. And my stinginess with code means thatmhchem
will have to call themathtools
arrow\xrightleftharpoons
, which has larger arrowheads than the originalmhchem
package.
To sum up: I can customize the min-length
with another 8 line of code and I can customize the arrowhead size with a dozen lines more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be fine with any solution.
In Latex/mhchem (= mhchem.sty), I was very picky with the arrows. For instance, I made them all have the same length (when used without superscript or subscript). With MathJax/mhchem I couldn't be so picky. I used what I could get. There, the arrows are of different length, some even cannot stretch. So, I appreciate your perfectionism – and I could join in if you like (like the question if the min-length should be implemented inside the arrows themselves or be specified with their usage). On the other hand, the arrows are already much better than the ones of MathJax and the last grain of perfection could be added later on.
@@ -47,6 +47,9 @@ const stretchyCodePoint: {[string]: string} = { | |||
xtwoheadrightarrow: "\u21a0", | |||
xlongequal: "=", | |||
xtofrom: "\u21c4", | |||
xrightleftarrows: "\u21c4", | |||
xrightequilibrium: "\u21cc", // Not a perfect match. | |||
xleftequilibrium: "\u21cb", // None better available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a couple of times to realize what the difference between u21cc
and u21cb
.
@@ -242,6 +242,10 @@ defineFunction([ | |||
"\\xrightharpoonup", "\\xleftharpoondown", "\\xleftharpoonup", | |||
"\\xrightleftharpoons", "\\xleftrightharpoons", "\\xlongequal", | |||
"\\xtwoheadrightarrow", "\\xtwoheadleftarrow", "\\xtofrom", | |||
// The next 3 functions are here to support the mhchem extension. | |||
// Direct use of these functions is discouraged and may break someday. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks :)
0.5 * arrowBody.height - 0.111; | ||
if (group.value.label === "\\xleftequilibrium") { | ||
upperShift -= upperGroup.depth; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this defined in mhchem.sty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The short upwards harpoon has an interference that doesn't occur in the other extensible arrows. So I needed to bump the text up to miss the descender.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In LaTeX/mhchem (= mhchem.sty), I used a different approach: I made the arrow longer, so that the descenders do not touch the arrow head. I am completely fine with your solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm excited that we're making progress on mhchem support.
@ronkok katex.less has been moved to the src folder. This merge conflict will be need to be resolved before I can merge this PR. |
I just merged local master into this branch. I think that takes care of the |
This PR is written to supply reaction arrows for a future
mhchem
extension.mhchem
uses seven reaction arrows. Four of them correspond to extensible arrows already available in KaTeX. This PR creates the other three.These arrows will also be useful to chemists writing about reactions when
mhchem
is unavailable.Three new extensible arrows are introduced:
\xrightleftarrows
,\xrightequilibrium
, and\xleftequilibrium
.These names are not
mhchem
’s user-facing function names. Inmhchem
, users would call these arrows with syntax such as:\ce{A<-->B}
, or\ce{A<=>>B}
, or\ce{A<<=>B}
. I’ve provided names that look more like the other extensible arrow names. That’s probably worth some discussion.