Latest news 2021-06-05: New blog post: Dickimaw Books Site Account.

# Bug Tracker

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

## Description

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
Date: 2019-11-13 00:27:00

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

Thanks for the fix. :-)

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

Ordered list:
[ol]
[li]first item[/li]
[li]second item[/li]
[/ol]

Unordered list:
[ul]
[li]first item[/li]
[li]second item[/li]
[/ul]

You can use the Preview button to review your message formatting before submitting.

🔗Comment from Nicola Talbot 🦜
Date: 2019-11-13 10:38:00

You're welcome :-)

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

Ordered list:
[ol]
[li]first item[/li]
[li]second item[/li]
[/ol]

Unordered list:
[ul]
[li]first item[/li]
[li]second item[/li]
[/ul]

You can use the Preview button to review your message formatting before submitting.

Name (optional):

Are you human? Please confirm the bug report ID (which can be found at the top of this page) or login if you have an account.

Comment:

You can use the following markup:

Block:

[pre]Displayed verbatim[/pre]
[quote]block quote[/quote]

In line:

[tt]code[/tt]
[file]file/package/class name[/file]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url] [sup]superscript[/sup]
[sub]subscript[/sub]

Ordered list:
[ol]
[li]first item[/li]
[li]second item[/li]
[/ol]

Unordered list:
[ul]
[li]first item[/li]
[li]second item[/li]
[/ul]

You can use the Preview button to review your message formatting before submitting.