Consider the following code,
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}
\psset{linecolor=red}
\pstVerb
{
/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
}
\def\WithoutDict{%
\begin{pspicture}[showgrid](-5,-5)(5,5)
\multido{\io=1+1}{15}
{%
\pstVerb{/Angles 0 def /CPx 1 def /CPy 0 def}% reset
\def\points{(0,0)(1,0)}% reset
\multido{\ii=1+1}{\io}{\xdef\points{\points(!1 \ii\space updateA Angles PtoC updateCP)}}
\expandafter\psrline\points
\psline(!CPx CPy)
}
\end{pspicture}}
\def\WithDict{%
\begin{pspicture}[showgrid](-5,-5)(5,5)
\multido{\io=1+1}{15}
{%
\pstVerb{tx@Dict begin /Angles 0 def /CPx 1 def /CPy 0 def end}% reset
\def\points{(0,0)(1,0)}% reset
\multido{\ii=1+1}{\io}{\xdef\points{\points(!1 \ii\space updateA Angles PtoC updateCP)}}
\expandafter\psrline\points
\psline(!CPx CPy)
}
\end{pspicture}}
\begin{document}
\WithoutDict
\WithDict
\end{document}
which produces the following outputs.
Question
\WithoutDict
is different from \WithDict
only in tx@Dict
that \WithoutDict
does not use. The use of tx@Dic
in \WithDict
was done by Christoph in his answer here. I really don't understand why I need it.
So the question is,
- What is PostScript dictionary for?
- How to use it in a simple but not trivial example?
- How do I know whether or not I need it?
Hopefully the answer can be used as a crash-course tutorial.
Best Answer
Postscript dictionaries implement the concept of name spaces which allow for control of variable visibility. To see the command line output from the Postscript interpreter, run
ps2pdf
on the PS file produced bydvips
.If you don't know which of the existing dictionaries from the PSTricks packages you will have to put on the dictionary stack, you can always define your variables in a new dictionary of your own. Make your dictionary the current one (and the variables defined therein available) by putting it on the dictionary stack when needed.
The dictionary and the operand stacks are separate things. Putting and popping dictionaries on the dictionary stack don't affect the operand stack: