Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Consider the following complete code first.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}

\begin{document}
\begin{pspicture}(-5,-5)(5,5)
    \def\points{(0,0)(1,0)}%
    \pstVerb{/Angles 0 def /CPX 1 def /CPY 0 def}
    \multido{\i=1+1}{15}
    {
        \xdef\points{\points(!1 Angles 1 \i\space 1 sub sqrt atan add dup /Angles ED PtoC %
        dup CPY add /CPY ED exch dup CPX add /CPX ED exch)(!CPX neg CPY neg)(!CPX CPY)}
    }
    \expandafter\psrline\points
\end{pspicture}

\begin{pspicture}(-5,-5)(5,5)
    \def\points{(0,0)(1,0)}%
    \pstVerb{/Angles 0 def /CPX 1 def /CPY 0 def}
    \multido{\i=1+1}{15}
    {
        \pstVerb{Angles 1 \i\space 1 sub sqrt atan add /Angles exch def}%
        \xdef\points{\points(!1 Angles PtoC %
        dup CPY add /CPY ED exch dup CPX add /CPX ED exch)(!CPX neg CPY neg)(!CPX CPY)}
    }
    \expandafter\psrline\points
\end{pspicture}
\end{document}

It produces two outputs as follows.

enter image description here

enter image description here

Explanation

When I move the definition of Angles from

xdef\points{\points(!1 Angles 1 \i\space 1 sub sqrt atan add dup /Angles ED PtoC %
            dup CPY add /CPY ED exch dup CPX add /CPX ED exch)(!CPX neg CPY neg)(!CPX CPY)}

to

\pstVerb{Angles 1 \i\space 1 sub sqrt atan add /Angles exch def}

why does the output become incorrect?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Fundamentally PostScript doesn't translate directly to TeX. Only \space and \i are properly identified and expanded.

When you include the \pstVerb inside the \multido loop, you are storing an updated version of Angles using PostScript. However, the construction of \points does not take this altered version of Angles into consideration, since it's not expanded in the usual TeX way. As such, the call

\expandafter\psrline\points

just uses the latest version of Angles when it does \psrline on the expanded \points.

share|improve this answer
    
+1 then is there any solution to overcome this limitation? –  In PSTricks we trust Jan 26 at 3:02
    
@CodeMocker: If you define \Angles using something like pgfmath or fp. –  Werner Jan 26 at 3:04
    
See my answer, I just got it by accident. –  In PSTricks we trust Jan 26 at 4:49

I got the solution as follows.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}

\begin{document}
\begin{pspicture}[showgrid](-5,-5)(5,5)
    \psset{linecolor=red}
    \def\points{(0,0)(1,0)}%
    \pstVerb
    {
        /Angles 0 def
        /CPx 1 def 
        /CPy 0 def
        /updateCP {2 copy CPy add /CPy ED CPx add /CPx ED} bind def
        /updateA  {1 sub sqrt 1 exch atan Angles add /Angles ED} bind def
    }
    \multido{\i=1+1}{15}
    {
        \xdef\points{\points(!1 \i\space updateA Angles PtoC updateCP)(!CPx neg CPy neg)(!CPx CPy)}
    }
    \expandafter\psrline\points
\end{pspicture}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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