3

Problem statement

When I try to apply the \MakeUppercase command to a macro whose value is retrieved from a .csv table via \DTLfetch from the datatool package, I get a compilation error.

I am looking for a solution that overcomes this problem.

Minimal (non-)working example (MWE)

\documentclass{article}

\usepackage{datatool}

\DTLloaddb{data}{data.csv}
\def\myvariable{\DTLfetch{data}{Key}{Variable}{Value}}%

\begin{document}

\myvariable\\% This works as expected
\MakeUppercase{\myvariable}% TODO: This breaks compilation

\end{document}

with data.csv consisting of:

Key,Value
Variable,1f.45

Error received upon compilation

Trying to compile the above example results in the following error:

! Illegal parameter number in definition of \reserved@a.
<to be read again> 
                   3
l.11 \MakeUppercase{\myvariable}
1
  • Problem seems to be specific to \DTLfetch - it seems that it is overcome at tex.stackexchange.com/questions/248965/… by using \DTLassignfirstmatch instead (which does not suit my situation, however). I'll amend the original question accordingly.
    – Florian H.
    Commented Jun 2, 2018 at 23:15

1 Answer 1

5

\DTLfetch is not expandable, so it can not work in the argument of \MakeUppercase, even if hidden inside \myvariable.

Instead, you can use \DTLgetvalueforkey to assign the value to \myvariable, then \myvariable contains the actual value instead of the \DTLfetch command and can be used inside of \MakeUppercase:

\documentclass{article}

\usepackage{datatool}

\DTLloaddb{data}{data.csv}
\DTLgetvalueforkey\myvariable{Value}{data}{Key}{Variable}

\begin{document}

\myvariable\\% This works as expected
\MakeUppercase{\myvariable}% This works too.

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .