Page MenuHomePhabricator

native:chem expression <chem>A ->[{}\atop\ce{+H2O}] B</chem> fail
Open, LowPublic

Description

Most things seem fine, although with a lighter weight, and font size for equations a little less than standard font for surronding text. A couple of things are broken

Some of <chem> environment is broken <chem>A ->[{}\atop\ce{+H2O}] B</chem> with a Failed to parse syntax error, which is a bit weird, as other chem stuff works.

I'm not sure where the issues lie, is it the conversion of latex to mathml, or Chrome's rendering of the mathml.

Event Timeline

Change 974141 had a related patch set uploaded (by Stegmujo; author: Stegmujo):

[mediawiki/extensions/Math@master] Fix native:chem expression <chem>A ->[{}\atop\ce{+H2O}] B</chem> fail

https://gerrit.wikimedia.org/r/974141

Checked this case, problem is that atop is not recognized by texvc php grammar.

It works with mathoid rendering and generates the following MathML output

<math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\ce {A->[{} \atop {\ce {+H2O}}]B}}}">
  <semantics>
    <mrow class="MJX-TeXAtom-ORD">
      <mstyle displaystyle="true" scriptlevel="0">
        <mrow class="MJX-TeXAtom-ORD">
          <mtext>A</mtext>
          <mrow class="MJX-TeXAtom-REL">
            <mover>
              <mo>→</mo>
              <mpadded width="+0.611em" lspace="0.278em" voffset=".15em">
                <mfrac linethickness="0">
                  <mrow class="MJX-TeXAtom-ORD">

                  </mrow>
                  <mrow class="MJX-TeXAtom-ORD">
                    <mo>+</mo>
                    <msubsup>
                      <mtext>H</mtext>
                      <mrow class="MJX-TeXAtom-ORD">
                        <mn>2</mn>
                      </mrow>
                      <mrow class="MJX-TeXAtom-ORD">
                        <mspace width="0pt" height="0pt" depth=".2em"></mspace>
                      </mrow>
                    </msubsup>
                    <mtext>O</mtext>
                  </mrow>
                </mfrac>
              </mpadded>
            </mover>
          </mrow>
          <mtext>B</mtext>
        </mrow>
      </mstyle>
    </mrow>
    <annotation encoding="application/x-tex">{\displaystyle {\ce {A-&gt;[{} \atop {\ce {+H2O}}]B}}}</annotation>
  </semantics>
</math>

The example is somehow strange. <chem>A ->[ce{+H2O}] B</chem> produces the same result and does not make use of an empty atop. Maybe we can define another example that makes more sense from a chemistry point of view.

The issue is that mhchem-texify produces a atop expression which is not readable for the TexVC grammar.

\ce{{}\atop a}

would be texified by mhchemTexify to: 

\ce{\atop a} 

actually it should be 

\ce{{}\atop a} 

to be valid TexVC grammer

This is fixed in the recent patchset by adding a space "{\;}\atop" before passing to mhChemTexify, so the library mhchem does not have to be modified and texified latex is readable by TexVC.

To me, the proposed solution seems to be more of a workaround than a fix. My proposal would be that texvc should accept expressions that start with an infix operator, i.e., in the form $arg1? infxOperator arg2 $ that would mimic the behavior of tex.

By the way \atop is amsmath discouraged Package amsmath Warning: Foreign command \atop; \frac or \genfrac (amsmath) should be used instead. https://de.overleaf.com/read/grbnmqpbbvdz#a1ddac

@mhchem what do you think?

To me, the proposed solution seems to be more of a workaround than a fix. My proposal would be that texvc should accept expressions that start with an infix operator, i.e., in the form $arg1? infxOperator arg2 $ that would mimic the

As i understand, you want to recognize $arg1 with texvc grammar as an optional parameter.
I think the LaTeX documentation for atop says that the numerator/arg1 is not optional.

The issue in this case is that an empty parameter is used as curly "{}\atop y" the preceding empty curly is removed by mhchem texification, it could be considered to not remove the empty curly by mhchem texification.

@mhchem what do you think?

I also think the expression does not make too much sense. We have an arrow with an \atop command with an empty base. I don't see why anybody would do that.

How does this work, internally? mhchemParser parses {} as an empty text escape, then sees a \command and switches to "The user forgot math mode, I'll switch to it". The proper way to write this would be: ->[${}\atop{}$], then the {} would not be omitted. But also this doesn't really make sense.

mhchemParser is very forgiving regarding sloppy user input, because the first \ce command of MathJax (not written by me) was as well.

We see a difference in how MathJax and texvc parse incomplete/bad user input. mhchemParser works identical. I think we can leave it that way. We probably have dozens of other use cases where MathJax and texvc differ.