EDIT:
Juan have a great approach when the coordinates can be know since before drawing the whole picture. But sometimes there are complex paths with relative positions which may require that the coordinates are created in the middle of the path.
Original question:
How may I hide or not show a pic but still have it calculate the internal coordinates/nodes?
Here I draw blue lines from the origin to every internal coordinate of the pic. My current solution is by having the command opacity=0 for the scope of the picture:
But it does not hold when any internal drawing of the pic has its opacity changed as it overrides the opacity=0 command:
\fill[fill=yellow,opacity=0.5] (0,0) rectangle (-1,-1) coordinate (-point 2);
\documentclass[margin=1cm]{standalone}
\usepackage{tikz}
\tikzset
{
draw it/.store in=\drawit,
draw it=1,
random symbols/.pic=
{
\begin{scope}[opacity=\drawit]
\draw (1,-1) -- +(0,1) coordinate (-point 1);
\fill[fill=yellow] (0,0) rectangle (-1,-1) coordinate (-point 2);
\node[draw,minimum size=1cm] (-point 3) at (-1,1) {a};
\path (0,0)
-- ++(1,1)
edge[red] coordinate[pos=1] (-point 4) +(-1,0);
\end{scope}
}
}
\begin{document}
\begin{tikzpicture}[x=2cm,y=2cm]
\path[draw it=1] pic (thepic) at (0,0) {random symbols};
\draw[blue,very thick] (0,0)
edge (thepic-point 1)
edge (thepic-point 2)
edge (thepic-point 3)
edge (thepic-point 4);
\end{tikzpicture}
\end{document}




github. There's an example at https://github.com/loopspace/tikzmark/blob/master/tests/piclocation.tex – Andrew Stacey Aug 20 '21 at 16:55wrap picandpic anchor. Am I missing something? – Robin Hellmers Aug 20 '21 at 17:01tikzmark.dtxand runtex tikzmark.dtxto generate the latest version of the library. – Andrew Stacey Aug 20 '21 at 17:03