[metapost] augment drawoptions

Stephan Hennig mailing_list at arcor.de
Thu Apr 17 15:01:25 CEST 2008


Dan Luecking schrieb:
> 
>>You could do explicit macro definitions and restores with expandafter:
>>
>>def savedrawoptions =
>>    expandafter def expandafter _savedop_ expandafter = _op_ enddef;
>>enddef
>>
>>def restoredrawoptions =
>>    expandafter def expandafter _op_ expandafter = _savedop_ enddef;
>>enddef
> 
> If you combine these as illustrated below, you can make use
> of the endgroup to restore _op_. This permits nested groups.

How does that relate to my last addtomacro attempt?  Is anything wrong
with that?  Admittedly, my solution can lead to multiple

save _op_;

within the same group, if addtodrawoptions is called more than once
inside a group.

>From the top of my head I don't know which saved state of a macro
endgroup restores.  But as the following example demonstrates it
restores the first saved state.  That is, saving an already saved
macro/variable seems to have no effect.

Best regards,
Stephan Hennig


def foo=1 enddef;
show foo;

begingroup
save foo;
  def foo=2 enddef;
  show foo;
save foo;
  def foo=3 enddef;
  show foo;
save foo;
  def foo=4 enddef;
  show foo;
endgroup;

show foo;% returns 1

end


More information about the metapost mailing list