[Tex/LaTex] Mhchem errors in LyX: kernel/command not defined and undefined control sequence

compilation errorerrorslyxmhchemundefined

I'm using MiKTeX (Console) 2.9.6673 on a Windows 10 Pro. Consider the following minimal-not-working-example.

\documentclass{article}

\usepackage{mhchem}

\begin{document}
\ce{H2O}
\end{document}

The document body contains nothing else but \ce{}, and it doesn't compile, throwing tons of errors. I don't understand the problem. I have every required package (mhchem, chemgreek, l3kernel, l3packages). Some errors:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! LaTeX error: "kernel/command-not-defined"
! 
! Control sequence \regex_match:NnTF undefined.
! 
! See the LaTeX3 documentation for further information.
! 
! For immediate help type H <return>.
!............................................... 

l.53 ...nerate_variant:Nn \regex_match:NnTF { NV }

|'''''''''''''''''''''''''''''''''''''''''''''''
| This is a coding error.
| 
| LaTeX has been asked to use a control sequence '\regex_match:NnTF':
| this has not been defined yet.
|...............................................

Here's the complete log (first error on line 375). They all seem to contain something regex-related. What can I do to solve this?

Best Answer

It seems placing \usepackage{l3regex} before \usepackage{mhchem} solves the problem. I'm not sure why l3regex is not included by default by mhchem if it makes use of the former, I didn't have a problem with this before reinstalling MiKTeX.

Related Question