5

Taken from pst-node's documentation on page 39:

This very short description about \getnodelist does not help me (maybe others as well) understand how to use it.

enter image description here

Could you give me an example how to use \getnodelist with non-empty <next command>?

3

Judging from the source of pst-node.tex, there is not a difference between

\getnodelist{<name>}{\command}(…)(…)…

and

\getnodelist{<name>}{}(…)(…)… \command

Even in the latter example you can use \PST@root(= <name>) and \pst@args (holds the number of the latest <name> node) without a problem.

The first version forces a more systematic structure (e.g. \command explicitly uses the following nodes). Using it elsewhere might produce unexpected results.

Consider the following example:

\documentclass[pstricks]{standalone}
\usepackage{pstricks,multido,pst-node}
\makeatletter
\def\myCircles#1{%
    \multido{\iCount=0+1}{\the\numexpr\pst@args+1\relax}{
        \pscircle*(\PST@root\iCount){#1}
    }
}
\makeatother
\begin{document}
    \begin{pspicture}(7,7)
    \getnodelist{P}{\myCircles{.25}}(2,2)(2,5)(5,2)(5,5)
    \end{pspicture}
    \begin{pspicture}(7,7)
    \getnodelist{P}{}(2,2)(2,5)(5,2)(5,5)\myCircles{.25}
    \end{pspicture}
\end{document}

There is no difference. They produce exactly the same result.

But if you want to provide an own macro, say \pstDottedNodes, you as the author of this \pstDottedNodes macro wouldn’t have a chance to prepend \myCircles. (It becomes even clearer when you want to hide the internal <name>s from the user and \pstDottedNodes only has one parameter (the radius).)

\documentclass[pstricks]{standalone}
\usepackage{pstricks,multido,pst-node}
\makeatletter
\def\pstDottedNodes#1#2{\getnodelist{#1}{\myCircles{#2}}}
\def\myCircles#1{%
    \multido{\iCount=0+1}{\the\numexpr\pst@args+1\relax}{
        \pscircle*(\PST@root\iCount){#1}
    }
}
\makeatother
\begin{document}
\begin{pspicture}(7,7)
\pstDottedNodes{P}{.25}(2,2)(2,5)(5,2)(5,5)
\end{pspicture}
\end{document}
  • use the node name instead of \PST@root – user2478 Apr 10 '13 at 6:36
  • @Herbert: Why did you use PST rather than pst for the root node name? – kiss my armpit Apr 12 '13 at 10:21
4

Here is a quick example showing that answers the question that illustrates how to draw a (closed) polygon from a sequence of points:

enter image description here

\documentclass{article}
\usepackage{multido,pst-node}% http://ctan.org/pkg/{multido,pst-node}
\makeatletter
\newcounter{mycount}
\newcommand{\drawpolygon}{%
  \setcounter{mycount}{\csname\PST@root nodecount\endcsname}% Extract number of nodes
    \stepcounter{mycount}\pnode(\PST@root 0){\PST@root\themycount}% Add extra node that matches origin node (for closed polygon)
  \multido{\iA=0+1,\iB=1+1}{\value{mycount}}{%
      \psline(\PST@root\iA)(\PST@root\iB)\psdot(\PST@root\iA)}% Draw line + dot
}
\makeatother
\begin{document}
\begin{pspicture}
    \SpecialCoor
    \getnodelist{P}{\drawpolygon}(1,1)(2,1)(2,2)(1,2)
    \degrees[5]
    \rput{0}(4,2){\getnodelist{Q}{\drawpolygon}(1;0)(1;1)(1;2)(1;3)(1;4)}
\end{pspicture}
\end{document}

The idea is to use \getnodelist to call \drawpolygon after specifying a bunch of nodes. Each node has a root name (first argument to \getnodelist), stored in \PST@root.

4

Werners solution with some modifications:

\documentclass{article}
\usepackage{multido,pst-node}

\newcommand\drawpolygon[1]{{%
  \psset{showpoints}
  \multido{\iA=0+1}{\csname#1nodecount\endcsname}{%
    \psline(#1\iA)(#1\the\numexpr\iA+1)}
  \psline(#1 0)(#1\csname#1nodecount\endcsname)}}

\begin{document}
\begin{pspicture}
    \getnodelist{P}{\drawpolygon{P}}(1,1)(2,1)(2,2)(1,2)
    \degrees[5]
    \rput{0}(4,2){\getnodelist{Q}{\drawpolygon{Q}}(1;0)(1;1)(1;2)(1;3)(1;4)}
\end{pspicture}
\end{document}
  • Passing P to \drawpolygon in \getnodelist{P}{\drawpolygon{P}}(1,1)(2,1)(2,2)(1,2) should not be necessary because (1) it can be inferred internally, (2) it increases the potential of error prone (users accidentally pass a different name). – kiss my armpit Apr 10 '13 at 6:58
  • nice that you want to tell me how my own code works internally ... – user2478 Apr 10 '13 at 8:51
0

enter image description here

\documentclass[border=12pt]{standalone}
\usepackage{multido,pst-node}
\makeatletter

\newcommand\psPolygon[2][my@pst@node@name]{\getnodelist{#1}{\my@Polygon{#2}}}

\def\my@Polygon#1{%
    \pscustom[#1]
    {
        \psnline{-}(0,\csname\PST@root nodecount\endcsname){\PST@root}
        \closepath
    }
    \multido{\i=0+1}{\the\numexpr\pst@args+1\relax}{%
        \pscircle*(\PST@root\i){2pt}
    }\ignorespaces
}

\makeatother

\begin{document}
\begin{pspicture}(5,5)
\psPolygon{fillstyle=solid,fillcolor=orange,origin={2.5,2.5}}(0,0)(5,0)(5,5)(0,5)
\end{pspicture}

\qquad

\begin{pspicture}(-2,-2)(2,2)
\degrees[5]
\psPolygon[Karl]{fillstyle=solid,fillcolor=orange}(1;0)(1;1)(1;2)(1;3)(1;4)
\psline(Karl0)(Karl2)
\end{pspicture}

\end{document}

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.