Using pgfkeys
, I automatically build some subkeys when an unknown key is encountered. See MWE below.
I would like to avoid having to set the test
key (which is what fires the .unknown
handler) before accessing the subkeys, ie. make it implicit. Is this possible?
\documentclass{article}
\usepackage{pgfkeys}
\usepackage{etoolbox}
\newcommand\buildkeys[1]{%
\pgfkeys{%
/mypath/#1/a/.initial=N/A,
/mypath/#1/b/.initial=N/A,
}
}
\pgfkeys{%
/mypath/.unknown/.code={%
\expandafter\buildkeys\expandafter{\pgfkeyscurrentname}%
}
}
\pgfkeys{%
/mypath/.cd,
test, % Needed to fire the .unknown handler. I would like to avoid this
test/a=test a,
test/b=test b,
}
\begin{document}
should be "test a": \pgfkeysvalueof{/mypath/test/a}
should be "test b": \pgfkeysvalueof{/mypath/test/b}
\end{document}
test/a
there is no check whethertest
exists first. That is deliberate, because for many keys in PGF the parent key doesn't exist and it would be really wasteful (or even harmful) to fire.unknown
in all of these situations.\mykeys[2]
macro that builds the keys under#1
, then sets them from#2
..initial
here correct? I would prefer to have them "undefined" if nothing is set by the user\pgfkeys{a/.initial=}
(or\pgfkeys{a/.initial={}}
if you wish) should define it to be empty.