# \pic without named coordinates

Is it possible to use the \pic command provided by the angles library in tikz, without using coordinates?
If I use something like this, it works correctly.

\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (0,5);
\coordinate (C) at (5,0);

\node [left] at (A) {$A$};
\node [left] at (B) {$B$};
\node [right] at (C) {$C$};

\draw (A) -- (B) -- (C);

\pic [draw] {angle = A--B--C};
\end{tikzpicture}


However, if I use this,

\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (0,5);
\coordinate (C) at (5,0);

\node [left] at (A) {$A$};
\node [left] at (B) {$B$};
\node [right] at (C) {$C$};

\draw (A) -- (B) -- (C);

\pic [draw] {angle = (0,0)--(0,5)--(5,0)};
\end{tikzpicture}


it does not work.

It would be great if I could use this so that I can use points without naming them.

angle expects names, not coordinates. The name argument is directly parsed to \pgfpointanchor, from tikzlibraryangles.code.tex:

\def\tikz@lib@angle@parse#1--#2--#3\pgf@stop{%
% ...
\pgf@process{\pgfpointanchor{#2}{center}}%
\pgf@xa=\pgf@x%
\pgf@ya=\pgf@y%
\pgf@process{\pgfpointanchor{#1}{center}}%
\pgf@xb=\pgf@x%
\pgf@yb=\pgf@y%
\pgf@process{\pgfpointanchor{#3}{center}}%
% ...
}


\pgfpointanchor expects a node name as first argument.

Therefore the library needs heavy patching to support coordinate specifications, too. The following example patches libary angles. The argument of angle needs to be sourrounded by curly braces to hide the comma from the pgfkeys parser:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles}

\usepackage{etoolbox}
\makeatletter
% Helper macros
\def\tikz@lib@angle@def@coord#1{%
\ifx(#1\relax
\coordinate(tikz@lib@angle@tmp)at#1;%
\else
\coordinate(tikz@lib@angle@tmp)at(#1);%
\fi
}
\def\tikz@lib@angle@coord#1{%
\pgf@process{%
\ifx(#1\relax
\tikz@scan@one@point\@firstofone#1\relax
\else
\pgfpointanchor{#1}{center}%
\fi
}%
}
% Patching
\patchcmd\tikz@lib@angle@background{#2}{tikz@lib@angle@tmp}{}{%
\errmessage{Cannot patch \string\tikz@lib@angle@background}%
}
\patchcmd\tikz@lib@angle@foreground{#2}{tikz@lib@angle@tmp}{}{%
\errmessage{Cannot patch \string\tikz@lib@angle@foreground}%
}
\pretocmd\tikz@lib@angle@background{\tikz@lib@angle@def@coord{#2}}{}{%
\errmessage{Cannot prepend \string\tikz@lib@angle@background}%
}
\pretocmd\tikz@lib@angle@foreground{\tikz@lib@angle@def@coord{#2}}{}{%
\errmessage{Cannot prepend \string\tikz@lib@angle@foreground}%
}
\patchcmd\tikz@lib@angle@parse{%
\pgf@process{\pgfpointanchor{#2}{center}}%
}{%
\tikz@lib@angle@coord{#2}%
}{}{%
\errmessage{Cannot patch \string\tikz@lib@angle@parse}%
}
\patchcmd\tikz@lib@angle@parse{%
\pgf@process{\pgfpointanchor{#1}{center}}%
}{%
\tikz@lib@angle@coord{#1}%
}{}{%
\errmessage{Cannot patch \string\tikz@lib@angle@parse}%
}
\patchcmd\tikz@lib@angle@parse{%
\pgf@process{\pgfpointanchor{#3}{center}}%
}{%
\tikz@lib@angle@coord{#3}%
}{}{%
\errmessage{Cannot patch \string\tikz@lib@angle@parse}%
}
% Better support for the comma in the value for angle:
\tikzset{
pics/angle/.style = {
setup code  = {\tikz@lib@angle@parse#1\pgf@stop},
background code = {\tikz@lib@angle@background#1\pgf@stop},
foreground code = {\tikz@lib@angle@foreground#1\pgf@stop},
},
}
\makeatother

\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (0,5);
\coordinate (C) at (5,0);

\node [left] at (A) {$A$};
\node [left] at (B) {$B$};
\node [right] at (C) {$C$};

\draw (A) -- (B) -- (C);

% \pic [draw] {angle=A--B--C};
\pic [draw] {angle={(0,0)--(0,5)--(5,0)}};
\end{tikzpicture}
\end{document}


• That does not answer my question. Is it possible to use something without having to name the coordinates? – Aakash Jog Mar 16 '15 at 9:49
• @AakashJog The answer is no. That is what Heiko means :-) – user11232 Mar 16 '15 at 9:54
• @HarishKumar Apparently I have a problem saying "no" ;-) – Heiko Oberdiek Mar 16 '15 at 11:00
• @HeikoOberdiek You are so gentle and yes with your knowledge of TeX, you probable won't need that word. :-) – user11232 Mar 16 '15 at 11:01
• I think this patch should go in to the angles library. – user11232 Mar 16 '15 at 11:04

You can also go the other way by inserting angle into your custom pic.

\documentclass[tikz]{standalone}
\usetikzlibrary{angles}

\makeatletter
\tikzset{pics/anglecoords/.style = {
setup code  = {
\def\minicoordparser##1--##2--##3\pgf@stop{
\coordinate (A-a) at ##1;\coordinate (B-b) at ##2;\coordinate (C-c) at ##3;
}
\minicoordparser#1\pgf@stop
\tikz@lib@angle@parse{A-a}--{B-b}--{C-c}\pgf@stop
},
background code = \tikz@lib@angle@background{A-a}--{B-b}--{C-c}\pgf@stop,
foreground code = \tikz@lib@angle@foreground{A-a}--{B-b}--{C-c}\pgf@stop,
},
}
\makeatother

\begin{document}
\begin{tikzpicture}[]
\draw (0,0) --(0,5) --(5,0) -- cycle;
\pic[draw]{anglecoords = {(0,0)--(0,5)--(5,0)}};
\pic[draw,fill=yellow]{anglecoords = {(5,0)--(0,0)--(0,5)}};
\end{tikzpicture}
\end{document}