1

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? ;)

Turion
  • 4,622
  • Switch the name broken and brokenbase in the pic definition should make the problem go away. – Jesse Dec 08 '14 at 14:09
  • Something strange is happening here. If you add [alias=BB-A] to the node in pic{brokenbase} it works. This looks like a bug in node naming of pics. – Kpym Dec 08 '14 at 14:48
  • @Jesse yes, if you don't use nasted pics it works. But the problem is with naming nodes in nested pics. – Kpym Dec 08 '14 at 14:54
  • 1
    The to operation needs to know the name of the nodes to link (to define \tikztostart and \tikztotarget). So this bug is the same as the linked question. – Paul Gaborit Dec 08 '14 at 15:13
  • In my case, I can get away with giving the base pic an empty name: \pic () {brokenbase};. – Turion Dec 08 '14 at 18:42
  • @PaulGaborit, but why does to without arguments not need to know? Because it just invokes --? – Turion Dec 08 '14 at 19:38
  • @Turion It is almost that. But a full explanation would not fit in a comment (in fact, with to, the bug only occurs with a named \tikztostart node: in your example, if you permute (-A) and (0,0), all is fine.) – Paul Gaborit Dec 08 '14 at 22:21

0 Answers0