# Why “Missing \endcsname inserted.” when importing a csv with csvsimple with babel set to spanish?

After figuring out why my MCVE wasn't working as expected, I think I've found a bug in either babel or csvsimple package. This compiles:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{test.csv}
2000,1059317580733.46,393302970000,37.127956446,281965700000,10616220000,437870990000,3941585537.81615,162572550457.059,109702668399.757,139614000000,172276800000
\end{filecontents*}

\usepackage[utf8]{inputenc}
\usepackage{csvsimple}

\begin{document}

\begin{tabular}{|l|r|r|}%
\bfseries Año & \bfseries PIB & \bfseries Consumo privado%
{\\ \hline \csvcoli & \csvcoliii & \csvcolv}%
\end{tabular}

\end{document}


But this doesn't:

\documentclass{article}

\usepackage[spanish]{babel}

\usepackage{filecontents}
\begin{filecontents*}{test.csv}
2000,1059317580733.46,393302970000,37.127956446,281965700000,10616220000,437870990000,3941585537.81615,162572550457.059,109702668399.757,139614000000,172276800000
\end{filecontents*}

\usepackage[utf8]{inputenc}
\usepackage{csvsimple}

\begin{document}

\begin{tabular}{|l|r|r|}%
\bfseries Año & \bfseries PIB & \bfseries Consumo privado%
{\\ \hline \csvcoli & \csvcoliii & \csvcolv}%
\end{tabular}

\end{document}


The only difference is that the later imports the spanish babel package. Using otherlanguage environment to set the language to english allows the compilation, so the problem is between the spanish and csvsimple packages.

The code in csvsimple.sty uses \roman in five places; since \roman is redefined by babel-spanish, this usage breaks.

You can file a bug report to the author and, in the meantime, fix yourself the issue.

\begin{filecontents*}{\jobname.csv}
2000,1059317580733.46,393302970000,37.127956446,281965700000,10616220000,437870990000,3941585537.81615,162572550457.059,109702668399.757,139614000000,172276800000
\end{filecontents*}

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}

\usepackage{csvsimple}
\usepackage{xpatch}

\newcommand{\standardroman}[1]{\romannumeral\value{#1}}
\makeatletter
\xpatchcmd{\csv@breakline@kernel}{\roman}{\standardroman}{}{}
\xpatchcmd{\csv@current@col}{\roman}{\standardroman}{}{}
\makeatother

\begin{document}

\begin{tabular}{|l|r|r|}%
\bfseries Año & \bfseries PIB & \bfseries Consumo privado%

• I have seen in my private code that I already replaced \roman by \romannumeral nearly two years ago. Unfortunately, I did not publish this since I was to concerned with other things (and then I forgot it). But I will provide an update in the near future. – Thomas F. Sturm Jun 29 '16 at 7:09
• @ThomasF.Sturm Lamport's original idea was for\roman to be fully expandable. Alas, even \arabic may be at risk with some exotic language. – egreg Jun 29 '16 at 7:21
• @egreg The LaTeX core never use \roman for that. I don't know what Lamport intended, but neither the LaTeX sources nor the LaTeX book says anything about the expandibility of \roman, \Roman, \fnsymbols and the like, except for \value. Even \Roman was no fully expandable until 1997 (and \fnsymbolstill isn't). On the contrary, they state the numbering commands print the value of a counter, and The LaTeX Comanion (1st ed.) speaks of "visual representation". Using them to generate code is a bad practice, IMO (and thank you, Thomas, for fixing it!), and not endorsed by the docs. – Javier Bezos Jul 4 '16 at 13:44
I've found a post suggesting that the problem is related to how spanish treats roman numbers, and suggest to use es-lcroman and es-ucroman. Only es-lcroman doesn't present the issue, which according to the manual it just ignores roman conversion and allows latex to define them.