I use datatool to get key-value pairs from a data file into a database. I then retrieve values using a custom command, \varConfig{}.
One of these values is the number 1, saved as a string in the data file.
My command \varConfig{} gives me the number "1" as a string if I use the command in the body of the document.
I want to use that number as an input to another command that generates the path to a file. At the moment I am hard coding it.
\input{\reviewfile{1}{conclusions.tex}}
But simply replacing the 1 with the \varConfig{} command, like this...
\input{\reviewfile{\varConfig{report-number}}{conclusions.tex}}
... gives me the error
illegal parameter number in definition of \reviewfle
How do I avoid this error? I'm guessing it is somehow related to expansion, but I have no idea how to use \expandafter appropriately in this case.
edit: I have tried the solutions at Pass the contents of an \input command to a macro, for example
\expandafter\input\expandafter{\reviewfile{\varConfig{report-number}}{conclusions.tex}}
but that just gives me more errors.
edit: MWE
\documentclass[9pt,notitlepage]{article}
\RequirePackage{datatool}
\DTLsetseparator{:}% Set the separator between the columns.
% import data from test.csv into a database called 'config'
\DTLloaddb[noheader, keys={key,value}]{config}{config.csv}
\newcommand{\varConfig}[1]{%
\DTLgetvalueforkey{\scratchmacro}{value}{config}{key}{#1}%
\DTLifnull{\scratchmacro}{\textbf{ERROR!} key #1 is undefined.}{\scratchmacro}%
}%
% create new command
\newcommand{\reviewfile}[2]{#1/#2}
\begin{document}
\varConfig{block-text}
\begin{table}[!htbp]
\caption{\protect\varConfig{short-text}}
\begin{tabular}{lr}
Name: & \varConfig{block-text} \
\end{tabular}
\end{table}
\varConfig{report-number}
\input{\reviewfile{1}{test.tex}}
%\input{\reviewfile{\varConfig{report-number}}{test.tex}}
\end{document}
the data in config.csv look like this:
short-text: "hello world"
block-text: "this is some long text to see what happens"
report-number: 1
I then have the file 1/test.tex, which is a dummy file containing the text:
THIS IS A TEST

\edef\tmp{\varConfig{report-number}}and then use\reviewfile{\tmp}{...– Rmano Feb 09 '24 at 15:39\hphantom{}. That can never work in a place where you expect a number. Use your \varconfig before the \input and then use\scratchmacroinside the input (untested due to the lack of MWE). – Ulrike Fischer Feb 09 '24 at 15:52\hphantom{}is not required. I had a hard time making \varConfig{} fail gracefully so would be willing to rewrite that if required. – Andy Clifton Feb 09 '24 at 16:40\@dtl@row -> \db@col@id .... – Andy Clifton Feb 09 '24 at 17:12\varConfig{report-number} \input{\reviewfile{\scratchmacro}{test.tex}}works, but then I have a random "1" just in the middle of my page from the \scratchmacro call. How would I supress that? – Andy Clifton Feb 09 '24 at 17:15