[pstricks] programming style of simple macro

Herbert Voss Herbert.Voss at fu-berlin.de
Tue Oct 23 12:21:11 CEST 2007

Patrick Drechsler schrieb:
> Hi,
> I am just starting to learn how to write pstricks macros and came up
> with the code below. The code works fine, but it is the result of
> trial-and-error after looking at more sophisticated, existing
> packages.
> Since I am no expert in tex, postscript, xkeyval or pstricks, I was
> wondering if somebody could comment on my pstricks "programming
> style".

when usind high level objects, then there is often no need
for a special macro, like \begin at ClosedObj, which is only
for objects which can be filled.

\def\PstWall{\pst at object{PstWall}}%read star/options, continue with @i

defines a PSTricks object, reads an optional star and the
optional arguments and stores it in \pst at star and \pst at par.
Then it continues with <nama>@i

\def\PstWall at i(#1)#2{{%
  \pst at killglue

when not using one of the open/closed/special/alt objects,
we kill the glue, otherwise it is done by one of the
\begin at Open/Closed/Special/AltObj

  \addbefore at par{linewidth=4pt}% allows overwriting by the user

adding it before the list allows an owerwriting by the user.

  \use at par%				 set options

is also done by default when using
\begin at Open/Closed/Special/AltObj




\pst at addfams{pst-new}%
\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}%
\define at key[psset]{pst-new}{MyAngle}{\pst at getangle{#1}\PstWall at MyAngle}%


\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

(\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
        \PstWall at thickness .5 mul \pst at number\pslinewidth add
        \PstWall at offset add 0){#2}




More information about the PSTricks mailing list