I am using kvoptions for a key-value syntax. However I need a switch syntax for the evaluation. Since boolexpr is problamatic (see here) I use now the other solution of this question.

However the switch is not working as expected (always results in the same value).

This is the code that I use:


\RequirePackage{kvoptions}  % options
\RequirePackage{pdftexcmds} % string comparison


% parallel, stacked


       value >\tplbugs@style< unkown \MessageBreak%

% Print code and result using the key-value syntax
%  #1  is the optional keyval argument
%  #2  is a mandatory argument
%  Do  stuff  with  #2



  • Your key setting is inside a group, so \PrintDemoUsingKeys will never see any change. – Joseph Wright Jan 20 '12 at 22:42
  • @JosephWright: that is right, but even that does not solve the problem. – Matthias Pospiech Jan 20 '12 at 22:55

There are two errors in your macros: you say


and #1 is the optional argument to \PrintDemo, which is by default empty, according to the definition. So nothing is evaluated, of course, if the call is \PrintDemo{whatever}.

But also calling


you'll get a surprise: because of the \begingroup and \endgroup pair, the value of \demo@style will be reverted to the default stacked just after executing \endgroup, so before \PrintDemoUsingKeys is expanded. Thus it should be

%  #1  is the optional keyval argument
%  #2  is a mandatory argument
  %  Do  stuff  with  #2

called as


If you want to call this as \PrintDemo{style=parallel}, just change the definition into

  • Ok, but I want to call it using \PrintDemo{style=parallel}. I copied the code for the optional argument, but can not remember where it is from. – Matthias Pospiech Jan 20 '12 at 22:59
  • @MatthiasPospiech Don't define an optional argument, then. – egreg Jan 20 '12 at 23:04
  • The code is from tug.org/TUGboat/tb30-1/tb94wright-keyval.pdf – Matthias Pospiech Jan 20 '12 at 23:06
  • It works with your code, nevertheless I would like to discuss how the solution of the documentation is supposed to work. – Matthias Pospiech Jan 20 '12 at 23:11
  • @MatthiasPospiech The authors explains clearly that they want to limit the action of setting the keys to that particular instance. If you want to do that, then put \PrintDemoUsingKeys inside the \begingroup-\endgroup pair. – egreg Jan 20 '12 at 23:19

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.