mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.01k stars 1.16k forks source link

<<=> not handled by extension "mhchem" #234

Closed mikkelricky closed 11 years ago

mikkelricky commented 12 years ago

The reaction arrow <<=> is parsed as < followed by <=> , but should be parsed as a single arrow and rendered as "<=>> rotated 180 degrees" (I'm not very strong at chemistry).

I've tried to fix this myself and have come up with the following (expressed as a git diff)

diff --git a/unpacked/extensions/TeX/mhchem.js b/unpacked/extensions/TeX/mhchem.js
index 5326885..704f63c 100644
--- a/unpacked/extensions/TeX/mhchem.js
+++ b/unpacked/extensions/TeX/mhchem.js
@@ -81,6 +81,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
       '<->': "leftrightarrow",
       '<=>': "rightleftharpoons",
       '<=>>': "Rightleftharpoons",
+      '<<=>': "Leftrightharpoons",
       '^': "uparrow",
       'v': "downarrow"
     },
@@ -204,7 +205,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
     //
     ParseLess: function (c) {
       this.FinishAtom();
-      var arrow = this.Match(/^(<->?|<=>>?)/);
+      var arrow = this.Match(/^(<->?|<?<=>>?)/);
       if (!arrow) {this.tex += c; this.i++} else {this.AddArrow(arrow)}
     },

@@ -374,10 +375,12 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
   MACROS.xleftrightarrow = ['xArrow',0x2194,6,6];
   MACROS.xrightleftharpoons = ['xArrow',0x21CC,5,7];  // FIXME:  doesn't stretch in HTML-CSS output
   MACROS.xRightleftharpoons = ['xArrow',0x21CC,5,7];  // FIXME:  how should this be handled?
+  MACROS.xLeftrightharpoons = ['xArrow',0x21CC,5,7];

   //  FIXME:  These don't work well in FF NativeMML mode
   MACROS.longrightleftharpoons = ["Macro","\\stackrel{\\textstyle{{-}\\!\\!{\\rightharpoonup}}}{\\smash{{\\leftharpoondown}\\!\\!{-}}}"];
   MACROS.longRightleftharpoons = ["Macro","\\stackrel{\\textstyle{-}\\!\\!{\\rightharpoonup}}{\\small\\smash\\leftharpoondown}"];
+  MACROS.longLeftrightharpoons = ["Macro","\\stackrel{\\rightharpoonup}{{{\\leftharpoondown}\\!\\!\\textstyle{-}}}"];

   //
   //  Needed for \bond for the ~ forms
dpvc commented 12 years ago

Thanks for the information. The <<=> arrow doesn't seem to be in the documentation that I have, which is why I didn't include it. Your changes look good except for the match pattern, which would also allow <<=>>, so I would use /^(<->?|<==>?|<<=>)/ instead.

I will make the modifications to the mhchem package.

mikkelricky commented 12 years ago

Cool. And you're absolutely right that my match pattern isn't as precise as it should be. The correct(ed) pattern in your comment contains a minor typo, but I suppose we can agree that the pattern should be /^(<->?|<=>>?|<<=>)/.

dpvc commented 12 years ago

Right. Your final pattern is the right one. I'm reopening the issue so that I will be sure to make the changes, and will close it again after that has occurred.

fred-wang commented 12 years ago

I started to write tests for the mhchem extension: https://github.com/fred-wang/MathJax-test/tree/master/testsuite/LaTeXToMathML/mhchem

These are based on example from http://mirror.ctan.org/macros/latex/contrib/mhchem/mhchem.pdf

I added a test for an unknown bond and for the "<<=>" arrow mentioned in this issue.

I have a [Math Processing Error] with advanced-1.html. For various other tests I get undefined macros. It seems that adding the mhchem extension does not force the loading of the package containing extended arrow definitions.

Maybe some tests are not correct or I did not use the correct MathJax version.

dpvc commented 12 years ago

Right, the mhchem extension relies on the AMSmath extension, but it doesn't currently force it to be loaded. I will have to do that. In the meantime, if you add "AMSmath.js" to the TeX.extensions array, that should make the tests work.

Davide

fred-wang commented 12 years ago

OK, I've updated the tests on my fork. I still have a [Math Processing Error] with advanced-1.html. It seems that the "<=>" arrow does not work in that case (it works in arrows-1.html, though).

dpvc commented 11 years ago

The issue234 branch of my fork of MathJax should resolve both the missing <<=> arrow, and the [Math Processing Error] that Fred reported. The mhchem extension now sets things up to load AMSmath automatically when needed and properly synchronizes with its loading. I think the processing error came from not synchronizing properly so that mhchem tried to use part of AMSmath before it was loaded. The is certainly the issue with the undefined macros. In any case, the test files seem to work for me now. (And thanks for putting them together.)

fred-wang commented 11 years ago

OK, I no longer have the [Math Processing Error]. But I need to update the reference pages, now that you merged the issue285 branch into the issue234 branch. It seems that I also need to modify some arrows in the reference.

dpvc commented 11 years ago

Sorry about that. The issue285 problem was what was causing the arrows with wording above and below to not be the correct width. Unfortunately, it does mean that the reference needs to be updated, as you say.

fred-wang commented 11 years ago

No problem, anyway I expected that I would have to update them.

LaTeXToMathML/mhchem/advanced-1.html LaTeXToMathML/mhchem/advanced-2.html LaTeXToMathML/mhchem/advanced-3.html LaTeXToMathML/mhchem/amounts-1.html LaTeXToMathML/mhchem/arrows-1.html LaTeXToMathML/mhchem/arrows-2.html LaTeXToMathML/mhchem/basics-1.html LaTeXToMathML/mhchem/bonds-1.html LaTeXToMathML/mhchem/environments-1.html LaTeXToMathML/mhchem/isotopes-1.html LaTeXToMathML/mhchem/math-1.html LaTeXToMathML/mhchem/special_symbols-1.html

fred-wang commented 11 years ago

=> In Testsuite, Ready for release

fred-wang commented 11 years ago

I just tried to run tests on IE7. There are two extra commas after the definitions of " tripledash" and "xLeftrightharpoons"...

fred-wang commented 11 years ago

It seems that a class="MJX-variant" has added in LaTeXToMathML/mhchem/arrows-1.html and LaTeXToMathML/mhchem/arrows-2.html since the last time. If that's intentional, I can update the references.

dpvc commented 11 years ago

OK, I've taken care of the extra commas in the commit above. Yes, the extra MJX-variant comes from the solution to issue #268. This will be the case for any prime produced by the TeX input jax. I will look into not applying the variant attribute when used in a superscript, where it is redundant.

dpvc commented 11 years ago

I have removed the extra MJX-variant in the develop branch. The log message refers to the wrong issue (issue #268) rather than this. Argh! Too many issues being worked on at once!