# How to define a global constant in postscript statement?

I want to define a constant globally within my pspicture environment as follows:

\begin{pspicture}(4,2)
\psgrid
\SpecialCoor
\def\length{2}
\pnode(!\length 1){C}
\uput[90](C){$C$}
% other codes truncated here for simplicity.
\end{pspicture}


The above example does not work.

What is the correct way to do that?

-

## migrated from stackoverflow.comJul 27 '11 at 9:07

This question came from our site for professional and enthusiast programmers.

We can use a (La)TeX macro or PS verb. When using a (La)TeX macro, \space is needed to prevent the macro from eating things after it. But when using PS verb, \space is not needed.

See the following for the details.

\documentclass{minimal}
\def\LENGTH{2}
\begin{document}
\begin{pspicture}[showgrid=true](4,2)
\SpecialCoor
\pstVerb{/length 2 def}
\pnode(!\LENGTH\space 1){C}
\pnode(! length 1){D}
\uput[90](C){$C$}
\uput[180](D){$D$}
\end{pspicture}
\end{document}

-