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}
  • 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. Jun 2 '18 at 23:15
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}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.