[Tex/LaTex] moderncv and babel spanish cause “Missing \endcsname…” error

babelerrorsmoderncvspanish

When I run the following code it compiles as expected:

\documentclass[%
  11pt
 ,a4paper
 ,sans
]{moderncv}

\moderncvstyle{classic}
\moderncvcolor{blue}

\usepackage[scale=0.75]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%\usepackage[spanish, activeacute]{babel} 

% Personal Data
\firstname{John}
\familyname{Doe}
\title{CV}
\address{city}{state}{country}
\phone[mobile]{+1~(234)~567~890}
\phone[fixed]{+2~(345)~678~901}
\phone[fax]{+3~(456)~789~012}
\email{john@doe.com}
\homepage{www.johndoe.com}
\extrainfo{extrainfo}
\quote{somequote}

\begin{document}

\makecvtitle

\section{First section}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}
\cventry{Prueba}{Alimentación}{alimentaci'on}{}{}{}

\end{document} 

Uncommenting \usepackage[spanish, activeacute]{babel} generates the following error (pasting here only the first part):

! Missing \endcsname inserted. \protect l.22
\phone[mobile]{+1~(234)~567~890} The control sequence marked should not appear between \csname and \endcsname.

If I then comment out the \phone lines (so babel is still uncommented) it runs fine. Furthermore, using babel with another language (e.g. ngerman) and the \phone lines, also works fine.

Can anybody tell me waht's going on? Why can't I have both babel spanish and \phone uncommented?

I use moderncv 1.5.1, Texlive 2012.20120611-5 and Texmaker 3.4 on Linux Mint Debian edition.

Thanks.

Best Answer

The babel module for Spanish redefines \roman to use small caps and in many places moderncv uses \roman for building indexed macros, basically by doing

\csname xyz\roman{counter}\endcsname

which won't work if \roman is redefined in that way.

Solution: add the es-lcroman option when loading babel:

\usepackage[spanish,es-lcroman]{babel}

I'm not sure that activeacute is really necessary with UTF-8 input. I wouldn't use ~ for the phone numbers: a normal space seems sufficient.


A different strategy, if es-scroman is needed, is to patch all the moderncv commands that use \roman:

\documentclass[
  11pt,
  a4paper,
 sans,
]{moderncv}

\moderncvstyle{classic}
\moderncvcolor{blue}

\usepackage[scale=0.75]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish, activeacute]{babel} 

\usepackage{regexpatch}
\makeatletter
\regexpatchcmd*{\endcvcolumns}
 {\c{roman}\cB.tmpiteratorcounter\cE.}
 {\c{romannumeral}\c{c@tmpiteratorcounter}}
 {}{}
\regexpatchcmd*{\cvcolumn}
 {\c{roman}\cB.cvcolumnscounter\cE.}
 {\c{roman}\c{c@cvcolumnscounter}}
 {}{}
\regexpatchcmd*{\collectionadd}
 {\c{roman}\cB.(collection@\cP.2@count)\cE.}
 {\c{romannumeral}\c{csname}c@\1\c{endcsname}}
 {}{}
\makeatother

% Personal Data
\firstname{John}
\familyname{Doe}
\title{CV}
\address{city}{state}{country}
\phone[mobile]{+1 (234) 567~890}
\phone[fixed]{+2 (345) 678 901}
\phone[fax]{+3 (456) 789 012}
\email{john@doe.com}
\homepage{www.johndoe.com}
\extrainfo{extrainfo}
\quote{somequote}

\begin{document}
\makecvtitle

\section{First section}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}
\cventry{Prueba}{Alimentación}{alimentaci'on}{}{}{}

\end{document} 

A request for bug fix should be filed to the maintainer of moderncv. The macros involved are

  1. \endcvcolumns which is defined by \newenvironment{cvcolumns}, where the occurrences of

    \roman{tmpiteratorcounter}
    

    should become

    \romannumeral\c@tmpiteratorcounter
    
  2. \cvcolumn, where the occurrences of

    \roman{cvcolumnscounter}
    

    should become

    \romannumeral\c@cvcolumnscounter
    
  3. \collectionadd (in moderncvcollection.sty), where the occurrences of

    \roman{collection@#2@count}
    

    should become

    \romannumeral\csname c@collection@#2@count\endcsname
    

A similar problem that shows when \moderncvstyle{banking} is used can be solved by adding

\renewcommand*{\maketitlesymbol}{%
    {\quad{\rmfamily\textbullet}\quad}}

The style uses ~~~ instead of \quad and, due to how the Spanish module of babel treats ~, using this in the title breaks the compilation. I believe that \quad or \hspace{...} should be used anyway: leave sequences of spaces to word processors, LaTeX can do better. ;-)