4

I have the following MWE:

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{expl3}
\usepackage{xparse}

\ExplSyntaxOn

\begin{document}

\keys_define:nn { examplea } {
  foo .tl_set:N = \l_examplea_foo_tl,
  baz .tl_set:N = \l_examplea_baz_tl
}

\NewDocumentCommand\examplea{m}{
  % \group_begin:
    \keys_set:nn { examplea } { #1 }
    \typeout{\l_examplea_foo_tl}
    \typeout{\l_examplea_baz_tl}
    \prop_put:Nnn \my:ns {foo} { \exp_after:wN \l_examplea_foo_tl }
    \prop_put:Nnn \my:ns {baz} { \l_examplea_baz_tl }
  % \group_end:
}

\prop_new:N \my:ns

\examplea{foo=bar,baz=asdf}

\prop_show:N {\my:ns}

\end{document}

And it outputs some helpful stuff so we know it got the values at least. However it also errors:

bar
asdf
The property list \my:ns contains the pairs (without outer braces):
>  {foo}  =>  {\exp_after:wN \l_examplea_foo_tl }
>  {baz}  =>  {\l_examplea_baz_tl }.
<recently read> }

l.32 \prop_show:N {\my:ns}
?
(./index.aux) )
No pages of output.
Transcript written on index.log.
Error 1

Actually I think the error may just be caused from \prop_show:N {\my:ns}. Anyways

The question is, how to expand the variables \l_examplea_foo_tl and \l_examplea_baz_tl so it instead logs this:

The property list \my:ns contains the pairs (without outer braces):
>  {foo}  =>  {bar}
>  {baz}  =>  {asdf}.

Or if it is supposed to work like this, and the expansion is supposed to be done when getting the value by key, that would be helpful to understand how to do.

5

You want to store the value of the token list variable:

\documentclass[a4paper]{article}

\usepackage{expl3}
\usepackage{xparse}

\ExplSyntaxOn

\begin{document}

\keys_define:nn { examplea }
 {
  foo .tl_set:N = \l_examplea_foo_tl,
  baz .tl_set:N = \l_examplea_baz_tl
 }

\NewDocumentCommand\examplea{m}
  {
    \keys_set:nn { examplea } { #1 }
    \typeout{\l_examplea_foo_tl}
    \typeout{\l_examplea_baz_tl}
    \prop_put:NnV \l_examplea_main_prop {foo} \l_examplea_foo_tl
    \prop_put:NnV \l_examplea_main_prop {baz} \l_examplea_baz_tl
  }

\prop_new:N \l_examplea_main_prop

\examplea{foo=bar,baz=asdf}

\prop_show:N \l_examplea_main_prop

\end{document}

Please, note the correct naming of the variables. Here's the console output:

bar
asdf
The property list \l_examplea_main_prop contains the pairs (without outer braces):
>  {foo}  =>  {bar}
>  {baz}  =>  {asdf}.
  • Is then naming of the variables convention or does it cause them to be parsed/treated specially internally? – Lance Pollard Mar 24 '18 at 17:44
  • 1
    @LancePollard Conventional, but sticking to the convention helps in avoiding conflicts and should help in reading the code. – egreg Mar 24 '18 at 17:49

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.