[metapost] augment drawoptions
taco at elvenkind.com
Fri Apr 11 20:10:02 CEST 2008
Stephan Hennig wrote:
> 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;
> drawoptions(withcolor red);% Set colour.
> mydraw;% Circle is drawn red and with a 4bp pen.
> 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
> 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_;
More information about the metapost