9

If someone had a good example to explain the nuances between the two handlers, it would be nice!

Alain Matthes
  • 95,075
  • 1
    Alain, could you add some more detail to your question explaining why you think these two handlers are so similar? In my understanding, you use mykey/.store in=\mymacro in order to be able to access the key value by calling \mymacro. The .code handler doesn't allow you to do that. Maybe you could include an example of how you're using these handlers? – Jake Mar 30 '16 at 07:46
  • An example is here : http://tex.stackexchange.com/questions/299272/problem-between-pgfkeys-tikz-and-personal-macro Percusse wrote "I think /.store in handler is better here" and I would like to know why ? – Alain Matthes Mar 30 '16 at 07:53
  • path/key/.code={something} defines, internally, a macro with one argument. It is just like \def\PathKeyCode#1{something}. But .store, on the other hand, is argument-free. – Symbol 1 Mar 30 '16 at 07:56
  • 1
    @AlainMatthes: Ah, I see. So basically the question is: "Are d/.code = {\def\macro@d{#1}} and d/.store in={\macro@d} equivalent, or is one preferable to the other?". Correct? – Jake Mar 30 '16 at 08:02
  • 1
    @Jake Yes it's my problem – Alain Matthes Mar 30 '16 at 08:11
  • Off-topic: It is interesting because the manual more-or-less dismisses .store in as superfluous, saying that you might just as well store the value in the key. But I seem to end up using this all the time. Probably because I don't really understand things properly. (But why is it provided if it is really so unnecessary? Is it bad to use it? I'm really unclear.) – cfr Apr 03 '16 at 02:00

1 Answers1

11

The .store in handler is defined (line 818 of pgfkeys.code.tex) as:

\pgfkeys{/handlers/.store in/.code=%
     \pgfkeysalso{\pgfkeyscurrentpath/.code=\def#1{##1}}}

So, as Jake says in its comment, the two lines below are equivalent:

d/.store in=\macro@d,
d/.code = {\def\macro@d{#1}}

The .store in handler is just a convenience handler defined by the more powerful .code handler.

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
  • so why two handlers to do the same things ? My english is not good enough to understand this kind of subtlety in the pgfmanual ! I love to read the code of pgf but ... – Alain Matthes Mar 30 '16 at 12:11
  • 1
    @AlainMatthes as I see it the .code handler is more general as it allows for arbitrary code while .store in always puts its input in a macro. – cgnieder Mar 30 '16 at 12:18
  • (the definition of .store in actually is a good example as it is defined in terms of .code.) – cgnieder Mar 30 '16 at 12:21
  • @clemens yes it's possible and we can add some extra codes – Alain Matthes Mar 30 '16 at 12:22
  • @Jake I agree with you when the code looks like what I wrote – Alain Matthes Mar 30 '16 at 12:25
  • Paul, finally your lines are equivalent but not .store in and .code. The first one is a special case of the second . .code can be more complex if I understand well all the comments. – Alain Matthes Mar 30 '16 at 12:29
  • 2
    @AlainMatthes I never says that .store in handler and .code handler are equivalent. As Jake says: .store in is just a convenience handler defined by the more powerful .code handler. – Paul Gaborit Mar 30 '16 at 12:43
  • Note that in the def version you have to double as many as possible if /.code goes into nested styles etc. ####1 and so on. Also it is already scoped with the current context. – percusse Mar 30 '16 at 13:08
  • @percusse You are right... but your remark is valid for any \definition. – Paul Gaborit Mar 30 '16 at 13:21
  • You don't need that if you use /.store in – percusse Mar 30 '16 at 13:21
  • @percusse Exact (And I understand better Symbol 1's comment: .store in is argument free) – Paul Gaborit Mar 30 '16 at 13:27