4

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.

krlmlr
  • 12,530

1 Answers1

7

There is no such feature (and it would be way too expensive).

If you need it, you have to record all options "in scope" manually (and you would need to define clearly what "in scope" means).

One way to record options might be the key filtering ability of pgfkeys (which is quite advanced, however).

  • I have enhanced my question a bit. Do you think key filtering could help here? – krlmlr Apr 05 '12 at 13:01
  • 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? – yannisl Apr 05 '12 at 13:04
  • Who would have to implement/maintain \setkeysdefault? – krlmlr Apr 05 '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 05 '12 at 17:01
  • @Ahmed thanks for the note. However, considering the fact that pgf and its child packages rely heavily on the keyvalue interface, I would refrain from activating such a feature by default (perhaps because I do not understand the use-case completely). But you can surely write some sort of custom library which does it. – Christian Feuersänger Apr 06 '12 at 09:14
  • @ChristianFeuersänger: The use case is resetting all PGF values to their defaults upon entering a nested tikzpicture (e.g., when defining a tikzpicture inside a node). See also the linked question. – krlmlr Apr 06 '12 at 20:10
  • Ok... but considering that "default" may be either system-wide or document-wide (i.e. include preamble styles) - or perhaps even section-wide, who knows, you expect something as your beginrecord/endrecord pattern, right? I guess such a feature might be useful, yes. It would be inactive unless explcitly activated - and useful if one needs it. Keep in mind that sometimes, value-inheritance is not a bug, but a feature. – Christian Feuersänger Apr 07 '12 at 10:57