# keyreader: How to save choice key value to a macro

Why does a choice key not save it’s value to a macro as a cmd key and as the corresponding xkeyval \define@choicekey do?

In the following example I have to define my@key manually by using the callback.

\documentclass{article}

\krddefinekeys*{CL}[my]{%
choice/keya/one/
one,two,three/\def\mykeya{#1};
choice/keyb/aa/
aa,bb,cc,dd;
}

\begin{document}
\mykeya% works
and
%\mykeyb% doesn't work
\end{document}


With xkeyval it is possible to define a bin i.e. a macro that saves the value:

\define@choicekey*{CL}{keyc}[\mybin]{alpha,beta,gamma,epsilon}[alpha]{}


an later \mybin holds the value of keyc

-

The command \define@choicekey of the xkeyval package doesn't yield a macro of the form \<macro-prefix>@<key-name> to hold the user input. The command \krddefinekeys of the keyreader package uses xkeyval's \define@choicekey in the background.

The feature you're asking for is available only in the ltxkeys package. Try the following:

\documentclass{article}
\usepackage{ltxkeys}
\makeatletter
\ltxkeys@declarekeys*{fam}[my]{%
% choice/<key name>.{<alternate values>}/<default>/<callback>;
choice/keya.{one,two,three}/one;
choice/keyb.{aa,bb,cc,dd}/aa;
% cmd/<key name>/<default>/<callback>;
cmd/keyc/cc/\def\xc##1{##1xx#1};
}
\makeatother

\begin{document}
\mykeya, \mykeyb\space and \mykeyc
\end{document}

-
But I can define a bin to save the value, please see my edit. Thath’s what I meant but had it wrong in my mind O:-) –  Tobi Mar 4 '12 at 2:34
Yes, you can define two bins \bina (to hold current user value) and \binb (to hold the numerical order of the user input, starting from 0). Your \mybin is well placed. NOTE: It is advisable to always provide a key prefix (eg, [TOB]) and a family (eg, {tobi}). –  Ahmed Musa Mar 4 '12 at 3:19
OK. But I can’t define a bin with \krddefinekeys right?. Why is it better to define a prefix? And why it this argument optional, though? –  Tobi Mar 4 '12 at 12:20
I have uploaded onto CTAN a version of keyreader package that allows macro prefixes to be used in \krddefinekeys for choice keys (like it has always been for command keys). It will take perhaps 24 hours before the upload is propagated to mirror sites. So for a choice key keya, you can now have \mykeya as you wanted. Note: Providing both key prefix and family makes your keys unique and reduces the chances of name clashes within and between packages. The default value of key prefix is often KV. –  Ahmed Musa Mar 4 '12 at 16:03
Thanks for the upload! I’ll do my update tomorrow. But if I define a <mpprefix> (\my) in my example the prefix isn’t uses anywhere, is it? –  Tobi Mar 4 '12 at 17:22