I have become quite fond of using TikZ pics, but sometimes I run into some unexpected behaviour.
As far as I know, if you define coordinates like (-A), (-B),... inside a pic and draw the pic later as \pic (yourname) {pictype};, you can access them as (yourname-A), (yourname-B), and so on, which is quite convenient if you want to build a base/scaffolding pic on which you add more stuff in subsequent pics.
But sometimes this breaks in unexpected ways:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{
brokenbase/.pic={
\node (-A) at (0,0) {};
\draw (-A) to[in=0] (0,0);
},
broken/.pic={
\pic (B) {brokenbase};
},
works/.pic={
\node (-A) at (0,0) {};
\draw (-A) to (0,0);
},
worksbase/.pic={
\pic (B) {worksbase};
}
}
\tikz{\pic {works};}
\tikz{\pic {broken};}
\end{document}
I've implemented the same thing twice here: A base pic that draws an empty node and then a to-path from the node to the origin. If I don't give any arguments to the to-path, this works. If I give an in or out argument, it fails with this error:
Package pgf Error: No shape named BB-A is known.
I have heard of a similar bug here: TikZ: Named nodes in nested `pic`s
But I don't think my problem is exactly the same since it goes away once you don't give to any options or use a usual -- path.
P.S.: It seems it would make some sense to have "pic inheritance" in an OOP sense. Anyone up to implement that? ;)
brokenandbrokenbasein the pic definition should make the problem go away. – Jesse Dec 08 '14 at 14:09pic{brokenbase}it works. This looks like a bug in node naming of pics. – Kpym Dec 08 '14 at 14:48tooperation needs to know the name of the nodes to link (to define\tikztostartand\tikztotarget). So this bug is the same as the linked question. – Paul Gaborit Dec 08 '14 at 15:13\pic () {brokenbase};. – Turion Dec 08 '14 at 18:42towithout arguments not need to know? Because it just invokes--? – Turion Dec 08 '14 at 19:38to, the bug only occurs with a named\tikztostartnode: in your example, if you permute(-A)and(0,0), all is fine.) – Paul Gaborit Dec 08 '14 at 22:21