[NTG-context] Wrong MetaPost text output

Hans Hagen j.hagen at xs4all.nl
Sun Aug 11 19:30:13 CEST 2019


On 8/11/2019 6:09 PM, Henri Menke wrote:
> Dear devs,
> 
> There seems to be a bug in the MetaPost integration of ConTeXt.  The MWE
> below should produce three different labels “dummy foo bar” but instead
> produces “bar bar bar”.  The same example works correctly in plain
> MetaPost.  Originally reported on
> 
>      https://tex.stackexchange.com/questions/503773/strange-behaviour-of-the-btex-etex-construct
> 
> Cheers, Henri
> 
> ---
> 
> \starttext
> \startMPpage
> def drawtest(expr i) = %i is not used here
>      draw btex dummy etex shifted (0,0);
>      draw btex foo   etex shifted (1.5cm,0);
>      draw btex bar   etex shifted (3cm,0);
> enddef;
> drawtest(5);
> \stopMPpage
> \stoptext
It's not a really bug but a side effect. When metapost parses btex .. 
etex it immediately replaces its content. In mpost the program that is 
hardcoded as 'call out to tex and convert the dvi result into a 
picture'. This parsing is not 'delayed' by wrapping in macro.

So in this case, what happens is that where normally there is some 
interplay between context and the library, this kind of gets messed up. 
Using btex inside a macro body is just a bad idea.

def drawtest(expr i) = %i is not used here
       draw textext("dummy") shifted (0,0);
       draw textext("foo")   shifted (1.5cm,0);
       draw textext("bar")   shifted (3cm,0);
enddef;

works fine because it is not replaced in the macro body when parsed.

In context lmtx I will give a warning when "btex .. etex" is used inside 
a macro definition. Actually btex/etex is just supported in context as a 
kind of 'service' (we could just drop it).

Anyway, you can advice not to use "btex .. etex" but textext instead. As 
with all things tex (and mp) with some hasty programming much can be 
solved but in this case it's not worth the effort and for sure it will 
bring up other side effects.

(In a similar fashion it's not a good idea to have global textexts 
because there are local stored for them but in that case one can enforce 
a persistent textext if needed.)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the ntg-context mailing list