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.
\documentclass[a4paper]{article}
\setlength{\parindent}{0em}
\usepackage{pgfkeys}
\usepackage{pgffor}
\pgfkeys{
/nom/.code=\def\nom{#1},
/prenom/.code=\def\prenom{#1},
/prop/.code=\def\prop{#1},
/prop/.default = {age,ville,couleur}
}
\newcommand{\qui}[2][]{
\pgfkeys{#1}
I am \prenom{} \nom{} !
\medskip
\#2 contains : #2
\medskip
prop contains : \prop
\medskip
If I use \#2 I get :\\
\foreach \item in {#2} {
\item \\
}
\medskip
If I use prop option I get :\\
\foreach \item in {\prop} {
\item \\
}
}
\begin{document}
\qui[prenom = toto, nom = titi, prop = {29,perpignan,bleu}]{29,perpignan,bleu}
\end{document}
\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?/nom/.store in = \nom
, etc, to just save a value in a macro. This is a little less writing.