7

Does anybody know how to fix this problem with mhchem package?

! Undefined control sequence.
<argument> \l__mhchem_cg_isScript_bool 

Recently I've found this part of mhchem.sty code:

\cs_new_protected:Npn \__mhchem_output_escapeFromTextToItalicMath:n #1
  {
    \ensuremath
      {
        \mhchem@hook@beforeItalicMath
        \bool_if:NT \l__mhchem_cg_isScript_bool
          {
            \medmuskip=0mu
            \thinmuskip=0mu
            \thickmuskip=0mu
          }
        #1
      }
  }

It seems to me problem is connected with \bool_if:NT \l__mhchem_cg_isScript_bool condition which can be wrong with newest expl3 package. The same bug has successfully been solved in siunitx package.

Win 10, MikTeX 2.9.6236, up-to-date

9
  • The siunitx problem has been solved because I notified the author: github.com/josephwright/siunitx/issues/311. So if you want to get a fix for mhchem: write to the author. Jul 24, 2017 at 11:10
  • Thank you. I sent him an e-mail with link to forum's question. Seems simple replacement bool<-bool_lazy can't solve this :)
    – Alexey
    Jul 24, 2017 at 11:33
  • Temporary, I make this: code \bool_new:N \l__mhchem_cg_isScript \cs_new_protected:Npn __mhchem_output_escapeFromTextToItalicMath:n #1 { \ensuremath { \mhchem@hook@beforeItalicMath \bool_lazy_any:nT \l__mhchem_cg_isScript { \medmuskip=0mu \thinmuskip=0mu \thickmuskip=0mu } #1 } }
    – Alexey
    Jul 24, 2017 at 11:44
  • The problem is that the boolean is not defined. Probably in the past an undefined boolean was considered false. This is quite likely a left-over from some older version. By the way, setting \thinmuskip to zero is wrong.
    – egreg
    Jul 24, 2017 at 11:48

3 Answers 3

10

The code \bool_if:NT \l__mhchem_cg_isScript_bool {...} was added in version 4.04 of mhchem.sty. However, the addressed boolean variable is nowhere defined.

With previous versions of expl3, such a case was dealt with by considering the boolean as false, now it is not so any longer.

By the way, as there obviously is no way to toggle the boolean's value, the code is completely useless (and it would be so even if the boolean was defined).

Here's a temporary fix, which wouldn't be invalid even after the package author defines the boolean variable.

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

\ExplSyntaxOn
\bool_if_exist:NF \l__mhchem_cg_isScript_bool
 {
  \bool_new:N \l__mhchem_cg_isScript_bool
 }
\ExplSyntaxOff

\begin{document}

$\ce{NO_$x$}$

$\ce{NO_$x+y$}$

\end{document}

enter image description here

7

mhchem v4.07 fixes this bug.

Thanks a lot for reporting this and all your research into that matter. Thanks @egreg! This seems indeed to be a leftover of an experiment I did once and did not completely reverse. And my (wrong) code stopped working with an expl3 update. I will publish an update of mhchem during the next couple of days.

4
  • 5
    Please do not add thank you as answer. Once the update is published you can post an answer showing how it works with the updated version.
    – TeXnician
    Jul 24, 2017 at 16:05
  • @TeXnician This is no thank you answer. It is an "I noticed this and I am working on an update". Am I not allowed to say thank you on the way? --> meta
    – mhchem
    Jul 24, 2017 at 18:44
  • 4
    Well, it is. The appropriate answer would be: "It's fixed in version X (problem was...) and this is how it works..." The rest is commentary.
    – TeXnician
    Jul 24, 2017 at 18:49
  • You can use comments if you need to say thank you not only using the up-vote button. Jul 25, 2017 at 7:26
0

I've fixed it directly in mhchem.sty:

\bool_new:nT \l__mhchem_cg_isScript_bool
\cs_new_protected:Npn \__mhchem_output_escapeFromTextToItalicMath:n #1
  {
    \ensuremath
      {
        \mhchem@hook@beforeItalicMath
        \bool_lazy_any:nT \l__mhchem_cg_isScript_bool
          {
            \medmuskip=0mu
            \thinmuskip=0mu
            \thickmuskip=0mu
          }
        #1
      }
  }
2
  • 4
    The name of a boolean variable should end with _bool. Besides, changing package code is not the best way to solve such issues. On another machine the document would choke again.
    – egreg
    Jul 24, 2017 at 12:40
  • @egreg, Ok. Also, I'm glad to see the author of this package here.
    – Alexey
    Jul 24, 2017 at 14:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .