[Tex/LaTex] Percentage symbol with csvsimple package

csvsimpletables

I'm using package csvsimple to read .csv files. The problem is, in some of the cells I have percentages, like:

a,b
1,10%
3,16%

If I leave the %s, everything after the first % is omitted, that is, it's behaving like a comment. If I escape % with \% I get compilation errors.

Example:

\documentclass{minimal}
\usepackage{csvsimple}
\begin{document}
\csvautotabular{tab.csv}
\end{document}

where tab.csv:

a,b
1,2%
2,5%

The same problem happens with datatool package.

Best Answer

You can add the possibility to evaluate some keys, which is not allowed with the default \csvautotabular command.

\documentclass{article}
\usepackage{csvsimple}

\newcommand{\csvloopx}[2][]{\csvloop{#1,#2}}
\newcommand{\csvautotabularx}[2][]{\csvloopx[#1]{autotabular={#2}}}
\newcommand{\respectpercent}{\catcode`\%=12\relax}

\begin{document}
\csvautotabularx[before table=\respectpercent]{tab.csv}
\end{document}

enter image description here

You get a similar effect with datatool by using the \DTLloadrawdb command:

\documentclass{article}
\usepackage{datatool}
\begin{document}
\DTLloadrawdb{tab}{tab.csv}
\DTLdisplaydb{tab}
\end{document}