# Newcommand for TikZ Diagram with Arguments as Labels

I'm trying to make a macro to print a TikZ diagram with "variable" labels. MWE:

\documentclass{standalone}
\usepackage{tikz}
\newcommand[3]{\myDiagram}{
\begin{tikzpicture}
\node[label={270:$1$}] (1) at (270:1) {};
\node[label={30:$2$}] (2) at (30:1) {};
\node[label={150:$3$}] (3) at (150:1) {};
\draw
(1) edge node[label={#1}] {} (2)
(1) edge node[label={#2}] {} (3)
(2) edge node[label={#3}] {} (3)
;
\end{tikzpicture}
}
\begin{document}
\myDiagram{$1$}{$2$}{$3$}
\end{document}


Expected Behaviour: A diagram which substitutes labels from argument. I.e. My MWE's Output should be the same as this:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[label={270:$1$}] (1) at (270:1) {};
\node[label={30:$2$}] (2) at (30:1) {};
\node[label={150:$3$}] (3) at (150:1) {};
\draw
(1) edge node[label={$1$}] {} (2)
(1) edge node[label={$2$}] {} (3)
(2) edge node[label={$3$}] {} (3)
;
\end{tikzpicture}
\end{document}


Actual Behaviour: I keep getting a Missing \endcsname inserted.

What I've Tried: Variations on this question's answers (I couldn't find much else in the way of similar questions).

Please explain what I'm doing wrong here and how I can fix it. Thanks in advance.

I suggest the following way:

\documentclass[tikz]{standalone}
\begin{document}
\newcommand*{\myDiagram}[3]{%
\path
(-90:1) node (1) {$1$}
(30:1)  node (2) {$2$}
(150:1) node (3) {$3$}
;
\draw[nodes={red,midway,scale=.6}] (1)
--(2) node[below right] {#1}
--(3) node[above] {#2}
--(1) node[below left] {#3}
;
}%

\begin{tikzpicture}
\myDiagram{$1$}{$3$}{$2$}
\end{tikzpicture}
\end{document}


Also you can define a pic for this task.


• This is a decent workaround, but doesn't address the "why is this not working" part of my question... Also, why \newcommand* here (it doesn't affect the output on my machine)? Jul 11 at 18:38
• @User12345 I see the picture, then caring how to code with simplicity. I don't care much about the error in your code. although I think that is easy to explain. Maybe someone can help you, or you can explain yourself later Jul 11 at 18:59
• yup, silly me. Thanks. Jul 11 at 19:19
• It happens sometimes ^^ Cheer up! I suppose that you can upvote and accept my updated answer now Jul 11 at 19:57
