# tikz pic: no pgfpointanchor possible inside the pic definition [duplicate]

If I use inside the declaration of a tikz-pic the name of a previously defined coordinate, in \pgfpointanchor{}, I get Package pgf Error: No shape namedCOORDis known.

An example of this behavior can be seen below. Where I define two coordinates A and B and then I want to calculate the angle between this two points. But this fails, because in the pic definition latex doesn't know what the coord A or B are.

If I use the same code inside the tikzpicture, it works as expected. What can I do, to enable the defined coords also inside the pic-definition?

\documentclass{standalone}
\RequirePackage{tikz}
\RequirePackage{pgfplots}
\pgfplotsset{compat=1.11}

\tikzset{
Test/.pic = {
\coordinate (A) at (1, 1);
\coordinate (B) at (0, 0);
\pgfmathanglebetweenpoints{\pgfpointanchor{A}{center}}{\pgfpointanchor{B}{center}}
\draw[red] (B) arc[start angle=0, end angle=360, radius=5mm];
\draw[green] (B) arc[start angle=0, end angle=\pgfmathresult, radius=5mm];
}
}
\begin{document}

\begin{tikzpicture}
%original pic, which is not working
\pic[](test1) at (0, 12mm) {Test};

%this is the reference, which is working, but should be replaced by the pic
\coordinate (A) at (1, 1);
\coordinate (B) at (0, 0);
\pgfmathanglebetweenpoints{\pgfpointanchor{B}{center}}{\pgfpointanchor{A}{center}}
\draw[red] (B) arc[start angle=0, end angle=360, radius=5mm];
\draw[green] (B) arc[start angle=0, end angle=\pgfmathresult, radius=5mm];

\end{tikzpicture}

\end{document}


## marked as duplicate by Kpym, TeXnician, Stefan Pinnow, Bobyandbob, SebastianoApr 24 '18 at 8:09

This is a bit annoying part of the pic syntax because all nodes infer a name prefix from the pic name here it is for example test1.

There are a few things you can do but if you are not going to refer to any node in the pic, then scope everything and add [name prefix ..] option to the scope which resets the name prefix

\documentclass[tikz]{standalone}
\tikzset{Test/.pic = {
\begin{scope}[name prefix ..]
\coordinate (A) at (1, 1);
\coordinate (B) at (0, 0);
\pgfmathanglebetweenpoints{\pgfpointanchor{A}{center}}{\pgfpointanchor{B}{center}}
\let\myresult\pgfmathresult
\draw[red,thick] (B) arc[start angle=0, end angle=360, radius=5mm];
\draw[ultra thick, blue] (B) arc[start angle=0, end angle=\myresult, radius=5mm];
\end{scope}
}
}
\begin{document}
\begin{tikzpicture}
\pic[](test1) at (0, 12mm) {Test};
\end{tikzpicture}
\end{document}


• thanks for the fast answer, but what can I do, if I want to refer to a node in the pic? – byteunit Apr 23 '18 at 17:44
• This is not what is in the doc. This looks like a bug : the example of page 254 (v3.0.1a) that precisely describe the name scoping is not working. Following the documentation name prefix .. is supposed to be used to access external nodes from inside (and not the other way). – Kpym Apr 23 '18 at 19:41
• @Kpym That's because external nodes also don't have any prefix. Hence the same thing happens – percusse Apr 23 '18 at 22:46
• @percusse This is a bug that I was not aware, but you were ;) Probably the @cfr's workaround (putting name prefix .. only in the draw) is a better solution. – Kpym Apr 24 '18 at 5:48
• But name prefix .. is not supported in \pgfpointanchor. (or is it?) Because the main problem is, that \pgfpointanchor doesn't see the coordinates. – byteunit Apr 24 '18 at 6:52