10

I have a project to draw something that is more complicated than the following. Apparently I cannot use w after invoking \psaxes with [$x$,0][$y$,90]. I found it after struggling for 1 hour.

enter image description here

\documentclass{standalone}
\usepackage{pstricks-add}

\begin{document}
\begin{pspicture}(-4,-4)(4,4)
    \pstVerb{/w 1 def}%
    \psaxes{->}(0,0)(-2,-2)(2,2)%
    [$x$,0][$y$,90]%<=== source of problem!
  \psline{-*}(!w w)
\end{pspicture}
\end{document}

Can you see the strange output? The radius of the point should be the square root of 2 cm.

How do I know that w must not be used if there is no warning/error message?

Edit: Another example where a single letter identifier produces a weird output!

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

\begin{document}
\multido{\i=0+30}{12}{%
\begin{pspicture}(4,4)
    \pstVerb{/a 1 def}
    \uput{5mm}[0](2,2){$\i^\circ$}
\end{pspicture}}
\end{document}

2 Answers2

15

it is not a good idea to define global variables with only one letter. They are also used inside the PostScript part. Use at least uppercase letters or better two characters:

\documentclass{standalone}
\usepackage{pst-plot}

\begin{document}
\pstVerb{/ww 1 def}
\begin{pspicture}(-4,-4)(4,4)
  \psaxes{->}(0,0)(-2,-2)(2,2)[$x$,0][$y$,90]
  \psline{-*}(!ww ww)
\end{pspicture}
\end{document}
  • Just curious, why didn't you use @ as the prefix? – kiss my armpit Jul 10 '12 at 17:49
  • I am talking about PostScript where @ is nothing special. The problem is \pstVerb it defines everything global so that a @ wouldn't help anyway –  Jul 10 '12 at 17:50
1

A recommended solution is to use userdict begin ... end construct. It is more flexible than the accepted answer.

\documentclass{standalone}
\usepackage{pstricks-add}

\begin{document}
\begin{pspicture}(-4,-4)(4,4)
    \pstVerb{userdict begin /w 1 def end}%
    \psaxes{->}(0,0)(-2,-2)(2,2)%
    [$x$,0][$y$,90]%<=== source of problem!
  \psline{-*}(!userdict begin w w end)
\end{pspicture}
\end{document}