[NTG-context] Labels in MetaPost (MetaObj)

Aditya Mahajan adityam at umich.edu
Sat Jan 22 02:38:37 CET 2011

On Sat, 22 Jan 2011, Hans Hagen wrote:

> On 20-1-2011 9:59, Taco Hoekwater wrote:
>> On 01/18/2011 01:17 PM, Stefan Müller wrote:
>>> Hi list,
>>> I'm having some trouble with MetaPost in general and MetaObj in
>>> particular.
>> The core problem is that context mkiv loads the metapost code twice
>> when you are typesetting labels, and that causes trouble for metaobj
>> which does not expect that. Sorry, I do not know of any solution.
>> Maybe Hans does?
> not immediately

A suggestion: Currently, ConTeXt does not clear the state 
of mplib at the end of each graphic. For example

       path p;
       p := fullcircle scaled 4cm ;

       draw p ;

draws a circle. I am not convinced that this is useful. Resetting the state of
mplib after each graphic might be better. Then, after the first run, you could
just set the value of mptopdf.texts[..], reset the state of mplib, and then draw
the graphic in the second run.

This approach will have less surprises. For example, in simpleslides module, we
provide a mechanism for highlighting a part of a picture using arrows. These
arrows are thick (typically 5bp). In order to scale the arrows correctly, we

   autoarrows := true ;

However, in the current implementation, this effect is global. It took a while
to realize that this messed up all the figures with arrows that I was drawing in
a presentation (where autoarrows := false) is better.

Not resetting the mplib state also has advantages. For example, it allows an
easy way to do something on the second path (trivial example, but there are
cases when something like this makes the code much shorter):

       newboolean flag ;
       flag := false ;

       if flag :
         fill boundary withcolor 0.5[blue,white] ;
       else :
         path boundary ;
       fi ;

       path A, B;

       A := fullsquare scaled 3cm ;
       B := fullsquare scaled 3cm shifted (5cm,0) ;

       fill A withcolor white ;
       fill B withcolor white ;

       draw A ; draw btex A etex ;
       draw B ; draw btex B etex shifted (5cm,0) ;

       boundary := (boundingbox currentpicture) enlarged 3mm ;

       flag := true ;


So, perhaps, we can have a `reset` key to \defineMPinstance, and let the user
choose whether to reset after each graphic or not. If `reset=yes` is chosen,
then such errors would not occur.


More information about the ntg-context mailing list