[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
Herbert
\listfiles
\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-node}
\usepackage{pst-xkey}
\SpecialCoor
\makeatletter
\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}%
\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
\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
\rput*[C]{90}(!
\PstWall at thickness .5 mul \pst at number\pslinewidth add
\PstWall at offset add 0){#2}
\fi}
}\ignorespaces}%
\makeatother
\pagestyle{empty}
\begin{document}
\begin{pspicture}[showgrid=true](-5,-5)(4,2)%
\PstWall[thickness=0.5,MyAngle=0](-4,1){A}
\PstWall[thickness=0.5,MyAngle=45,thickness=1cm](-2,0){Surface}
\PstWall[thickness=0.75,MyAngle=90,linewidth=2pt](1,0){}
\PstWall[thickness=0.5,MyAngle=180](-3,-3){}
\PstWall[MyWidth=2,thickness=0.5,MyAngle=270](0,-3){}
\end{pspicture}
\end{document}
More information about the PSTricks
mailing list