# [pstricks] programming style of simple macro

Herbert Voss Herbert.Voss at fu-berlin.de
Wed Oct 24 08:30:50 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.
>
> I see. That's why I was just lucky with my original "\edef" approach:
>
> \define at key[psset]{pst-new}{offset}{\edef\PstWall at offset{#1}}%
>
> I can now see why "\edef" is used for "strings", not "dims".
>
> On a side note: Understanding the difference between "\edef" and
> "\def" will take up a lot of time, which is why I will postpone that

\def is the correct one, because \edef can make things weired,
e.g. when using an expandable macro in the argument.

>>> 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.
>
> Understood. Is there a reason *not* to use a macro
> open/closed/special/alt to avoid this problem? In other words: Would I
> not be on the save side always using one of these macros?

In general: so-called hih level macros use already defined PSTricks
macros and no PostScript code.
so-called low-level macros will have commands like \addto at pscode{...}.
In such a case you have to initialize this PostScript part and to
insert linewidth/fillstyle/fillcolor/... on PS-level. This all
is done by the open/closed/special/alt macros.

Closed: checks not for arrows but for filling/double lines/shadows
Special: no check for arrows/filling/double lines/shadows
AltOpen: special arrows/linetype setting (more internally)

>> \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.

> I am trying to write a package. Are there things I should be aware of
> when using pst-xkey/xkeyval? Are there any tutorials on the usage of
> xkeyval other than "texdoc xkeyval"?

for PSTricks it should be ok, when looking at another package or