7

When I was looking for the solutions of How to give a name to \pic, I discovored that it looks like that the problem is only with the code of \tikztostart in the to path and not with the \tikztotarget.

Here is a MWE that shows this (the commented commands are "corrected" by replacing the starting node with explicit coordinates).

\documentclass[tikz,border=3mm]{standalone}
\tikzset{
  seagull/.pic={
    % Code for a "seagull". Do you see it?...
    \coordinate (-left wing) at (-3mm,0);
    \coordinate (-head) at (0,0);
    \coordinate (-right wing) at (3mm,0);
    % \draw (-left wing) to [bend left] (0,0);
    \draw (-3mm,0) to [bend left] (-head);
    % \draw (-head) to [bend left] (-right wing);
    \draw (0,0) to [bend left] (-right wing);
  }
}
\begin{document}
  \begin{tikzpicture}%\small\sffamily
    \pic (Emma) {seagull};
    \pic (Alexandra) at (0,1) {seagull};
    \draw (Emma-left wing) -- (Alexandra-right wing);
  \end{tikzpicture}
\end{document}

enter image description here

So my question is: By looking at the difference between \tikztostart and \tikztotarget can we imagine a fix up ?

Note : I'm not looking for workaround, because in the originals question we can already find : the use of name prefix .., or the replacement of named by explicit coordinates using let ....

Kpym
  • 23,002
  • 1
    Well I think this is actually a corollary of the same bug. This also works \draw (-left wing) -- (0,0); It is related to how the nodes names are collected. – percusse Apr 25 '18 at 16:18
  • @percusse I have no problems with --. Only to paths with named start coordinate throw errors. Your example do not present the bug when I test it. – Kpym Apr 25 '18 at 23:04
  • Yes we should find a different canonical example that fails all the time. It is intriguing indeed. – percusse Apr 26 '18 at 10:58

1 Answers1

2

This is not a full answer but to tell you that I do not think it has to do with \tikztostart vs. \tikztotarget. Rather, I share the opinions of @cfr, @Symbol 1 and @percusse. In more detail, I think that it is just a coincidence that your code works, it does simply because the parsing starts from \tikztostart.

The only very modest improvement to @cfr's great workaround is that you do no longer have to type seagull=.

\documentclass[a4paper]{ltxdoc}
\usepackage{tikz}
\begin{document}
\tikzset{ 
  seagull/.pic={
    \coordinate (-left wing) at (-3mm,0);
    \coordinate (-head)      at (0,0);
    \coordinate (-right wing) at (3mm,0);
    \xdef\myname{\pgfkeysvalueof{/tikz/name prefix}}
    \draw[name prefix=]  (\myname-left wing) to [bend left] (\myname-head) to [bend left] (\myname-right wing);
  }
}

\tikz {
  \pic (Emma)               {seagull};
  \pic (Alexandra) at (0,1) {seagull};

  \draw (Emma-left wing) -- (Alexandra-right wing);
}

\end{document}

I also think that this should not be necessary. In particular, I copied the preamble from the pgfmanual, i.e. loaded all the libraries, and then just made a document with the example from the bottom of page 254. And it failed. But the pgfmanual does compile, doesn't it?

What is also suspicious is the seemingly superfluous (0,0) in

\draw (-left wing) to [bend left] (0,0) (-head) to [bend left] (-right wing);

in the manual. Why was that added?

  • Thanks but I do not agree with your analysis : as you can see in my example the problem arrives with only one named \tikztostart. And you can check that with two named \tikztotarget there's no problem. And by the way, as I note in my question, I'm not looking for workaround. – Kpym Apr 25 '18 at 14:51
  • @Kpym I am sorry, I disagree. I think that this is just a coincidence because parsing goes from start to target. –  Apr 25 '18 at 14:58
  • @Kpym I have restored a modified version of my answer. I understand that you may not like it, but IMHO the fact that you've presented a code that does not fail does not really prove that the issue is due to \tikztostart. There are many possible other explanations for this, and I think that this is simply due to the parsing order. You can check this by replacing your code by \draw (-3mm,0) to [bend left] (-head) to [bend left] (-right wing);. Then for the second leg (-head) is also a \tikztostart node/coordinate, but it still works. –  Apr 26 '18 at 20:31