# Package mhchem Error while writing chemical equations in Lyx

I am only a beginner with respect to Tex. I have MikTex installed on Windows10, and the following equation works fine in TexStudio.

\ce{2Al(s)+3Cl2(g)->2AlCl3(s)}


However when I import the same tex file into Lyx, I get the following error:

Package mhchem Error: Assertion failed: Unexpected input character. In case


I thought it was the minus sign (-) that was causing the problem, as it has done in other imported docs, but even on re-entering the error persists. I am using \usepackage[version=4]{mhchem} in the preamble. There is no error in plain chemical formulae, e.g. \ce{AlCl3} works fine. I updated MikTex also, but still of no use. The Tex output generated by Lyx seems fine - it is:

$\ce{2Al(s)+3Cl2(g)->2AlCl3(s)}$


Any idea what I am doing wrong while writing the eqn?

Add some spaces around the arrow and the plus sign:

\documentclass{article}
\usepackage[version=4]{mhchem}
\begin{document}
\ce{2 Al(s) + 3 Cl2(g) -> 2 AlCl3(s)}
\end{document}


• I hope you have tested on LyX 😉 Oct 21, 2021 at 21:41
• @leandriis - you are right about adding space. I had space in the original Tex file but on import to Lyx, the space was lost. And in Lyx, in Math mode, there seems to be no way to enter normal space (not Math space, which doesn't help here). The only option I can see in Lyx to retain space is to do Insert -> Tex Code for all chemical eqns. Is there a better way that I am not aware of?
– Siv
Oct 22, 2021 at 7:53
• Spaces are an important part of mhchem's \ce{}syntax. Lyx should not remove them. I guess it doesn't remove spaces from \text{}, it should apply the same logic to \ce{}. Oct 31, 2021 at 17:39