I have a csv file with tags and (page) nrs, as follows:
tag,nr
t1,1
t2,5
t3,9
The nr-column refers to page numbers in a pdf file. Each page has a corresponding tag. Given a tag, I want to show the corresponding page in a figure in my latex document.
With datatools I can load the csv file, and fetch the page nr of a given tag. For example, for tag t2 I get page nr 5.
But now when I feed that page nr as the page=... argument to includegraphics, I get the error message
"! Missing number, treated as zero."`
What extra step should I take to convert the latex 5 string into a page nr that includegraphics can handle?
Here's a simplified version (using counters instead of includegraphics) that triggers the problem:
\documentclass{article}
\usepackage{datatool}
\begin{document}
\DTLloaddb{tags}{prestags.csv}
\newcommand{\pagenr}{\DTLfetch{tags}{tag}{t2}{nr}}
\newcounter{snr}
\addtocounter{snr}{\pagenr}
\end{document}
% Output:
! Missing number, treated as zero.
<to be read again>
\let
l.10 \addtocounter{snr}{\pagenr}
What should I do to fix this?



\DTLgetvalueto define\pagenr. (Sorry, cannot test currently). – cabohah Jan 05 '24 at 15:14\DTLfetchis not expandable. You can use the technique here: retrieving substring of `\DTLfetch` to overcome this. – Alan Munn Jan 05 '24 at 15:45DTLgetvaluein combination withDTLgetlocation. Thedtlcurrentvaluetrick to handle non-expandable results seems nice too. Please feel free to turn your suggestions into answers that I can upvote / accept (I can also do this if that's what you prefer). – avandeursen Jan 05 '24 at 15:51