I am trying to understand the naming behavior of paths inside a pic
definition. Consider the following
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\tikzset{%
path1/.pic={%
\coordinate (-p) at (-0.5,-0.5);
\draw[red, name path=-horz-fails] (-1,0.5) to (1,0.5);
\draw[black, name path=-vert] (0,-1) to (0,1);
};
}
\tikzset{%
path2/.pic={%
\draw[blue, name path=-horz] (-1,0) to (1,0);
};
}
\begin{document}
\begin{tikzpicture}
\pic [name=p1] at (0, 0) {path1};
\pic (p2) at (0, 0) {path2};
\draw [name intersections={of=-vert and -horz}]
(intersection-1) circle (2pt) to (p1-p);
%\draw [name intersections={of=-vert and -horz-fails}]
% (intersection-1) circle (2pt);
\end{tikzpicture}
\end{document}
In this example, all four lines are correctly drawn. Further, the uncommented intersection is correctly drawn; however, if I uncomment the second intersection, I get get the compiler error
! Package tikz Error: I do not know the path named `-horz-works'. Perhaps you
misspelt it.
From my searches, I came across this question and the associated bug report from the answer. As with that answer, the last path named in the pic
is available outside the definition. I thought this might be related, but I cloned the repository and tried compiling with the fix, but I still get the same result. I also tried to use name path ..
, but that did not make the path available in the main picture environment.
My question is: Is this a manifestation of the same bug? If not, what are the naming rules for paths inside a pic
definition?
I notice that the coordinate (-p
here) inherits the pic
name outside scope of the pic
as I expected and I would like to reference the path in the same manner.
Motivation
My ultimate goal is to draw a line to the intersection of two paths defined inside a generated pic
. I have some Python code that generates the lines of latitude and longitude along a sphere. I would like to use the pic
multiple times within a single picture; thus, I would like to refer to the paths with the parent pic
name to compute only those intersections that will further what I am trying to show. Since I am computing the paths, I could define the coordinates of the intersections, but I would like to let TikZ do the job and that seems like overkill to me.