[pstricks] Defining a command
Herbert Voss
herbert49 at googlemail.com
Thu Jul 5 09:17:40 CEST 2007
Konrad Viltersten wrote:
> I've defined the following command.
>
> \newcommand{\something}[4]
> {\pspolygon (#1,#2) (#3,#2) (#3,#4) (#1,#4)}
>
> As i've been rectangling a lot, it was extremely useful.
> Now, i'll be rombing for a while but i seem to get stuck
> on how to define it so i only need to specify two points
> when calling it...
>
> It will be something like this.
>
> \newcommand{\something}[4]
> {\pspolygon
> (#1,#2)
> (#3,#4)
> (2 * #3 - #1,#2)
> (#3,2 * #2 - #4)}
>
> Now, the problem is that i still don't really get how to
> perform multiplication and subtraction inside there.
> Suggestions?
>
\listfiles
\documentclass{article}
\usepackage{pstricks}
\SpecialCoor
\newcommand{\something}[4]{%
\pspolygon(#1,#2)(#3,#4)(! #3 dup add #1 sub #2)(! #3 #2 dup add #4 sub)}
% better, can have optional arguments
\makeatletter
\def\psPolygon{\@ifnextchar[\psPolygon at i{\psPolygon at i[]}}
\def\psPolygon at i[#1](#2,#3)(#4,#5){%
\pspolygon[#1](#2,#3)(#4,#5)(! #4 dup add #2 sub #3)(! #4 #3 dup add
#5 sub)}
\makeatother
\begin{document}
\something 1 2 3 4 \hspace{2cm}
\psPolygon[linecolor=red,fillstyle=solid](1,2)(3,4)
\end{document}
Herbert
--
http://PSTricks.tug.org
http://www.dante.de/CTAN/info/math/voss/
More information about the PSTricks
mailing list