[pstricks] programming style of simple macro

Patrick Drechsler patrick at pdrechsler.de
Tue Oct 23 00:03:24 CEST 2007


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

Since I am no expert in tex, postscript, xkeyval or pstricks, I was
wondering if somebody could comment on my pstricks "programming

Thankful for any feedback,


--8<---------------cut here---------------start------------->8---


% Macro Start =================================================


\pst at addfams{pst-new}%

\define at key[psset]{pst-new}{offset}{\edef\PstWall at offset{#1}}%
\define at key[psset]{pst-new}{thickness}{\edef\PstWall at thickness{#1}}%
\define at key[psset]{pst-new}{MyWidth}{\edef\PstWall at MyWidth{#1}}%
\define at key[psset]{pst-new}{MyAngle}{\pst at getangle{#1}\PstWall at MyAngle}%


%% Check for optional arguments (starting with "["):
\def\PstWall{\@ifnextchar[{\pst at PstWall@i}{\pst at PstWall@i[]}}%

%% Main macro
\def\pst at PstWall@i[#1](#2)#3{{%
    \begin at ClosedObj%
      \use at par% ??
        \pssetlength{\pst at dima}{\PstWall at offset}%
        \pst at dimb=\pst at dima%
        \pnode(\pst at dima,0){A}%
        \psaddtolength{\pst at dimb}{\PstWall at thickness}%
        %% "Surface" line:
          \rotate{\PstWall at MyAngle}%
          \psline(\pst at dima,-\PstWall at MyWidth)(\pst at dima,\PstWall at MyWidth)%
        %% Hatched frame:
          \rotate{\PstWall at MyAngle}%
          \psframe(\pst at dima,-\PstWall at MyWidth)(\pst at dimb,\PstWall at MyWidth)%
        %% Test if string is empty:
        %% Else place string:
        \uput*{0.25}[\PstWall at MyAngle]{!\PstWall at MyAngle 90 add}(A){#3}%
    \end at ClosedObj%

% Macro End ===================================================




--8<---------------cut here---------------end--------------->8---

,----[ *File List* ]
|  article.cls    2005/09/16 v1.4f Standard LaTeX document class
|   size10.clo    2005/09/16 v1.4f Standard LaTeX file (size option)
| pstricks.sty    2007/02/18 v0.33 LaTeX wrapper for `PSTricks' (RN,HV)
| pstricks.tex    2006/12/22 v1.15a `PSTricks' (tvz)
|   xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
|    color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
|    dvips.def    1999/02/16 v3.0i Driver-dependant file (DPC,SPQR)
| pst-node.sty    2006/01/01 package wrapper for pst-node.tex
| pst-node.tex    2000/11/09 97 patch 11 `pst-node' (tvz)
| pstricks-add.sty    2007/09/03 v. 0.11 package wrapper for pstricks-add.tex (hv
| )
| pstricks-add.tex    2007/09/25 v2.90 `PSTricks-add' (hv)
| pst-xkey.tex    2005/11/25 v1.6 PSTricks specialization of xkeyval (HA)
|  xkeyval.sty    2006/11/18 v2.5f package option processing (HA)
|  xkeyval.tex    2006/11/18 v2.5f key=value parser (HA)
| pstricks-add.pro    2007/09/04 v. 0.14, PostScript prologue file (hv)
| pst-xkey.sty    2005/11/25 v1.6 package wrapper for pst-xkey.tex (HA)
| graphicx.sty    1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
| graphics.sty    2006/02/20 v1.0o Standard LaTeX Graphics (DPC,SPQR)
|     trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
| graphics.cfg    2007/01/18 v1.5 graphics configuration of teTeX/TeXLive

,----[ System info ]
| patrick at golem:~$ uname -a
| Linux golem 2.6.15-29-k7 #1 SMP PREEMPT Mon Sep 24 17:31:22 UTC 2007 i686 GNU/Linux

More information about the PSTricks mailing list