Latest news 2024-02-16: Experimental (unstable) datatool v2.49a available for testing. Download from the experimental page if you would like to try it out.

Feature Tracker RSS feed

I’m currently working on a major new version of the datatool package. This may take a while. Please be patient. (Experimental version available for testing.)

ID 39🔗
Date: 2016-05-31 09:48:07
Status Closed (Not Implemented)
Category datatool
Summary DTLiflastrow for conditions in foreach

Sign in to subscribe to notifications about this report.


Dear Nicola Talbot,

your datatool-package is very great and helps me in a lot of cases (even with big amounts of data). Sometimes I am iterating through a database with the DTLforeach-command and a condition. The condition leaves some rows out, maybe the last.

Is it possible to have a command within foreach, that can decide wether it will be the last row in the loop and not in the database itself? It seems a little bit complicated, because the DTLforeach seems to read the next row of the database every loop iteration and decides then, if the condition matches. Maybe it is possible to store the output of every iteration with a match of the condition in a savebox (e.g. the box in tcolorbox) and print the savebox when datatool knows, what row will be the last one?



No mwe.tex


Unfortunately I don't think this is possible in general as it would need to look ahead and scan the rest of the database at the end of each iteration to determine if the current row is the last to satisfy the condition, which would be very inefficient. It would be quicker to simply have two loops: the first to determine the final row index and the second to test the current row index against the previously found final row index. It would be even better if the first loop saved a list of the required row indexes and then the second loop iterated over that list (instead of the entire database). An even faster approach would be to use datatooltk to perform the filtering.



Add Comment

Name (optional):

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


You can use the following markup:


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

In line:

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

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

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

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

Page permalink: