# Is it possible to simplify the following expression by defining a global operator?

The following MWE is the simplified version of the real scenario. I want to simplify (!\psGetNodeCenter{A}\psGetNodeCenter{B} A.x B.x add A.y B.y add) to (!A B AddNode). Is it possible?

\documentclass[pstricks,border=12pt]{standalone}
\pstVerb
{
% convert nodes A B to a new node C where C.x=A.x+B.x and C.y=A.y+B.y
}

\begin{document}
\begin{pspicture}[showgrid=top](6,6)
\pnode(0,3){A}
\pnode(4,0){B}
\psline{->}(A)(B)(C)
\end{pspicture}
\end{document}

-

In general the answer is no. The (! ) construction introduces literal postscript, and in your suggested syntax A is inserted on to the stack unquoted, so you risk this already being defined as e.g. a variable with another value or a function trying to operate on something.

pst-node.tex, used by pstricks for defining and maniulating nodes, stores node names in the dictionary tx@NodeDict, with e.g. node A stored in /N@A. If you are prepared to work hard you could write postscript code that would take the string (A) and extract the coordinates via GetCenter, enabling to have syntax like (!(A) (B) AddNode). However, it is unclear to me when this could win over just defining a LaTeX command

\newcommand{\pnodeadd}[3]{\pnode(!\psGetNodeCenter{#1}\psGetNodeCenter{#2}

\pnodeadd{A}{B}{C}

The pst-node code does all its interfacing to postscript in this sort of way, using tex to build the names N@A etc. before postscript ever sees them.
Indeed, as I say they are stored in the PS side in tx@NodeDict as /N@A etc. The problem is the requested syntax, without quoting of the tex version of the node names. – Andrew Swann Aug 14 '12 at 9:36
\pnode(! /A /B AddNode){C} would be easy to realize – Herbert Aug 14 '12 at 9:54