[pstricks] programming style of simple macro
Patrick Drechsler
patrick at pdrechsler.de
Tue Oct 23 00:03:24 CEST 2007
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".
Thankful for any feedback,
Patrick
--8<---------------cut here---------------start------------->8---
\listfiles
\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-node}
\usepackage{pstricks-add}
\usepackage{pst-xkey}
\usepackage{graphicx}
% Macro Start =================================================
\makeatletter
\SpecialCoor%
\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}%
\psset{offset=0,thickness=0.5,MyAngle=0,MyWidth=1}%
%% 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{{%
\psset{#1}%
\begin at ClosedObj%
\use at par% ??
\rput(#2){%
\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:
\pscustom[linewidth=0.08]{%
\rotate{\PstWall at MyAngle}%
\psline(\pst at dima,-\PstWall at MyWidth)(\pst at dima,\PstWall at MyWidth)%
}%
%%
%% Hatched frame:
\pscustom[linestyle=none,fillstyle=hlines]{%
\rotate{\PstWall at MyAngle}%
\psframe(\pst at dima,-\PstWall at MyWidth)(\pst at dimb,\PstWall at MyWidth)%
}
\def\tempa{#3}%
%% Test if string is empty:
\ifx\tempa\empty\relax%
\else%
%% Else place string:
\uput*{0.25}[\PstWall at MyAngle]{!\PstWall at MyAngle 90 add}(A){#3}%
\fi%
}%
\end at ClosedObj%
}}%
\makeatother
% Macro End ===================================================
\begin{document}
\pagestyle{empty}
\begin{figure}
\centering
\begin{pspicture}[showgrid=true](-5,-5)(4,2)%
\PstWall[thickness=0.5,MyAngle=0](-4,0){A}
\PstWall[thickness=0.5,MyAngle=45](-2,0){Surface}
\PstWall[thickness=0.5,MyAngle=90](1,0){}
\PstWall[thickness=0.5,MyAngle=180](-3,-3){}
\PstWall[MyWidth=2,thickness=0.5,MyAngle=270](0,-3){}
\end{pspicture}
\caption{bar4}
\label{fig:bar}
\end{figure}
\end{document}
--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