[pstricks] programming style of simple macro

Herbert Voss Herbert.Voss at fu-berlin.de
Tue Oct 23 22:21:27 CEST 2007


Patrick Drechsler schrieb:

>> \define at key[psset]{pst-new}{offset}{\pst at getlength{#1}\PstWall at offset}%
>> \define at key[psset]{pst-new}{thickness}{\pst at getlength{#1}\PstWall at thickness}%
>> \define at key[psset]{pst-new}{MyWidth}{\pst at getlength{#1}\PstWall at MyWidth}%

all "lengths" are saved as a value without a unit, it is by
default pt and can be used directly inside PS code.

>> \define at key[psset]{pst-new}{MyAngle}{\pst at getangle{#1}\PstWall at MyAngle}%
>>
>> \psset[pst-new]{offset=0pt,thickness=0.5,MyAngle=0,MyWidth=1}%
>>
>> \def\PstWall{\pst at object{PstWall}}%read star/options, continue with @i
>> \def\PstWall at i(#1)#2{{%
>>   \pst at killglue
>>   \addbefore at par{linewidth=4pt}% allows overwriting by the user
>>   \use at par%				 set options
>>   \rput{\PstWall at MyAngle}(#1){%
>>     \psset{unit=1pt}%		     local setting
> 
> Why is this line not necessary when using objects such as
> open/closed/special/alt?

you are on TeX level, the reason why you have to tell TeX, that
we have all lengths as pt. When writing a macro on low level,
then you can use these lengths directly.

>>     \psframe[linestyle=none,fillstyle=hlines]%
>> (\PstWall at offset,-\PstWall at MyWidth)(\PstWall at thickness,\PstWall at MyWidth)
>>     \psline(\PstWall at offset,-\PstWall at MyWidth)%
>>        (\PstWall at offset pt,\PstWall at MyWidth)%
>>     \ifx#2\pst at empty\else
> 
> What is the difference between "\pst at empty" and "\empty"?

we know, what \pst at empty is, but we do not really know,
if \empty is the same. A user may have redefined it. It is only
safe to use PSTricks macros.


>>       \rput*[C]{90}(!
>>         \PstWall at thickness .5 mul \pst at number\pslinewidth add
> 
> I figure that "\pst at number" converts a dimension/length to an
> integer. Is this correct? What other commands are there for conversion
> (i.e. int2length)?

\pst at number converts every length with a unit (a dimen) into
an integer (strips the unit), the value then refers to pt.

\documentclass{article}
\usepackage{pstricks}

\begin{document}

\makeatletter
\pst at dima=10cm
\pst at number\pst at dima

\end{document}

the output is the value of the length 10cm in pt.

> Is something like this covered in detail in the current version of
> your book? I only have the first edition, but I saw that the fourth
> edition has twice as many pages. In the first edition these subjects
> are covered too briefly for me to comprehend the full meaning.

yes, there is now a bit more text
The original documentation of the core of pstricks is here:
ftp://ftp.tug.org/tex/PSTricks/pst-code.pdf

Herbert



More information about the PSTricks mailing list