# Bug Tracker

ID: 130 🔗 Closed (Fixed) datatool 2.31 2019-05-24 16:05:26 Some tests don't support well \noalign material

## Report

Hello,

Some tests in dataool.sty (2018/12/07 v2.31 (NLCT)) don't support well \noalign material in one of the <true> and <false> clauses. This is because they use \relax to be sure to terminate a <number>, but this is not necessary as what precedes is already a <number> according to TeX's grammar. The \relax, when seen (which depends on which clause is used), makes TeX stop its search for \noalign, which causes a (for instance) subsequent \rowcolor to fail, because \rowcolor expands to something containing \noalign, but that is too late for \noalign to be valid because of the unneeded \relax. For instance, let's have a look at:

\gdef\DTLiflastrow##1##2{%
\expandafter\ifnum
\csname c@DTLrow\romannumeral\dtlforeachlevel\endcsname
=\csname dtlrows@#2\endcsname\relax
##1%
\else
##2%
\fi}%

\dtlrows@DBNAME being a \countdef token, it is already a <number>, therefore the \relax isn't necessary, and is actually harmful because it prevents the attached MWE from working ("Misplaced \noalign" error). Removing the \relax in the appropriate definition of \DTLiflastrow allows that example to work.

Note: both definitions of \DTLiflastrow have the same problem.

I haven't looked at all tests, but at least \DTLiffirstrow seems to suffer from the same problem:

\gdef\DTLiffirstrow##1##2{%
\expandafter\ifnum
\csname c@DTLrow\romannumeral\dtlforeachlevel\endcsname
=1\relax
##1%
\else
##2%
\fi}%


The \relax shouldn't be needed since a space token terminates a TeX <number>. Besides, space tokens are ignored when TeX is looking for \noalign or \omit inside an alignment, therefore such a space token instead of the \relax would allow for the useful case where ##1 contains \noalign material.

FYI, this problem is mentioned here on TeX.SX:

Thanks!

### MWE

\RequirePackage{filecontents}
\begin{filecontents*}{data.csv}
colname
first
second
\end{filecontents*}

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{datatool}

\begin{document}

\begin{tabular}{c}
\rowcolor{orange}%
\DTLforeach*{sample}{\word=colname}{%
\word
\DTLiflastrow{\rowcolor{green}}{%
\DTLifoddrow{\rowcolor{gray!20}}%
{\rowcolor{orange}}%
}%
}
After rows from the CSV file
\end{tabular}

\end{document}


## Evaluation

I've removed \relax from \DTLiffirstrow and \DTLiflastrow in version 2.32 (2019-09-27) but your MWE is missing \\ so it won't work even with the fix. I'm guessing you intended \word\\ in the body of the loop.

Comment from anonymous. 2019-11-13 00:27 GMT

Yes, you guessed right about \word\\: somehow, I forgot the \\ when preparing the MWE---sorry about that.

Thanks for the fix. :-)

Comment from Nicola Talbot. 2019-11-13 10:38 GMT

You're welcome :-)

## Watch This Report

If you supply your name, it will be used in the email greeting, which provides a more personal message, otherwise you'll just get a generic greeting. If you have previously supplied your name when signing up for notifications, you don't need to resupply it unless you want to change it.

If you have previously subscribed to notifications for this report, you can unsubscribe by clicking on the "Stop Notification" button.

The "Confirm Bug ID" field helps to protect against spambots. Please enter the bug ID (which you can find at the top of this page).

Name: (Optional.)