[Tex/LaTex] Why “Missing \endcsname inserted.” when importing a csv with csvsimple with babel set to spanish

babelcsvsimplespanish

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}
n,pibreal,pibnom,deflactor,c,isr,trc,tdeflactado,trcdeflactado,I,x,m
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%
  \csvreader{test.csv}{}%
  {\\ \hline \csvcoli & \csvcoliii & \csvcolv}%
\end{tabular}

\end{document}

But this doesn't:

\documentclass{article}

\usepackage[spanish]{babel}

\usepackage{filecontents}
\begin{filecontents*}{test.csv}
n,pibreal,pibnom,deflactor,c,isr,trc,tdeflactado,trcdeflactado,I,x,m
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%
  \csvreader{test.csv}{}%
  {\\ \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.

Best Answer

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}
n,pibreal,pibnom,deflactor,c,isr,trc,tdeflactado,trcdeflactado,I,x,m
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}{}{}
\xpatchcmd{\set@csv@autohead}{\roman}{\standardroman}{}{}
\xpatchcmd{\set@csv@head}{\roman}{\standardroman}{}{}
\xpatchcmd{\set@csv@nohead}{\roman}{\standardroman}{}{}
\makeatother

\begin{document}

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

\end{document}

enter image description here