10

I have a property list which associate names with values

name 1 -> value 1
name 2 -> value 2
...

I want to use names from the property list to dynamically create keys. The following code

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\prop_new:N   \l_my_prop 
\prop_put:Nnn \l_my_prop { name1 } { val1 }
\prop_put:Nnn \l_my_prop { name2 } { val2 }

\prop_map_inline:Nn \l_my_prop
  {
    \keys_define:nn { phylogenetictree } 
      {
        #1 .tl_gset:c = \l_#1_tl
      }
  }
\ExplSyntaxOff
\end{document}

gives an error

! Undefined control sequence.
<argument> \l_ 
    name1_tl
l.15   }

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

Why this code isn't working ? Is there a better way to achieve this ?

1 Answer 1

10

You have not given the c-type argument in the correct form: it should (in general) not start with a \ but should be in braces:

\prop_map_inline:Nn \l_my_prop
  {
    \keys_define:nn { phylogenetictree } 
      {
        #1 .tl_set:c = { l_ #1 _tl }
      }
  }

I've also changed .tl_gset:c to .tl_set:c here, as your variable name (\l_...) indicates that it is local not global.

1
  • 2
    Oops ! My mistake. expl3 syntax is very powerful but hard to learn. Is a beginner's guide planned ? Oct 28, 2013 at 8:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .