# Iterate over all defined PGF keys

Is there a way to iterate over all PGF keys that have been defined previously? My idea is to capture the value of all keys in order to do Proper nesting of tikzpicture environments: Reset all PGF values to their defaults.

EDIT: I imagine something along these lines:

\documentclass{article}
\beginrecordallpgfkeys
\usepackage{tikz}
\endrecordallpgfkeys

\begin{document}
\restoreallrecordedpgfkeys
\end{document}


I wouldn't mind if recording and restoring would use a temporary file.

-

I think an option is to use a macro for setting the keys in the first place \def\setkeysdefault{\pgfkeysset{...}} then is easy to have them reset. Is this a good option? –  Yiannis Lazarides Apr 5 '12 at 13:04
Who would have to implement/maintain \setkeysdefault? –  krlmlr Apr 5 '12 at 15:40
Collecting/saving defined pgf keys should presumably be cheaper than in the case of ltxkeys. In ltxkeys there is a way to iterate over all defined ltxkeys that have been previously defined. Yes, it is expensive but not too expensive. All defined keys and their default/initial values are available at any time in the macro \<prefix>@<family>@intialkeyvalues. This is used to recover all default values of keys at once and to, if needed, reinitialize keys (ie, reset keys to their default values) at any time. –  Ahmed Musa Apr 5 '12 at 17:01