So its either using text or using metaobj? Too bad, metaobj is quite fun... I still hope you guys can fix this, but it's not urgent (to me).

Just as a wild guess I tested the example below today, trying to make use of the things Aditya said, but to no avail. Anyway, what does the [+] after \startMPinclusions? I did not find documentation for that on the wiki.

Best regards,
Stefan.

\startMPinclusions
        input metaobj;
        boolean flag; flag := false;
\stopMPinclusions

\starttext
\startMPpage
        vardef newSegment@\#=
                assignObj(@\#,"Segment");
                ObjPoint a,b;
                ObjCode "@\#b-@\#a=(1cm,2cm)";
        enddef;

        def drawSegment(suffix n)=
                draw n.a--n.b;
        enddef;

        newSegment.s;
        s.a=origin;
        drawObj(s);

        if flag: draw btex A etex; fi;

        flag := true;
\stopMPpage
\stoptext

On 22.01.2011 02:38, Aditya Mahajan wrote:
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

\starttext
\startMPcode
path p;
p := fullcircle scaled 4cm ;
\stopMPcode

\startMPcode
draw p ;
\stopMPcode
\stoptext

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
set:

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):

\startMPinclusions[+]
newboolean flag ;
flag := false ;
\stopMPinclusions

\starttext
\startMPpage
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 ;

\stopMPpage
\stoptext

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.

Aditya



___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to