You can only name nodes, not arbitrary parts of a drawing. In your example, if you wanted to be able to refer to the ellipse by name, you'd need to create it as a node instead of a plain ellipse. Try replacing your \draw
command with this:
\node[draw=blue,ellipse,name=e1,minimum width=100pt,minimum height=60pt] at (10pt,10pt) {};
To address the second part of your question, I know of no better documentation of TikZ than the PGF manual itself. I've never heard of a short "cheat sheet" that briefly lists TikZ commands along with reminders of their syntax, if that's what you're looking for. Although it might be out there somewhere, at least for the most commonly used ones. You could probably create such a quick reference by extracting lines from the PGF documentation.
Your first case almost works. Where it needs tweaking is that the -- cycle
syntax needs to be given to the \filldraw
command. The second needs a little more work to get it to ... er ... work.
You probably already know this (since you've discovered the soft paths), but I'll explain the mechanics anyway just in case anyone else is listening in. When you give a TikZ command, like \path (0,0) -- (2,2) -- (4,1);
then TikZ translates that in to the underlying PGF commands, which are then used to build a soft path. A soft path is held in a macro (or a series of macros) and is the basic instructions on how the path is built. It is "soft" in that it can still be manipulated, but it is in a very simple format (which makes the manipulation much simpler). When the save path
key is given then TeX saves the current soft path.
When TikZ/PGF are working on a path then there is a "current soft path" which is the one that they are using right at this moment. Any commands that define a path are added to this one. The sneaky bit is that TikZ does not blank the current soft path when it starts, so when a command such as \draw
starts up then it simply appends its stuff to whatever was there already. This is usually the empty path because whenever a path is used (ie rendered) then the current soft path is set to "empty". But it needn't be.
So the command \pgfsyssoftpath@setcurrentpath{\tmppath}
is essentially saying to the next TikZ command (the \filldraw
) "instead of starting with a blank path, start with \tmppath
". But the extension commands have to go through the TikZ system to be processed in to soft path tokens, which is why the -- cycle
has to be on the \filldraw
instead of after the \pgfsyssoftpath@setcurrentpath
.
Now we see why the second doesn't work. The first says "Use \tmppath
" and the second says, "No, use \tmppathII
". So the second wins and we just get the second path. In this case you want to concatenate the paths. If you really just wanted to concatenate them then you could just put one after the other (this needs a little care with expansions, but is perfectly possible). Assuming that \ge@addto@macro
is defined to add the expansion of the second macro to the end of the first then you would do:
\ge@addto@macro\tmppath\tmppathII
\pgfsyssoftpath@setcurrentpath{\tmppath}
\filldraw[color=red,fill=blue] -- cycle;
Where it gets complicated is that you want to join them with a lineto not a moveto. Every soft path starts with an explicit move. You need to swap that for a line. To do this, we need to gobble up the first token of \tmppathII
(which is a \pgfsyssoftpath@movetotoken
) and put \pgfsyssoftpath@linetotoken
in its place.
At this point, I would start thinking, "Wouldn't it be nice if there was a package that did all this for me?". Fortunately, I thought that a while ago and as there wasn't one, wrote it. I've just updated it to do the concatenate with lineto
that is needed.
So go to the TeX-SX Package, download the file spath.dtx
, run pdflatex spath.dtx
, then the following will do what you want:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{spath}
\begin{document}
\begin{tikzpicture}
\path[save path=\tmppath] (0,0) -- (2,2) -- (4,1);
\pgfoonew \patha=new spath(\tmppath)
\path[save path=\tmppath] (6,-2) -- (3,-2);
\pgfoonew \pathb=new spath(\tmppath)
\patha.concatenate with lineto(,\pathb)
\patha.close()
\patha.use path with tikz(line width=3pt,draw=red,fill=blue)
\end{tikzpicture}
\end{document}
(Edit: Got bored and implemented the close
method. The line width=3pt
is to show that the path really does get closed.)
Result:
Best Answer
One way you could address this is to define your own node shapes as described in the PGF/TikZ manual in ยง 107.5 "Declaring New Shapes" and then define e.g.
\mirror
as\node [shape=mirror]
(theshape=
part is optional, but I would recommend it here). However, unfortunately you need to define node shapes using PGF not TikZ commands, which makes the creation of them difficult and doesn't allow you to simply convert an existing TikZ picture into a node shape.