# How can I use a macro argument as a pst-node label?

In the following example:

\documentclass{article}

\usepackage{pstricks,pst-node}

\begin{document}

\def\working(#1,#2,#3, #4){
\rput(#1,#2){
\ovalnode{M5}{
#4
}
}
}

\def\notworking(#1,#2,#3,#4){
\rput(#1,#2){
\ovalnode{M#3}{
#4
}
}
}

\psset{unit=1cm}

\begin{pspicture}
\working(1,1, 5, WORKING)
\ovalnode{Start}{Start}
\ncarc{Start}{M5}
\end{pspicture}

\begin{pspicture}
\notworking(1,1, 5, NOTWORKING)
\ovalnode{Start}{Start}
\ncarc{Start}{M5}
\end{pspicture}

\end{document}

there are two very similar macros. In the "working" macro, the node label "M5" is hard-coded. The first picture indeed creates the "M5" node and connects it to the "Start" node:

But, I want the node-label to be a macro argument. This is not working, as shown in the "notworking" macro. I see "NOTWORKING" and "Start" but they are not connected:

How can I make it work?

• What do you mean by 'not working'? Your code compiles without errors for me and the output looks the same for both nodes. (Although compiling with auto-pst-pdf seems to chop off the left edge of each node. Compiling with xelatex or latex+dvips and without auto-pst-pdf solves that issue though.) – Alan Munn May 8 '16 at 14:15
• @AlanMunn I added an explanation. It was created with xelatex and without auto-pst-pdf. – Erel Segal-Halevi May 8 '16 at 14:52
• Thanks for the update. This makes the problem clearer, but I suspect you have an outdated version of something, since this compiles correctly on my system (TL 2015). – Alan Munn May 8 '16 at 14:55

With this definition you expect a space before the fourth parameter:

\def\working(#1,#2,#3, #4){
\rput(#1,#2){
\ovalnode{M5}{
#4
}
}
}

\working(1,1,5, WORKING) will be ok, but \working(1,1,5,WORKING)is not; the space before "WORKING" is missing. However use

\def\working(#1,#2,#3,#4){%  NO SPACE HERE
\rput(#1,#2){%
\ovalnode{M5}{%
#4%
}%
}%
}

The % are not all really needed, because PSTricks kills trailing spaces if you are inside a PSTricks object. If not you get a lot of these spaces.

• OK... Now I see. So it is not related to pstricks it all. Only a matter of spaces before the macro parameters. – Erel Segal-Halevi May 8 '16 at 17:42

This works flawlessly:

\documentclass{article}

\usepackage{auto-pst-pdf}
\usepackage{pstricks,pst-node}

\begin{document}

\def\working(#1,#2,#3,#4){%
\rput(#1,#2){%
\ovalnode{M5}{%
#4%
}%
}%
}

\def\notworking(#1,#2,#3,#4){%
\rput(#1,#2){%
\ovalnode{M#3}{%
#4%
}%
}%
}

\psset{unit=1cm}

\begin{pspicture}
\working(1,1,5,WORKING)
\ovalnode{Start}{Start}
\ncarc{Start}{M5}
\end{pspicture}

\begin{pspicture}
\notworking(1,1,5,WORKING)
\ovalnode{Start}{Start}
\ncarc{Start}{M5}
\end{pspicture}

\end{document}

and gives the same result for both pictures.