# PSTricks: user defined and predefined nodes behave differently

Denis Girou Denis.Girou at idris.fr
Fri Aug 1 23:28:20 CEST 1997

-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

>>>>> "Christophe.Broult" == Christophe Broult <broult at info.unicaen.fr> writes:

Christophe.Broult> When I define new node types using the macro \MatrixNodeDefinition,
Christophe.Broult> and if I put some connecting commands like \ncline inside the
Christophe.Broult> \psmatrix, the result is incorrect.

Christophe.Broult> ..................................................

Christophe.Broult> I forgot to mention the problem was only appearing for the last node

Yes, there is a special problem on the last node when the connection is
defined inside the psmatrix environment.

What I can say:

* It is a very specifix case!

* The interest to define node connections inside the environment are not
very important. The only one mentioned is to have shortput=tablr pre-defined.
Nevertheless, it's easy to define explicitely and so to be able to use
abbreviations outside psmatrix environment.

* Problem is related to some group structure which is not considered
"closed". So, my solution, which was to write some PostScript code after node
definition to change the definition of nodes doesn't work, because this
PostScript code for the last node is writed too late... (after the closing of
the environment, so after the node connection). I have found some workarounds,
but all too heavy to be usable.

* My solution is not very pretty. It consist to define the node without
the special format, to add later the format with a new node, then to change
the name of it to the previous one (and to the explicitely one if name= is
used).

I have found another way to solve the problem, which is cleaner.
Nevertheless it disadvantage is that it doesn't use high level macros, but the
lower level ones. In simple cases, it can be masked. But for complex or
special ones, you must know a little the internals of PSTricks (but what is
required is simple and can be easily found in the code of pstricks.tex).
For instance you can't use psdblframebox', because the internal macro
\psdblframebox at ii doesn't exist. You must look at the code to see that it is
defined as \psframebox with the parameter doubleline=true

D.G.

\documentclass{article}

\usepackage{pst-node}

\makeatletter

% To define personal nodes for the psmatrix environment
% Denis Girou <Denis.Girou at idris.fr> - Aug. 1, 1997
\def\MatrixNodeDefinition#1#2#3{%
% #1=type of node name, #2=macro to apply to the node contents, #3=parameters
% Ex: \MatrixNodeDefinition{MyNodeType}{psframebox}{linecolor=red}
\expandafter\def\csname mnode@#1\endcsname{%
% Modification of \Rnode at ii
\def\Rnode at ii{%
% DG modification begin - Aug. 1, 1997
\setbox\pst at hbox=\hbox{\ifx#3\@empty\else\psset{#3}\fi\csname #2 at ii\endcsname}
% DG modification end
\use at par
\pst at dima=\psk at href\wd\pst at hbox
\divide\pst at dima 2
\pssetlength\pst at dimb{\psk at vref}}
\rnode at iii\Rnode at ii{\psm at thenode}}}

\makeatother

\pagestyle{empty}

\begin{document}

\MatrixNodeDefinition{MyNodeTypeA}{pscirclebox}{linecolor=red}

\begin{psmatrix}[mnode=MyNodeTypeA]
[name=A] AAAA\\[0pt]
[name=B] BBBBBBBB
\ncline{A}{B}
\end{psmatrix}
\begin{psmatrix}[mnode=MyNodeTypeA]
AAAA \\
BBBBBBBB
\end{psmatrix}
\ncline{1,1}{2,1}
% We must know for instance that \psdblframebox at ii doesn't exist.
% So psdblframebox can't be required. We must used psframebox with
% the doubleline=true parameter.
\MatrixNodeDefinition{MyNodeTypeB}{psframebox}{doubleline=true}
\begin{psmatrix}[mnode=MyNodeTypeB]
AAAA \\
BBBBBBBB
\end{psmatrix}
\ncline{1,1}{2,1}

\MatrixNodeDefinition{MyNodeTypeC}{psframebox}{framesep=1,linecolor=green}

\vspace{2cm}
{\Huge
\begin{psmatrix}[mnode=MyNodeTypeA]
[name=A] A & [name=B] B                   & [name=C,mnode=MyNodeTypeC] C \\
& [name=D,mnode=MyNodeTypeC] D & [name=E] E
\end{psmatrix}
\psset{arrows=->}
\nccircle{A}{1.5}
\ncangle[angle=90,armB=0.8]{A}{C}
\ncline{C}{D}
\ncline{D}{E}
\ncbar[angleA=-90,armB=1.5]{A}{E}
\ncline{C}{E}
}

% For more sophisticated definitions, we must used low level macro definitions
\makeatletter
\def\mnode at MyNodeTypeD{%
% Modification of \Rnode at ii
\def\Rnode at ii{%
% DG modification begin - Aug. 1, 1997
\setbox\pst at hbox=\hbox{\pscirclebox at ii}%
\setbox\pst at hbox=\hbox{\psset{linecolor=red,framesep=0}\pstribox at ii}%
\setbox\pst at hbox=\hbox{\psset{linecolor=yellow,framesep=0}\psframebox at ii}
% DG modification end
\use at par
\pst at dima=\psk at href\wd\pst at hbox
\divide\pst at dima 2
\pssetlength\pst at dimb{\psk at vref}}
\rnode at iii\Rnode at ii{\psm at thenode}}
\makeatother

\vspace{2cm}
\begin{psmatrix}[mnode=MyNodeTypeD]
[name=A] AAAA \\[0pt]
[name=B] BBBBBBBB
\end{psmatrix}
\ncline{A}{B}

\vspace{1cm}
\begin{psmatrix}[mnode=MyNodeTypeD]
AAAA & BBBBBBBB
\end{psmatrix}
\ncline{1,1}{1,2}

\end{document}

-----------------------------------------------------------------------------
To [un]subscribe to this list, send mail to pstricks-request at mail.tug.org
Leave the subject line blank and in the body put the line
`