# l3keys: how to store the value of a choice key more effectively?

I want to define with l3keys a choice key which also stores the value given to the key. That's easy enough:

\documentclass{article}
\usepackage{expl3}

\ExplSyntaxOn
\tl_new:N \curmykey

\keys_define:nn { my }
{
mykey .choice:,
mykey /choice-a .code:n ={\tl_set:Nn\curmykey{#1}spezific~code~for~a},
mykey /choice-b .code:n ={\tl_set:Nn\curmykey{#1}spezific~code~for~b},
}
\ExplSyntaxOff
\begin{document}

\ExplSyntaxOn
\keys_set:nn{my}{mykey=choice-a,},~\curmykey
\ExplSyntaxOff

\end{document}


But I don't find it very elegant to have to copy the \tl_set:Nn\curmykey{#1} in all the code arguments. Is there any way to define \curmykey only in one place? (I already tried mykey .tl_set:N but this breaks the choice code.)

• I don't understand the question (it's probably me, but if you could rephrase the question or detail it alittle bit more I would appreciate it). In any case, the key name and value are stored in \l_keys_key_tl and \l_keys_value_tl (and there's also \l_keys_choice_tl). I'm not sure what do you want to do. – Manuel Dec 3 '14 at 14:20
• @Manuel: I have two \tl_set:Nn\curmykey{#1} above in the code, and each choice would need one more. I want to avoid this repetition. \l_keys_value_tl is not an option: it holds the value after the setting of the key but as I need it much later on I must store this value in some other command before it is overwritten by some other key. – Ulrike Fischer Dec 3 '14 at 14:37

\keys_define:nn { my }

• Good idea. One should add a specific error message for mykeyaux / unknown .code:n = so that users are not confused when they use unknown choices and get a complain about the key "mykeyaux". – Ulrike Fischer Dec 3 '14 at 15:05