4

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.)

2
  • 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
2
\keys_define:nn { my }
 {
  mykey .code:n =
    \tl_set_eq:NN \curmykey \l_keys_value_tl \keys_set:nn { my } { mykeyaux = #1 } ,
  mykeyaux .choice: ,
  mykeyaux / choice-a .code:n = { spezific ~ code ~ for ~ a } ,
  mykeyaux / choice-b .code:n = { spezific ~ code ~ for ~ b } ,
 }
3
  • Ulrike, if this doesn't work please, let me know, and I will delete it. I can't compile right know, so this is a “theoretical answer”. – Manuel Dec 3 '14 at 14:57
  • 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
  • @UlrikeFischer Those messages and warnings are out of my knowledge, if you want to edit this answer, feel free to do it. – Manuel Dec 3 '14 at 15:06

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.