Let us start with an example from the pgf manual, version 2.10, page 495:
\pgfkeys{/flat world/.is if=theworldisflat}
\pgfkeys{/flat world=false}
\def\x#1{% code-A
\iftheworldisflat
Flat
\else
Round?
\fi
#1%
}
I have two questions concerning this example.
(1) Can I set \newif\iftheworldisflat within the command \pgfkeys or, better still, get \pgfkeys to declare the boolean for me automatically. The latter is what obtains in xkeyval package.
(2) How do I pass a code (eg, code-A above) directly to the key flat world within \pgfkeys without a de tour? Is this possible? Something like the following appears to me to be better, since it allows the callback to be executed whenever the key is set.
\pgfkeys{%
/my family/my keys/.cd,
keya/.is if={<boolean>}{<callback>},
}
(3) Why did pgfkeys use \edef here:
\def\pgfkeys@non@outer@newif@#1#2{%
\expandafter\edef\csname #2true\endcsname
{\noexpand\let\noexpand#1=\noexpand\iftrue}%
\expandafter\edef\csname #2false\endcsname
{\noexpand\let\noexpand#1=\noexpand\iffalse}%
\csname #2false\endcsname
}
EDIT
What I have tried is for something like the following. I am still thinking of how to optimize the code; that's why I am yet to post it:
\pgfkeys{%
/my family/my keys/.cd,
keya/.is if=boola,
keyb/.is if=keyb, % Acceptable, but why repeat 'keyb'?
% Use 'keyc' as the boolean and allow the user to provide a default value.
% No need to provide a boolean or repeat 'keyc' on the right hand side of '='.
keyc/.is bool={true}{\def\y##1{##1-True-#1}}{\def\y##1{##1-False-#1}},
}
\edefthere is not needed, of course. Change\edefinto\defand remove all\noexpandtokens: it will behave exactly the same. At least if\let,\iftrueand\iffalseare the primitives when the code is executed: I don't think they are ever redefined. – egreg Apr 15 '12 at 22:52