Bug Tracker

ID:130 🔗
Status:Closed (Fixed)
Category:datatool
Version:2.31
Date:2019-05-24 16:05:26
Summary: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:

Color rows with \rowcolor and datatool \DTLforeach loop

Thanks!

MWE

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

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

\DTLloaddb{sample}{data.csv}

\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.

Comments

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 :-)

Add comment or return to search results.

Watch This Report

If you would like to be notified whenever updates are made to this report, please fill in your email address in the box below and click on "Notify Me of Changes" button. (Please ensure the address is valid.) Your details won't be passed on to third parties in line with this site's Privacy Policy.

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).

(Optional.)
E mail:
Confirm E mail:
Confirm Bug ID:

To unsubscribe from all notifications use the notifications page.

Comment

You can append a comment to the report using the form below. Comments are checked first before being added. Any spam or offensive content will be removed first according to this site's Terms of Website Use. Please bear in mind that I develop and maintain free software in my spare time. If you want commerical level support then you can hire a TeX consultant.

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).

(Optional. If provided, it will be shown with the comment.)
Confirm Bug ID:

You can use the following markup:

[pre]Displayed verbatim[/pre]
[tt]monospace text[/tt]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url]

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

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

Click on the Preview button to preview the message.

Return to search results.