[pstricks] programming style of simple macro

Alan Ristow ristow at ece.gatech.edu
Wed Oct 24 17:20:10 CEST 2007


Herbert Voss wrote:
> Patrick Drechsler schrieb:
>>> \pst at number converts every length with a unit (a dimen) into
>>> an integer (strips the unit), the value then refers to pt.
>> OK. Before asking if there is something like "\pst at ConvertNumberToDim"
> 
> this is alreday done by \pst at getlength{...}. The argument can have
> a unit or not, then it takes the current one. pstricks-add also
> has some more macros for reading lengths or values.

Though it's worth noting that \pst at getlength returns a value equal to a 
length in pt, but it doesn't actually return what TeX would call a 
length. If you actually need a length -- something you can store in a 
dimen register -- the \p@ macro can come in handy. I'm not aware of an 
equivalent in pstricks, though even after years of occasionally reading 
the source code I'm still discovering things I wasn't aware of (and this 
thread actually clarified several things for me)....

Anyway, compare the different sections of the code below.

Alan

\documentclass{article}
\usepackage{pstricks}
\begin{document}
\makeatletter
\def\notlength{10}% store number 10 -- not a length!
\newdimen\islength
%
% Print 20pt in pt
%
\islength=20pt
\the\islength
\par
%
% Print 10pt in pt
%
\islength=\notlength\p@
\the\islength
\par
%
% Print 10cm in pt
%
\psset{unit=1cm}
\pst at getlength{\notlength}{\temp}
\islength=\temp\p@
\the\islength
\par
%
% Print 10pt in pt
%
\psset{unit=1pt}
\pst at getlength{\notlength}{\temp}
\islength=\temp\p@
\the\islength
\end{document}




More information about the PSTricks mailing list