[Tex/LaTex] Weird pdfLaTeX+babel+color bug, Missing = inserted for \ifnum

pdftex

I let the MWE speak for itself.

\documentclass{minimal}
% remove babel and it works
% remove one language and it works
% reorder the languages and it works
\usepackage[italian,spanish,UKenglish]{babel}
% remove the color package and it works
\usepackage{color}
\begin{document}
hi
\end{document}

which outputs

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian)

(/usr/share/texlive/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
! Missing = inserted for \ifnum.
<to be read again> 
                   \let 
l.400 \newcount\nofMPsegments

Best Answer

This is a complement to egreg's answer

The source of the problem is that etoolbox hence etex will be loaded at a time where < is active. This is not completely catastrophic though, because even with < active, it might well expand to a catcode 12 < hence could work ok in \ifnum tests. However when package color is loaded and used with driver pdftex it then loads support file supp-pdf.mkii for MPS to PDF conversion. This file temporarily modifies the definition of \protect. And the active < then gives something unacceptable to \ifnum.

With only \usepackage[italian,spanish]{babel} and without color there is thus no error.

For some reason spanish.ldf temporarily makes makes < and > active during the time it is loaded by babel at the very end of spanish.ldf. This activity is cancelled for the rest of the preamble until \AtBeginDocument by code executed immediately after babel.sty is loaded. In the order \usepackage[spanish, italian]{babel} the loading of etoolbox which was demanded by italian.ldf at the end of package Babel is thus executed after the code, also at end of package Babel, which resets to unactive the catcodes of the activated characters by spanish (edit: activated at the very end of spanish.ldf itself).

In the order of \usepackage[italian,spanish]{babel} the end of package Babel demands of italian (which include the loading of package etoolbox hence also of package etex) are executed before those of spanish. As a result this is done at a time where < is active. Hence etex definition of \alloc@ is done with an active <. This is recipe for disaster although as seen above in some circumstances it may remain hidden, becasue the active < still will extend to a catcode 12 <.

I do not know enough the innards of Babel, but it appears to me that spanish.ldf should not demand to Babel to reset the catcodes of < and > at the end of loading of babel.sty [snip] but do it him/herself at the end of spanish.ldf... in fact I am not sure spanish.ldf makes any explicit demand of this type what I see is that

  1. it demands to Babel to activate < and >,
  2. then it immediately resets the catcodes to 12,
  3. then at the very last command of spanish.ldf one sees it re-activates < and >.

Babel by default I think resets to 12 the catcodes for the rest of the preamble when the activation was done properly (I do not investigate more, but I tested it in the case of spanish by itself).

Thus, I recommend this issue should be raised to the spanish.ldf and babel.sty maintainers. In fact, it would seem that the \csname activatequoting\endcsname at the end of spanish.ldf might be a bug (perhaps should be from what I understand only \let\es@quoting\activatequoting but not do \shorthandon{<>} ?), as anyhow Babel resets for the rest of the preamble the catcodes to 12.