# Reusing TikZ Path Definition

I'd like to know if somebody know a way to define a path in TikZ and reuse the path's definition several times. For example, consider the following:

If I wanted to change the path (0,2) -- (0,2) -- (5,3) -- (5,2) I'd have to make two changes to the code. How can I avoid this?

-
Why not \def it? \def\mypath{ (0,0) -- (5,5)} and then using it \tikz \draw {\mypath};. Not so elegant though. –  percusse Jan 19 '12 at 17:30
@percusse Interesting how obvious the solution sometimes is. I'd never have thought TikZ would be able to parse the definition and expand it. The solution is good enough in the sense that you can keep defs local to a tikzpicture. Interestingly, and this is one of the reasons why I never thought of using a \def, TikZ's name path only seems to work for intersections but not for drawing.... –  Marc van Dongen Jan 19 '12 at 17:49
I've written a library that does exactly this. I've limited internet access right now, though so can't paste much here. If you search this site for spath then you might get some idea of the sort of thing I do with my code. If it looks interesting, tell me and I'll try to see if it could do what you want. –  Loop Space Jan 19 '12 at 23:06
For the interested people this is the question that @AndrewStacey mentions. –  percusse Jan 20 '12 at 1:28
–  qubyte Jan 20 '12 at 2:17

In a limited way, a postaction or a preaction may be viewed as repeated work on a path. For example, in the following code

\begin{tikzpicture}

\fill[postaction={draw=red,->},blue] (0,3) -- (5,3) -- (5,2) -- (0,2) -- (0,3);

\end{tikzpicture}


the path is only entered once, but two actions are performed on it, the fill and afterwards the draw.

Again, this is limited in what you can do, but it saves on reentering a path.

-
@Fr\'ed\'eric Thanks. I have to study this in more detail. (I've never used postactions.) –  Marc van Dongen Jan 19 '12 at 20:44