How to create PSTricks commands?

Denis Girou Denis.Girou at
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> 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

  But in you case, use only something like:







    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!).

  \pscustom environment give you access to low level PostScript mechanisms,
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. : ( from foreign countries)           |
Messagerie : Denis.Girou at                                         |

The list interface (subscription, information, access to the archives) is on:
Otherway to unsubscribe, send mail to pstricks-request at
with a blank subject and in body the line unsubscribe <email-address>

More information about the PSTricks mailing list