[Xy-pic] 'macros' with saved points

Ross Moore ross at ics.mq.edu.au
Fri Oct 31 14:56:39 CET 2003


Hello Scott,

On Thu, 30 Oct 2003, Scott Morrison wrote:

> Hi,
>
> I'm fairly new to xy-pic, please forgive my ignorance!
>
> I'd like to be able to do something like this:
>
> \newcommand{\dropblob}[1]{
> 	*\xycircle(1,1){}="#1"
> }

This cannot work as it is, since it does not turn on the Xy-pic
parser.

But this works:

  \newcommand{\dropblob}[1]{\POS*\xycircle(1,1){}="#1"}
or
  \newcommand{\dropblob}[1]{\drop\xycircle(1,1){}="#1"}

 * is a non-active shorthand for \drop , when in the
appropriate parser context.

Another useful way to define a macro expansion is as:

  \newcommand{\dropblob}[1]{\save*\xycircle(1,1){}="#1"\restore}

where now the graphics state reverts to what it was before
the  \dropblob  macro is called.


>
> That is, have a new command which drops some stuff (generally much more
> complicated than just a circle), and names certain points in it according
> to passed arguments. This command would be for drawing certain complicated
> objects which I reuse many times. Being able to name certain points in
> this way means that when I need to add more to the standard object, I can
> do things relative to those named points, without having to calculate
> where they are. Does that make sense? Is it possible?

Of course. Macro-programming is at the heart of TeX.
Xy-pic extends that for constructing graphics as well.
You just have to remember to start the expansion tokens with an active
control-sequence that turns on Xy-pic parsing, so that the non-active
characters can be interpreted within the correct context.


Hope this helps,

	Ross Moore

>
> Thanks,
> Scott Morrison
>
> _______________________________________________
> xy-pic mailing list
> http://tug.org/mailman/listinfo/xy-pic
>


More information about the xy-pic mailing list