Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to define a command with key arguments, which stores something in a table with help of the package datatool. My attempt is :

\documentclass[12pt]{scrartcl}
\usepackage{keycommand}
\RequirePackage{datatool}
\begin{document}
  % declare a new table
\DTLnewdb{table}
  % define the command
\newkeycommand{\myCom}[op=1]{%
\DTLnewrow{table}
\DTLnewdbentry{table}{option}{\commandkey{op}}
}
%call 4 times the command
\myCom[op=2] 
\myCom[op=3]
\myCom[op=4]
\myCom[op=5]
% display the content of the table
\DTLdisplaydb{table}

I would expect "2 3 4 5", but i get "5 5 5 5". This is actually a common problem that i encounter regularly with datatools (that somehow "only the last operation is taken into account"), which shows probably that i still don't know how to use it properly... What am i doing wrong here ?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

I checked the datatool manual and found the following note about \DTLnewdbentry (page 32):

The value isn’t expanded by default, but you can change this using the declaration: \dtlexpandnewvalue. This can be localised by placing it in a group, or you can switch back using: \dtlnoexpandnewvalue.

I simply rewrote \myCom:

\newkeycommand{\myCom}[op=1]{%
\DTLnewrow{table}
\dtlexpandnewvalue
\DTLnewdbentry{table}{option}{\commandkey{op}}%
\dtlnoexpandnewvalue
}

Now the output is correct:

Datatool output

share|improve this answer
    
great ! i think, this solves some of my other problems with datatool ! :) –  nicolas roy Jan 9 '12 at 13:25
    
@nicolasroy: glad to hear! :) I updated the code with \dtlnoexpandnewvalue right after the insertion. –  Paulo Cereda Jan 9 '12 at 13:29
    
yes, without \dtlnoexpandnewvalue, one gets some bad errors... –  nicolas roy Jan 9 '12 at 14:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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