Using the .code handler to my keys and a private macro, I can easily test whether a key has been set when using pgfkeys. For example:
\documentclass{article}
\newcounter{mytestenvcounter}
\usepackage{pgfkeys}
\makeatletter
\let\ae@mykey@test\relax
\def\ae@get@mykey@test{\ifx\ae@mykey@test\relax{I've not been set.}\else{I am set to:\ae@mykey@test}\fi}
\pgfkeys
{
/ae/mykeys/set/.cd,
mykey/.code = {\def\ae@mykey@test{#1}},
/ae/mykeys/get/.cd,
mykey/.code = {\ae@get@mykey@test},
}
\makeatother
\newenvironment{mytestenv}[1]
{\pgfkeys{ /ae/mykeys/set/.cd, #1}%
\begin{minipage}[t]{2in}%
\stepcounter{mytestenvcounter}\themytestenvcounter.)\hspace*{0.5em}
\pgfkeys{ /ae/mykeys/get/mykey }%
}
{\end{minipage}%
}
\pagestyle{empty}
\begin{document}
\begin{mytestenv}{mykey={testing}}
\end{mytestenv}
\begin{mytestenv}{}
\end{mytestenv}
\end{document}
But in the comments to an earlier question of mine it was suggested that there's a better approach via .initial and testing for an empty value. But, I don't know how to implement this.
This is as far as I know how to get:
\documentclass{article}
\newcounter{mytestenvcounter}
\usepackage{pgfkeys}
\pgfkeys
{
/ae/mykeys/.cd,
mykey/.initial=,
}
\newenvironment{mytestenv}[1]
{\pgfkeys{ /ae/mykeys/.cd, #1}%
\begin{minipage}[t]{2in}%
\stepcounter{mytestenvcounter}\themytestenvcounter.)\hspace*{0.5em}
\pgfkeys{ /ae/mykeys/mykey }%
}
{\end{minipage}%
}
\pagestyle{empty}
\begin{document}
\begin{mytestenv}{mykey={testing}}
\end{mytestenv}
\begin{mytestenv}{}
\end{mytestenv}
\end{document}
I've tried using \pgfkeysifdefined, but that always seems to test positve.
I've also seen the following question and answer, but don't understand how it relates to what I'm trying to do. Additionally, in this particular question and answer, I don't understand why the need to \detokenize and the syntax for the definition of \pgfkeysifstyleempty@i seems incorrect. So, if you're tempted to point me in that direction, I'd greatly appreaciate comments on what's happening there.
But, is it really necessary to define a macro to test for empty values in pgfkeys? To be able to test whether a key has been set or not in the current environment seems to be something rather reasonable. I've poured over the chapter on pgfkeys in the tikz manual. But nothing there seems very promising, other than what I've already mentioned above.




\relax(which might not be the ideal macro to check against as we have learned) we can simply use\pgfkeys@notsetwe can check against. Best would be to create our own handlers for that and an own\ifpgfkeyssetbyuserfor a better interface. – Qrrbrbirlbel Jul 23 '13 at 01:34pgfkeyspackage uses a similar approach for testing for “no value given” (i.e. using a key without a =). I included a special version of the-NoValue-text from yourxparsesolution. One can still do/.expand once=\pgfkeys@notsetbut if a user uses this they should know what they do (or simply use.unset). – Qrrbrbirlbel Jul 23 '13 at 05:13