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

mhchem package may be incompatible #793

Open
John02139 opened this issue Jan 31, 2025 · 4 comments
Open

mhchem package may be incompatible #793

John02139 opened this issue Jan 31, 2025 · 4 comments

Comments

@John02139
Copy link
Contributor

Running lualatex-dev, LaTeX2e <2025-06-01> pre-release-1 (develop 2025-1-15 branch).

\DocumentMetadata 
{
	testphase={phase-III,firstaid,math,table,title},
	pdfstandard = ua-2,
	pdfversion  = 2.0,
	lang = en-US,
}
\documentclass{article}
\usepackage{unicode-math}

\usepackage[version=4]{mhchem}

\begin{document}

This example is taken from the documentation of the \texttt{mhchem} package.
\begin{gather}
\ce{x Na(NH4)HPO4 ->[\Delta] (NaPO3)_x + x NH3 ^ + x H2O} \\[0.5em]
\ce{^234_90Th -> ^0_-1$\beta${} + ^234_91Pa} \\[0.5em]
\ce{SO4^2- + Ba^2+ -> BaSO4 v} \\[0.5em]
\ce{Zn^2+
<=>[+ 2OH-][+ 2H+]
$\underset{\textrm{amphoteric hydroxide}}{\ce{Zn(OH)2 v}}$
<=>[+ 2OH-][+ 2H+]
$\underset{\textrm{tetrahydroxozincate}}{\ce{[Zn(OH)4]^2-}}$
}
\end{gather}

\end{document}

This gives the following warnings

====>subpart splitting deactivated
====>grabbed math=macro:->\ce {x Na(NH4)HPO4 ->[\Delta ] (NaPO3)_x + x NH3 ^ + 
x H2O} \\[0.5em] \ce {^234_90Th -> ^0_-1$\beta ${} + ^234_91Pa} \\[0.5em] \ce {
SO4^2- + Ba^2+ -> BaSO4 v} \\[0.5em] \ce {Zn^2+ <=>[+ 2OH-][+ 2H+] $\underset {
\textrm {amphoteric hydroxide}}{\ce {Zn(OH)2 v}}$ <=>[+ 2OH-][+ 2H+] $\underset
 {\textrm {tetrahydroxozincate}}{\ce {[Zn(OH)4]^2-}}$ }
WARNING: Tag extraction failed
WARNING: Tag extraction failed
WARNING: Tag extraction failed
WARNING: Tag extraction failed
@u-fischer
Copy link
Member

The "Tag extraction failed" warning is an error in the luamml code that will be corrected in the next release (it already works in a branch).

But beside this: a chemical formula should naturally not be tagged as math (and the mathml extraction looks odd anyway).

I have no idea if some sensible "language" exist here. Probably the best currently would be to tag that as a Formula with an alt-text created from the source.

\DocumentMetadata
{
	testphase={phase-III,firstaid,math,table,title},
	pdfstandard = ua-2,
	pdfversion  = 2.0,
	lang = en-US,
}
\documentclass{article}
\usepackage{unicode-math}

\usepackage[version=4]{mhchem}

\begin{document}

This example is taken from the documentation of the \texttt{mhchem} package.
%
\begingroup
\AssignSocketPlug {tagsupport/math/struct/begin}{default}
\AssignSocketPlug {tagsupport/math/struct/end}{default}
\tagpdfsetup{math/alt/use}
\begin{gather}
\ce{x Na(NH4)HPO4 ->[\Delta] (NaPO3)_x + x NH3 ^ + x H2O} \\[0.5em]
\ce{^234_90Th -> ^0_-1$\beta${} + ^234_91Pa} \\[0.5em]
\ce{SO4^2- + Ba^2+ -> BaSO4 v} \\[0.5em]
\ce{Zn^2+
<=>[+ 2OH-][+ 2H+]
$\underset{\textrm{amphoteric hydroxide}}{\ce{Zn(OH)2 v}}$
<=>[+ 2OH-][+ 2H+]
$\underset{\textrm{tetrahydroxozincate}}{\ce{[Zn(OH)4]^2-}}$
}
\end{gather}
\endgroup
\end{document}

@davidcarlisle
Copy link
Member

@u-fischer there is ChemML but as support for that isn't that common, using MathML for chemistry isn't unreasonable.

MathJax has support for the mhchem package and produces this MathML (I just pasted the supplied example into
math.stackexchange that supports mathjax and copied the generated mathml. (mhchem doesn't seem to be available to mathjax in this github site)

there is some experimental support for intent properties in MathML to give hints for chemical rather than mathematical readings.

https://w3c.github.io/mathml-docs/intent-core-properties/#prop-chemical-equation

Image

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mtable rowspacing="0.8em 0.8em 0.8em 0.3em" columnspacing="1em" displaystyle="true">
    <mtr>
      <mtd>
        <mtext>x</mtext>
        <mtext>Na</mtext>
        <mrow class="MJX-TeXAtom-ORD">
          <mo stretchy="false">(</mo>
          <msubsup>
            <mtext>NH</mtext>
            <mrow class="MJX-TeXAtom-ORD">
              <mn>4</mn>
            </mrow>
            <mrow class="MJX-TeXAtom-ORD">
              <mspace width="0pt" height="0pt" depth=".2em" />
            </mrow>
          </msubsup>
          <mo stretchy="false">)</mo>
        </mrow>
        <msubsup>
          <mtext>HPO</mtext>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>4</mn>
          </mrow>
          <mrow class="MJX-TeXAtom-ORD">
            <mspace width="0pt" height="0pt" depth=".2em" />
          </mrow>
        </msubsup>
        <mrow class="MJX-TeXAtom-REL">
          <mover>
            <mo>&#x2192;</mo>
            <mpadded width="+0.611em" lspace="0.278em" voffset=".15em">
              <mi mathvariant="normal">&#x0394;<!-- Δ --></mi>
            </mpadded>
          </mover>
        </mrow>
        <mrow class="MJX-TeXAtom-ORD">
          <mo stretchy="false">(</mo>
          <msubsup>
            <mtext>NaPO</mtext>
            <mrow class="MJX-TeXAtom-ORD">
              <mn>3</mn>
            </mrow>
            <mrow class="MJX-TeXAtom-ORD">
              <mspace width="0pt" height="0pt" depth=".2em" />
            </mrow>
          </msubsup>
          <mo stretchy="false">)</mo>
        </mrow>
        <mtext>x</mtext>
        <mo>+</mo>
        <mtext>x</mtext>
        <msubsup>
          <mtext>NH</mtext>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>3</mn>
          </mrow>
          <mrow class="MJX-TeXAtom-ORD">
            <mspace width="0pt" height="0pt" depth=".2em" />
          </mrow>
        </msubsup>
        <mrow class="MJX-TeXAtom-ORD">
          <mo stretchy="false">&#x2191;<!-- ↑ --></mo>
        </mrow>
        <mo>+</mo>
        <mtext>x</mtext>
        <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" />
          </mrow>
        </msubsup>
        <mtext>O</mtext>
      </mtd>
    </mtr>
    <mtr>
      <mtd>
        <mmultiscripts>
          <mtext>Th</mtext>
          <none />
          <none />
          <mprescripts />
          <mn>90</mn>
          <mn>234</mn>
        </mmultiscripts>
        <mo stretchy="false">&#x27F6;<!-- ⟶ --></mo>
        <mmultiscripts>
          <mrow class="MJX-TeXAtom-ORD">
            <mo>&#x2212;<!-- − --></mo>
          </mrow>
          <none />
          <none />
          <mprescripts />
          <none />
          <mn>0</mn>
        </mmultiscripts>
        <mn>1</mn>
        <mspace width="thinmathspace" />
        <mi>&#x03B2;<!-- β --></mi>
        <mrow class="MJX-TeXAtom-ORD">

        </mrow>
        <mo>+</mo>
        <mmultiscripts>
          <mtext>Pa</mtext>
          <none />
          <none />
          <mprescripts />
          <mn>91</mn>
          <mn>234</mn>
        </mmultiscripts>
      </mtd>
    </mtr>
    <mtr>
      <mtd>
        <msubsup>
          <mtext>SO</mtext>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>4</mn>
          </mrow>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>2</mn>
            <mo>&#x2212;<!-- − --></mo>
          </mrow>
        </msubsup>
        <mo>+</mo>
        <msup>
          <mtext>Ba</mtext>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>2</mn>
            <mo>+</mo>
          </mrow>
        </msup>
        <mo stretchy="false">&#x27F6;<!-- ⟶ --></mo>
        <msubsup>
          <mtext>BaSO</mtext>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>4</mn>
          </mrow>
          <mrow class="MJX-TeXAtom-ORD">
            <mspace width="0pt" height="0pt" depth=".2em" />
          </mrow>
        </msubsup>
        <mrow class="MJX-TeXAtom-ORD">
          <mo stretchy="false">&#x2193;<!-- ↓ --></mo>
        </mrow>
      </mtd>
    </mtr>
    <mtr>
      <mtd>
        <msup>
          <mtext>Zn</mtext>
          <mrow class="MJX-TeXAtom-ORD">
            <mn>2</mn>
            <mo>+</mo>
          </mrow>
        </msup>
        <mrow class="MJX-TeXAtom-REL">
          <munderover>
            <mo>&#x21CC;</mo>
            <mpadded width="+0.667em" lspace="0.278em" voffset="-.24em">
              <mo>+</mo>
              <mn>2</mn>
              <mi>H</mi>
              <mo>+</mo>
            </mpadded>
            <mpadded width="+0.667em" lspace="0.278em" voffset=".15em">
              <mo>+</mo>
              <mn>2</mn>
              <mi>O</mi>
              <mi>H</mi>
              <mo>&#x2212;<!-- − --></mo>
            </mpadded>
          </munderover>
        </mrow>
        <munder>
          <mrow>
            <mtext>Zn</mtext>
            <msubsup>
              <mrow class="MJX-TeXAtom-ORD">
                <mo stretchy="false">(</mo>
                <mtext>OH</mtext>
                <mo stretchy="false">)</mo>
              </mrow>
              <mrow class="MJX-TeXAtom-ORD">
                <mn>2</mn>
              </mrow>
              <mrow class="MJX-TeXAtom-ORD">
                <mspace width="0pt" height="0pt" depth=".2em" />
              </mrow>
            </msubsup>
            <mrow class="MJX-TeXAtom-ORD">
              <mo stretchy="false">&#x2193;<!-- ↓ --></mo>
            </mrow>
          </mrow>
          <mrow class="MJX-TeXAtom-ORD">
            <mtext>amphoteric hydroxide</mtext>
          </mrow>
        </munder>
        <mrow class="MJX-TeXAtom-REL">
          <munderover>
            <mo>&#x21CC;</mo>
            <mpadded width="+0.667em" lspace="0.278em" voffset="-.24em">
              <mo>+</mo>
              <mn>2</mn>
              <mi>H</mi>
              <mo>+</mo>
            </mpadded>
            <mpadded width="+0.667em" lspace="0.278em" voffset=".15em">
              <mo>+</mo>
              <mn>2</mn>
              <mi>O</mi>
              <mi>H</mi>
              <mo>&#x2212;<!-- − --></mo>
            </mpadded>
          </munderover>
        </mrow>
        <munder>
          <msup>
            <mrow class="MJX-TeXAtom-ORD">
              <mo stretchy="false">[</mo>
              <mtext>Zn</mtext>
              <msubsup>
                <mrow class="MJX-TeXAtom-ORD">
                  <mo stretchy="false">(</mo>
                  <mtext>OH</mtext>
                  <mo stretchy="false">)</mo>
                </mrow>
                <mrow class="MJX-TeXAtom-ORD">
                  <mn>4</mn>
                </mrow>
                <mrow class="MJX-TeXAtom-ORD">
                  <mspace width="0pt" height="0pt" depth=".2em" />
                </mrow>
              </msubsup>
              <mo stretchy="false">]</mo>
            </mrow>
            <mrow class="MJX-TeXAtom-ORD">
              <mn>2</mn>
              <mo>&#x2212;<!-- − --></mo>
            </mrow>
          </msup>
          <mrow class="MJX-TeXAtom-ORD">
            <mtext>tetrahydroxozincate</mtext>
          </mrow>
        </munder>
      </mtd>
    </mtr>
  </mtable>
 </math>

@u-fischer
Copy link
Member

@davidcarlisle interesting, so perhaps we can more or less support that through math (but we will have to fight against the spec which says that non-math should use Formula and Alt ;-) ). But currently the mathml output is imho unusable as the mhchem commands do not contain the needed luamml support.

@davidcarlisle
Copy link
Member

@u-fischer

But currently the mathml output is imho unusable

yes sure it's work in progress, but I thought this issue was as good as anywhere to post some MathML as a marker for possible extended support later,

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

No branches or pull requests

3 participants