[metapost] augment drawoptions

Stephan Hennig mailing_list at arcor.de
Fri Apr 11 23:07:44 CEST 2008


Taco Hoekwater schrieb:
> Stephan Hennig wrote:
>> 
>> ...' 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.
> 
> You can use expandafter, much like you would in tex:

Thanks!  There is one remaining problem: changes to drawoptions are
global.  In the attached example the final stroke is drawn with a thick
pen, instead of the standard pen.

To keep changes to draw options locally, I've tried to save _op_ prior
to using addtodrawoptions.  But again, this doesn't work.  Any ideas?

Best regards,
Stephan Hennig


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

def thick_circle =
begingroup
save _op_;% Doesn't work.
  addtodrawoptions(withpen pencircle scaled 4);
  draw fullcircle scaled 100;
endgroup
enddef;

def thin_circle =
begingroup
save _op_;
  addtodrawoptions(withpen pencircle scaled 2);
  draw fullcircle scaled 100 shifted (0, 100);
endgroup
enddef;

beginfig(1);
  drawoptions(withcolor red);% Set colour.
  thin_circle;
  thick_circle;
  draw (0,0)--(100,100);% Ooops!  Wrong pen width.
endfig;
end


More information about the metapost mailing list