6

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}
\usepackage{pstricks-add}
\pstVerb
{
    % convert nodes A B to a new node C where C.x=A.x+B.x and C.y=A.y+B.y
    /AddNode {} bind def
}

\begin{document}
\begin{pspicture}[showgrid=top](6,6)
    \pnode(0,3){A}
    \pnode(4,0){B}
    \pnode(!\psGetNodeCenter{A}\psGetNodeCenter{B} A.x B.x add A.y B.y add){C}
    %\pnode(!A B AddNode){C}
    \psline{->}(A)(B)(C)
\end{pspicture}
\end{document}
4
+50

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} 
  #1.x #2.x add #1.y #2.y add){#3}}

and simply using

\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.

  • 2
    In general: nodes are saved on PS side the reason why it is possible! – user2478 Aug 12 '12 at 15:25
  • 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 – user2478 Aug 14 '12 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.