I'm trying to use \pgfkeys in the following setting:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfkeys}
\begin{document}
\begin{tikzpicture}[%
m1 color/.initial=red,
m2 color/.initial=green,
m3 color/.initial=blue,
]
\foreach \i in {1, ..., 3} {%
\pgfkeys{/tikz/m\i color/.get=\c}
\node at (0, \i) [color=\c] {\i};
}
\end{tikzpicture}
\end{document}
And when I compile it, I get the following error:
! Package xcolor Error: Undefined color `\c '.
If I change the code to not use \i to select the key, i.e.:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfkeys}
\begin{document}
\begin{tikzpicture}[%
m1 color/.initial=red,
m2 color/.initial=green,
m3 color/.initial=blue,
]
\foreach \i in {1, ..., 3} {%
\pgfkeys{/tikz/m1 color/.get=\c}
\node at (0, \i) [color=\c] {\i};
}
\end{tikzpicture}
\end{document}
then it compiles, but now I can't iterate over the keys.
I also noticed that this actually works:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfkeys}
\begin{document}
\begin{tikzpicture}[%
color1/.initial=red,
color2/.initial=green,
color3/.initial=blue,
]
\foreach \i in {1, ..., 3} {%
\pgfkeys{/tikz/color\i/.get=\c}
\node at (0, \i) [color=\c] {\i};
}
\end{tikzpicture}
\end{document}
So what's the problem with the first example?
Just for curiosity, I tried changing m1 color to m1_color, and now it works. Hence, it appears to have something to do with the spaces. But what?
pgfkeysis loaded implicitly bytikzpackage anyway so you don't need to include it externally. – percusse Mar 29 '12 at 14:38