# Using collcell package with csvsimple, or datatool

I was trying to compose an answer to Bold one cell in table using CSV reader using the collcell package, and can't seem to get it to work either with the csvsimple tabluar, nor datatool.

With the cvssimple, I get:

Runaway argument?
! Paragraph ended before \collect@cell@arg was complete.
<to be read again>
\par


With the datatool I get:

! TeX capacity exceeded, sorry [input stack size=5000]. \reserved@a ->\def \reserved@a *{\let \@xs@assign \@xs@expand@and@detokenize... l.56 \end{tabular}

! ==> Fatal error occurred, no output PDF file produced!

## Note:

• Apologies for the formatting screw up: But before you attempt to edit it to fix it, see Preview not displaying identical to final post

• The MWE below code compiles fine and produces the output shown above as the cvssimple and datatool tables below do not use the collcell pacakge. In order to attempt to use the collcell package the two tabular column specifications need to be changed from l l to L L so that the \newcolumntype is used.

## Code:

\documentclass{article}
\usepackage{csvsimple}
\usepackage{collcell}
\usepackage{datatool}
\usepackage{booktabs}
\usepackage{xstring}
\usepackage{xcolor}

% Make csv in question
\usepackage{filecontents}
\begin{filecontents*}{scientists2.csv}
name,surname,
Albert,Einstein,
Marie,Curie,
Thomas,Edison,
\end{filecontents*}

\newcommand*{\FormatCell}[1]{%
\IfStrEq{#1}{Curie}{\textcolor{red}{#1}}{#1}%
}%

% Need this so that the header rows is not passed to \collectcell

\newcolumntype{L}{>{\collectcell\FormatCell}l<{\endcollectcell}}

\begin{document}
\noindent
Normal \textbf{tabular}:\par
\begin{tabular}{L L}\toprule
Albert  & Einstein  \\
Marie   & Curie     \\
Thomas  & Edison    \\
\end{tabular}

\bigskip\noindent
{scientists2.csv}{name=\name,surname=\surname}%
{\name & \surname}%

\bigskip\noindent
Using \verb|\DTLforeach|:\par
\begin{tabular}{l l}\toprule
\DTLforeach*{myDB}{\Name=Name,\Surname=Surname}{%
\Name & \Surname \\
}%
\end{tabular}
\end{document}

-
Why not just put the formatting in the body of the loop? Such as \FormatCell{\Surname}. (You may need to expand \Surname first. I can't remember if \IfStrEq performs any expansion.) –  Nicola Talbot Jul 7 '14 at 7:33
@NicolaTalbot:Yeah that is certainly an option as the MWE is presented here. However, this was encountered while solving the linked question in the body of the question where the contents were being read form a file, and it is preferable to leave the formatting out of the actual data. Hence, the desire to have the formatting outside of the body of the table. Hope that makes sense -- this question was posted a while ago... –  Peter Grill Jul 7 '14 at 21:48
Sorry, Peter, I didn't notice the date on the question (or the answer for that matter)! The edit brought it to the top of the active list and I wasn't paying enough attention. –  Nicola Talbot Jul 8 '14 at 7:56

The collcell package (written by me) scans over the tabular content to find the end of the cell by looking for the tokens automatically added by TeX when finding the next & or for \\ etc. I don't think it is compatible with cvssimple, which will add such tokens in a different way I guess, even if it doesn't matter for the typesetting itself.