0

The question in short is: Is there a handler to achieve what the low-level \pgfkeysvalueof macro does or should I implement it myself? If so, is the following a reasonable implementation?

\pgfkeysdef{/handlers/.value}{%
    \pgfkeysvalueof{\pgfkeyscurrentpath}%
}

Background / Comments / Line of thoughts / Example

Deeping in the pgfkeys world and trying to understand what is going on behind the scene I started reading the section Key Management of the pgf manual (section 86 at page 946 in the version 3.1.1). Despite that everything is contained in "only" 25 pages, the density of information is definitely high and so the probability for me to have missed some point is quite high. That is why I read some threads here around (1, 2, 3) before/during making some practice.

Still I am a bit surprised of one aspect of the pgfkeys package. From this nice answer it is quite clear that a key can store both an action and a value. And since the = sign is not synonym of assignment, one has to act differently depending on the meaning that the <key>=<value> should have (i.e. is <value> a value or actually something to be given to the action?). Supposing to have a pure value key (i.e. without any action associated), it might make sense to mark its value as required.

\pgfkeys{/my color/.initial = red, /my color/.value required}

At this point, it is not any more true that \pgfkeys{<full path of key>} will retrieve the value, since we are not authorised to use the key without a value. One of the other ways to retrieve the value has to be used. So far so good. Now, despite \pgfkeysvalueof seems the simplest answer in this case, the manual kind of repeatedly warns about the "general no need" to use this kind of low-level commands. For example, at page 948,

Each key (may) store some tokens and there exist commands, described below, for setting, getting, and changing the tokens stored in a key. However, you will only very seldom use these commands directly. Rather, the standard way of using keys is the \pgfkeys command or some command that uses it internally like, say, \tikzset. So, you may wish to skip the following commands and continue with the next subsection.

I also like the use of handlers to stay on a higher level of abstraction. So trying to retrieve the value of the key /my color I looked for a handler, but in my case I do not see any reason to go through a macro (i.e. /.get and /store in are not welcome). And here I realised that no handler to simply retrieve the value seems to be available.

Bonus question:

Is it a good philosophy to try to use handlers exclusively as far as possible? They look to me like an higher level interface and therefore I would say so.


MWE:

\documentclass[border=5mm, varwidth]{standalone}
\usepackage{pgfkeys}

\pgfkeysdef{/handlers/.value}{%
    \pgfkeysvalueof{\pgfkeyscurrentpath}%
}

\pgfkeys{/my color/.initial = red, /my color/.value required}

\begin{document}

    %My color is \pgfkeys{/my color}. %This clearly does not compile
    My color is \pgfkeysvalueof{/my color}.\\
    My color is \pgfkeys{/my color/.value}.

\end{document}
  • 1
    Just for the records: I read your question twice but am completely unsure what you are asking. This might be just me. Yes, My color is \pgfkeys{/my color}. leads to an error. But what do you want to achieve? I see an essay on the philosophy and a bonus question, but unfortunately I was unable to figure out what the non-bonus question is. (I also do not understand the bonus question.) As I said, this may just be me, so this is not to be misinterpreted as a criticism. – user121799 Mar 8 at 17:47
  • Thanks for your comment, if you do not understand what I ask it means I was not clear enough. I try with a different analogy. The key handler .get seems to be analog to the command \pgfkeyslet (or maybe of \pgfkeysgetvalue). However I did not find an handler to achieve the same operation done by the \pgfkeysvalueof and I wonder if one exists. The bonus question is whether I should try to prefer handlers with respect to commands at a lower level. As I wrote, I am trying to deepen into the pgfkeys package and I could have missed many points... – Axel Krypton Mar 11 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.