Problem Embedding Angle into TikZ Pic

tikz-anglestikz-pgf

I am trying to create a pic that includes an angle pic from the angles library using TikZ. The error I get is

! TeX capacity exceeded, sorry [grouping levels=255].
<argument> ...kz@pp@name {x1}\endcsname }{center}{
                                                  \pgfsettransform {\csname ...
l.18 ...pic text=$\alpha$] {my angle={x1}{x2}{x3}}
                                                  ; % does not work
If you really absolutely need more capacity,
you can ask a wizard to enlarge me.

I have not been able to resolve this issue. How can I draw the angle within my own pic?

Here's the MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles}
\begin{document}
    \begin{tikzpicture}
        \tikzset{
            pics/my angle/.style n args={3}{
                code = {
                    \draw (#1) -- (#2) -- (#3);
                    \pic [draw] {angle=#1--#2--#3}; % offending line
                }
            }
        }
        
        \coordinate (x1) at (-1, 0);
        \coordinate (x2) at (0, 0);
        \coordinate (x3) at (-0.5, -0.5);
        \pic[pic text=$\alpha$] {my angle={x1}{x2}{x3}}; % does not work
        
%        \pic [draw] {angle=x1--x2--x3}; % this does draw the angle
    \end{tikzpicture}
\end{document}

Best Answer

The problem is that the angle pic works with foreground code and background code, and this does for some reason not like to get nested into a "normal" code. However, you can use e.g. foreground code to nest the angle pic in your my angle pic.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles}
\begin{document}
    \begin{tikzpicture}
        \tikzset{pics/my angle/.style n args={3}{
                setup code  ={},
                background code ={},
                foreground code = {\pic [draw] 
                        {angle=#1--#2--#3}; % no longer offending 
                },
                code = {
                    \draw (#1) -- (#2) -- (#3);
                }
            }
        }
        
        \coordinate (x1) at (-1, 0);
        \coordinate (x2) at (0, 0);
        \coordinate (x3) at (-0.5, -0.5);
        \pic[pic text=$\alpha$] 
        {my angle={x1}{x2}{x3}}; %  works now
        
    \end{tikzpicture}
\end{document}

enter image description here