I need to define a style contained in a macro without expanding this macro.
The problem is that if the macro contains several keys like or sets a value to a key like here:
\def\myconfiguration{text={The value of my great counter is \themycounter}}
it fails because pgfkey tries to first evaluate the macro, and then checks if a key is named text={The value ...}, which of course is wrong.
So what is the good way to define a pgfkey style inside a macro, and make sure that this macro is not expanded at definition time?
MWE:
\documentclass{article}
\usepackage{pgfkeys}
\newcounter{mycounter}
\def\myconfiguration{text={The value of my great counter is \themycounter}}
\pgfkeys{
/prAtEnd/.cd,
% Text
text/.code={\def\sayhello{#1}},
configuration options/.style={
text={The counter value is \themycounter},
\myconfiguration %% This lines fails!
},
}
\begin{document}
\pgfkeys{/prAtEnd/.cd, configuration options}
\sayhello
\stepcounter{mycounter}
\sayhello
\stepcounter{mycounter}
\sayhello
\end{document}
-- EDIT --
I would like to have at the end the same result as if \myconfiguration was replaced with it's definition, i.e. text={The value of my great counter is \number\value{mycounter}}. So the output must be:


The counter value is XwithThe value of my great counter is X(as configured in the\myconfigurationmacro). Basically, you can imagine that you replace the\myconfigurationwithtext={The value of my great counter is \number\value{mycounter}}to get what I want. (see my edit) – tobiasBora May 06 '19 at 18:39configuration optionsin a style, and not in a macro. – May 06 '19 at 18:53\myconfigurationbecause I would like it to be consistent with the remaining configuration that does not require\noexpand. Second, this overwrite all the definitions ofconfiguration options(this may be fixable by using a temporary style, but sounds strange). – tobiasBora May 06 '19 at 19:06kvoptions(this is send to package configuration), and the second time I need to define a "global" style to go though environments, so I use\global\def..., and unfortunately pgfkeys seems to be only local. – tobiasBora May 06 '19 at 19:06\myconfigurationby adding this "\noexpand" which is a bit of "cheating". Indeed, if you copy pastetext={The value of my great counter is \noexpand\number\noexpand\value{mycounter}}}in place of\myconfigurationthe compilation will fail because of the noexpand. So it leads to two "syntax" for a user, depending on whether he is configuring the package (use "noexpand") or directly a style (no "noexpand") which is confusing for him. Is it clearer? Sorry I'm super bud to explain… – tobiasBora May 06 '19 at 20:24\numberand\valuefrom being expanded. Alternatively you could decompose the thing in two pieces: the text and the\number\value{mycounter}bit, which you could store in a code. Would this be an option? – May 06 '19 at 20:34\unexpanded\expandafterexpands only once) so that I can accept your answer ;-) Thanks! – tobiasBora May 07 '19 at 07:30.style/.expandedinto.style/.expand onceand it works exactly as expected! Once you change it I'll accept the answer. Thanks a lot! – tobiasBora May 07 '19 at 09:11