# How to create PSTricks commands?

Denis Girou Denis.Girou at idris.fr
Mon Nov 3 11:11:08 CET 1997

-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

The following message is a courtesy copy of an article
that has been posted to comp.text.tex as well.

>>>>> "Jonas.Bofjall" == Jonas Bofjall <m9418 at abc.se> writes:

Jonas.Bofjall> I have some pictures which all should look alike, that me and some other
Jonas.Bofjall> people are working on to include in a text. To draw them we use PSTricks,
Jonas.Bofjall> since it is very versatile but can still be used inside TeX.

Jonas.Bofjall> Now, for example, many pictures contains a negatively charged particle.
Jonas.Bofjall> So what could be more natural than defining how that looks once and for
Jonas.Bofjall> all, and then use that definition for all remaining pictures.
Jonas.Bofjall> The command might be \negpart(x,y) to place that picture element on (x,y).

Jonas.Bofjall> But how do I do that with \newcommand? (or is there a better way?)
Jonas.Bofjall> I don't know how to declare a command which should take two arguments
Jonas.Bofjall> inside paranthesis.

The LaTeX \newcommand macro doesn't allow this syntax, but the primary TeX
\def macro allow it. Just use something like \def\negpart(#1,#2){%

Jonas.Bofjall> The command might look something like this:
Jonas.Bofjall>   \pscircle*[linecolor=white]{x,y){2.5}
Jonas.Bofjall>   \pscircle(x,y){2}
Jonas.Bofjall>   \qline(x-1.2,y)(x+1.2,y)

Jonas.Bofjall> Where x' and y' should be substituted for the coordinates.
Jonas.Bofjall> Is there a nice way to do that subtraction / addition by 1.2?
Jonas.Bofjall> I know that it can work by using \FPadd and \FPsub from multido.sty,
Jonas.Bofjall> but perhaps is there a cleaner way (\FPadd is enormously slow).

There are other packages (at least realcalc' and fp') for fixed point
computations, which allow a lot more operations, but you don't need it in your
case. You can just use the simple \rlineto macro (see documentation on page
39) which work on relative coordinates (but only in a \pscustom environment).

The manipulation of relative coordinates is very restrictive in PSTricks
(we have only the \rlineto and \rcurveto macros). But I recently shown on the
PSTricks mailing list how to implement a generalized mechanism for relative
coordinates. See http://tug.cs.umb.edu/ListsArchives/pstricks/msg00066.html

But in you case, use only something like:

\documentclass{article}

\usepackage{pstricks}

\def\negpart(#1,#2){%
\pscircle*[linecolor=cyan](#1,#2){2.5}
\pscircle(#1,#2){2}
\pscustom[linecolor=red,linewidth=1mm]{%
\moveto(#1,#2)\rlineto(-1.2,0)
\moveto(#1,#2)\rlineto(1.2,0)}}

\begin{document}

\negpart(1,1)

\end{document}

Jonas.Bofjall> There is a command called \pscustom which sounded
Jonas.Bofjall> good, but it doesn't do this (I can't understand what it is for!).

such as the graphics state (\gsave and \grestore), the coordinate state
(\msave and \mrestore), the stroke mechanism, etc. It allow some special
functionalities. One specially useful is to fill the region between two
arbitrary curves (see documentation pages 35 to 37).

Denis Girou

--

---------------------------------------------------------------------------
Institut du De'veloppement et des Ressources en Informatique Scientifique |
Centre National de la Recherche Scientifique                              |
Ba^timent 506 - B.P. 167 - 91403 Orsay Cedex - France                     |
Tel. : 01.69.35.85.75 (33.1.69.35.85.75 from foreign countries)           |
Messagerie : Denis.Girou at idris.fr                                         |
---------------------------------------------------------------------------

-----------------------------------------------------------------------------