I want to pass a key=value pair as the value of another key=value pair. The problem is, that the equal sign gets interpreted by pgfkeys and thus I need to encapsulate it using curly brackets, which in turn prevent pgfkeys to interpret the equal sign (surprise).
The following minimal example doesn't make sense, but it illustrates what I'm trying to do. In reality I try to pass on the key=value pair to another command, which takes key=value pairs.
\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{pgfkeys}
\begin{document}
\newcommand{\mycmd}[1]{%
\pgfkeys{/mykey/.initial=hello}%
\pgfkeys{/mykey2/.initial=world}%
\pgfkeys{#1}%
\pgfkeys{\pgfkeysvalueof{/mykey2}}%
\pgfkeysvalueof{/mykey}%
\pgfkeysvalueof{/mykey2}%
}
\mycmd{mykey2={mykey=test}}.
\end{document}
The error I get is of course: "I do not know the key '\mykey=test' ...". How can I solve this?
Edit:
Thanks to percusse I now use a style for what I'm doing. In the example below mycmdA gives the error 'I do not know the key '/fill/', while mycmdB works. Does anybody know why?
\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{pgfkeys}
\begin{document}
This is a test
\newcommand{\mycmdA}[1]{%
\pgfkeys{/mystyle/.style={##1}}%
\pgfkeys{#1}%
}
\newcommand{\mycmdB}[1]{%
\pgfkeys{/mystyle/.style={}}%
\pgfkeys{/mystyle/.code=\pgfkeys{/style/.style={##1}}}
\pgfkeys{#1}%
}
\mycmdA{mystyle={fill=red}}
\mycmdB{mystyle={fill=red}}
\end{document}
\mycmdA
is equivalent to\pgfkeys{/fill=red}
, which will fail because the key/fill
has not been defined. I don't understand what you are trying to achieve but perhaps you want\pgfkeys{/mystyle/.code=\pgfkeys{/mystyle/##1}}
or\pgfkeys{/mystyle/.cd, /mystyle/.style={##1}}
? The later will still fail because/mystyle/fill
has not been set but at least the error is in the right pgfkeys "directory"