TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I try to use the pgfkeys package. Hereafter there is a short example of a simple command which use pgfkeys. I would like to know why the containts of a variable is not considered in a same way in the case of it is a mandatory argument of the command and in the case it is a option.

As you can see below, if I use #2 or \prop I do not obtain the same output.



    /prop/.default = {age,ville,couleur}

    I am \prenom{} \nom{} !


    \#2 contains : #2


    prop contains : \prop


    If I use \#2 I get :\\
    \foreach \item in {#2} {
        \item \\


    If I use prop option I get :\\
    \foreach \item in {\prop} {
        \item \\

\qui[prenom = toto, nom = titi, prop = {29,perpignan,bleu}]{29,perpignan,bleu}

enter image description here

share|improve this question
If you want to use \foreach to cycle over a comma separated list that's stored in a macro, you'll need to use \foreach \item in \prop (without the {...}). If it's stored in a macro argument (like #2), you do need the {...}. Is that what you're asking? – Jake Dec 5 '12 at 13:51
Yes it was that. But strangely I thought I had already tested this ... – Ger Dec 5 '12 at 14:11
You can use /nom/.store in = \nom, etc, to just save a value in a macro. This is a little less writing. – Ryan Reich Dec 5 '12 at 14:59

You see similar things with most loop macros. If you go

  \foreach \item in {a,b,c}

then the loop will spin three times with \item being set to a on the first time.

If you go

\foreach \item in {\prop}

The loop will just spin once, with \item being defined to be \prop and only later expanding to a,b,c when the item is used.

share|improve this answer
...and if you use \foreach \item in \prop, the loop will spin three times again... – Jake Dec 5 '12 at 14:00
Yes saw that in your top comment after I posted, you have the advantage of having used pgfkeys I suspect:-) – David Carlisle Dec 5 '12 at 14:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.