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


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:


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

1 Answer 1


Add some spaces around the arrow and the plus sign:

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

enter image description here

  • I hope you have tested on LyX 😉
    – Sebastiano
    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
  • 1
    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{}.
    – mhchem
    Oct 31, 2021 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.