[pstricks] programming style of simple macro

Patrick Drechsler patrick at pdrechsler.de
Wed Oct 24 00:06:21 CEST 2007


Herbert Voss <Herbert.Voss at fu-berlin.de> writes:

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

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

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?


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

I just skimmed the documented pstricks code you mention below. I guess
I must make a list of TeX <commands> which are replaced by
pst@<commands>. Obviously I cannot assume that every command has been
ported (i.e. there is no "\pst at ifx" or "\pst at else" in the line above).

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

OK. Before asking if there is something like "\pst at ConvertNumberToDim"
I will look it up in the commented pstricks code (see comments below).

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

Very instructive, thank you!

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

I have just ordered a copy of the current edition.

> The original documentation of the core of pstricks is here:
> ftp://ftp.tug.org/tex/PSTricks/pst-code.pdf

A first glance at pst-code.pdf answered further questions I have with
writing pstricks code. Thanks for the pointer. 

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"?


Again, thank you very much! Your feedback is very much appreciated!

Patrick



More information about the PSTricks mailing list