Using pgfkeys, suppose that I have a key whose value is a comma separated list:
\pgfkeys{/a list/.initial = {1,2,3}}
Question What is the correct way to iterate over this list using \foreach
(from pgffor)?
The only way that I have found that works is to forcibly extract and expand the key value with something like:
\edef\alist{\pgfkeysvalueof{/a list}}
\foreach \a in \alist {A = \a\newline}% works!
This works but is ungainly as it shouldn't be necessary to extract the value of a key into a temporary variable in order to use it. My initial thought/hope was that something like
\foreach \a in \pgfkeysvalueof{/a list} {a = \a\newline}
would work, but this gives an error (! Argument of \pgfkeysvalueof has an extra }.
)
Is there an "officially sanctioned" pgf approach for looping over a comma separated list that is the value of a pgf key? I initially got excited when I found the .list
handler. It is not unlikely that .list
does give a way of doing what I want but for the life of me I can't figure how to use it!
Bonus question Give an example showing what the .list
handler does.
Here is full MWE:
\documentclass{article}
\usepackage{pgfkeys,pgffor}
\pgfkeys{/a list/.initial = {1,2,3}}
\begin{document}
\edef\alist{\pgfkeysvalueof{/a list}}
\foreach \a in \alist {A = \a\newline}% ugly, but works!
%\foreach \a in \pgfkeysvalueof{/a list} {a = \a}% does not work
\end{document}