29

Sometime, for example in a solution to a recent question, one wants to apply a postaction (like a decoration) to a group of paths. A naive solution is to use every path/.style={}. Unfortunately this also this then applies the postaction to every path drawn in the postaction, leading to an infinite regress.

Is there any way to avoid this?

A somewhat stupid minimal example of the problem:

\begin{tikzpicture}[every path/.style={postaction={draw}}]
    \draw (0,0)--(1,0);
\end{tikzpicture}

with error message

! TeX capacity exceeded, sorry [grouping levels=255].
\pgfutil@g@addto@macro #1#2->\begingroup 
                                         \toks@ \expandafter {#1#2}\xdef #1{...
l.12     \draw (0,0)--(1,0);
4
  • 3
    Let's see if a bounty can get this question answered.
    – Seamus
    Nov 12, 2010 at 13:29
  • @seamus: much to me surprise it did. :)
    – Caramdir
    Nov 14, 2010 at 16:44
  • 2
    (I only did it to get the badge for posting a bounty on someone else's question, but I actually feel like I've helped make the site better, a little bit...)
    – Seamus
    Nov 16, 2010 at 11:31
  • @Seamus: fair enough, it did work. :) Nov 16, 2010 at 18:45

3 Answers 3

28
+100

Please check if the following solves your problem, in particular with regard to scoping, this seems far too easy. nomorepostactions is intended to locally empty out the postactions, so they don't get applied after that.

It did fix your toy problem.

\makeatletter
\tikzset{nomorepostaction/.code=\let\tikz@postactions\pgfutil@empty}
\makeatother
[...]
\begin{tikzpicture}[every path/.style={postaction={nomorepostaction,draw}}]
    \draw (0,0)--(1,0);
\end{tikzpicture}
4
  • works fine, indeed: tex.stackexchange.com/questions/3161/…
    – Grigory M
    Nov 14, 2010 at 10:13
  • 1
    Thanks a lot. I didn’t know about .code. That might be useful in other situations too.
    – Caramdir
    Nov 14, 2010 at 16:54
  • 1
    Fantastic! I also didn't know about the .code and have just looked it up in the manual (p383 in v2.00). I can think of lots of things to do with this! (Having small kids, I also like the example for the .store in handler). Nov 14, 2010 at 18:01
  • 1
    @Andrew With small children it may be better to evaluate what happened first, which is why .estore in may be the preferred option.
    – user10274
    Jan 14, 2012 at 22:40
2

Maybe this answer on "How to draw an arrow in the middle of the line?" might help you. This way you do not run into a recursion.

1
  • 6
    The point was that in my answer to the question you reference, one needs to add [postaction={decorate}] to every path by hand which in larger examples adds a lot of copy&pasted code. And copy&pasting code is usually bad design.
    – Caramdir
    Oct 10, 2010 at 16:03
2

(Not an answer.)

Usually one can override properties, but is there a way to remove 'postaction' completely? I mean, there should be a way to write something like [every path/.style={postaction={nopostaction}},nopostaction/.style={draw, <some way to override postaction option>}], probably.

(Related: Is it possible to clear tikz/pgf options?)

3
  • Interesting approach. I don’t know what to write in place of <some way to override postaction option> though. Setting a postaction inside a postaction seems to get ignored.
    – Caramdir
    Nov 13, 2010 at 17:15
  • In the original example even replacing postaction={draw} by postaction={} leads to an infinite recursion.
    – Caramdir
    Nov 13, 2010 at 17:20
  • (Re: ..even replacing..) Of course: postaction={<options>} creates a copy of the original path with these <options> added -- in this case without any additional options -- but a path is created anyway. So one really have to remove the key, not just make it empty. (Or so it seems.)
    – Grigory M
    Nov 13, 2010 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .