[Tex/LaTex] How to put chemical formula into subscript with mhchem

mhchem

I would like to put chemical formulas into subscripts/superscripts. For example, $M_\ce{H}$ should denote mass of H atom. However, this fails in recent version of mhchem (4.02)

\documentclass{report}
\usepackage{mhchem}

\begin{document}
\begin{equation}
    M_\ce{H}
\end{equation}

\end{document}

Saying

! Missing { inserted.
<to be read again> 
                   \tex_let:D 
l.6     M_\ce{H}

? q

I know that it used to work in previous version of mhchem (3.07), but adding \usepackage[version=3]{mhchem} doesn't help. Is there some other way how to do it?

Best Answer

Sub- and superscripts should be given in braces if they are not a single token. Whilst some cases do work without this (for example $M_\mathrm{n}$) this is not generally true. Here, the document will work correctly with eh official LaTeX syntax

\documentclass{report}
\usepackage[version=4]{mhchem}

\begin{document}
\begin{equation}
    M_{\ce{H}}
\end{equation}

\end{document}
Related Question