[metapost] augment drawoptions

Taco Hoekwater taco at elvenkind.com
Fri Apr 11 20:10:02 CEST 2008


Stephan Hennig wrote:
> Hi,
> 
> inside a macro I want to determine some draw options, say pen width,
> while keeping others that are already set by drawoption(), e.g., stroke
> colour.  The straight forward way to do that is directly applying my
> modified draw options to the drawing command, e.g.,
> 
> def mydraw =
>   draw fullcircle scaled 100 withpen pencircle scaled 4bp;
> enddef;
> 
> beginfig(1);
>   drawoptions(withcolor red);% Set colour.
>   mydraw;% Circle is drawn red and with a 4bp pen.
> endfig;
> 
> Now, in macro mydraw I do not directly draw anything, but delegate all
> drawing operations to another macro, so that I cannot apply 'withpen
> ...' directly.  My idea was to augment the current draw option by
> 'withpen ...', that is, keeping the former drawoptions configuration,
> but append my own draw options.
> 
> The definition of drawoptions in plain.mp is
> 
> def drawoptions(text t) =
>   def _op_ = t enddef
> enddef;
> 
> My approach to a macro addtodrawoption() doesn't work (attached below).
>  How would you do that?

You can use expandafter, much like you would in tex:

def addtodrawoptions(text t) =
   expandafter def expandafter _myop_  expandafter = _op_ t enddef;
   let _op_ = _myop_;
enddef;

Best wishes,
Taco


More information about the metapost mailing list