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.

How can I resolve an xkeyvalue from a definition? The code


\define@key{mykeys}{foo}[foo-default]{\def\x{Key 'foo' does nothing}}


fails because foo,bar=key is not recognized as two keys, but only as one key. In other words, xkeyval does not recognize the comma between the keys foo and bar=key. How can I make xkeyval identify the comma correctly?

share|improve this question
Welcome to TeX.sx! –  Peter Jansson Mar 11 '13 at 0:07
Without a default value, foo can't be set without a user value. So I inserted defaults for foo and bar. –  Ahmed Musa Mar 11 '13 at 1:16
add comment

2 Answers

up vote 2 down vote accepted

\setkeys does not expand its second argument, but the error message does so sometimes it's puzzling.

You can define a \setkeysexpanded command:




will work.

The double argument switching is to ease the use of \expandafter.

share|improve this answer
Thanks! I already thought my problem had to do with expansions, but I cound not figure it out correctly. Would it also be possible to achieve this without any auxiliary commands? –  Simon Reich Mar 11 '13 at 0:02
@SimonReich One could redefine \setkeys, but I wouldn't recommend it. Better keeping the things well separated. However, \setkeysexpanded works also with normally specified options. –  egreg Mar 11 '13 at 0:04
Alright, this solution works perfectly well. –  Simon Reich Mar 11 '13 at 0:04
@SimonReich Welcome to TeX.sx! –  egreg Mar 11 '13 at 0:05
add comment

Please accept egreg's answer. Another approach is to define a special key set list that you then use to set a key-value list:

\define@key{mykeys}{set list}{%
  \edef\x{Key 'foo' with value '\detokenize{#1}' does nothing}%
  \edef\x{Key 'bar' with value '\detokenize{#1}' does nothing}%
\setkeys{mykeys}{set list=\kvlist}
share|improve this answer
add comment

Your Answer


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.