[NTG-context] Circled text in metapost

Alan Braslau braslau.list at comcast.net
Fri Mar 30 16:44:23 CEST 2018


luatex includes the MetaPost library MPlib, so MetaPost code is called
and then injected into the output stream. As a user, it is useful to
know that MP is in fact called in two passes, thus twice, and this can
have some unexpected consequences when not programmed cleanly. Global
variable storage, for example, can reflect the multiple passes. Take
the following (silly) example:


if unknown n : n := 0 ; fi
n := n + 1 ;
draw textext(decimal n) ;

n := n + 1 ;
draw textext(decimal n) ;



(perhaps Hans or Taco can explain why one does not get 2 4)

This side effect is somewhat handled by the fact that each call to MP
is treated as a group : begingroup  ... endgroup so

save n ; n := 0 ;

works as expected, but n is then local and becomes unknown (or keeps
its global value) for subsequent calls to MP.

What should be understood is that calls to MP returns a bounding box to
TeX, and space is reserved for this bounding box. Likewise, calls
within MP to TeX, for example textext() or label(), or btex ... etex
returns a bounding box to MP, and this (picture) object is placed in
the graphic. Mechanisms exist allowing the passing of values of
variables via lua (as strings, in fact). This is a more advanced

Now, there are a number of ways of calling MP from TeX, directly as
above, but also as unique MP graphics or as reusable MP graphics, ...
This is another subject all together.

Hopefully this helps some.


On Fri, 30 Mar 2018 13:31:30 +0200
Gerhard Kugler <G.W.Kugler at posteo.de> wrote:

> Hello,
> my problem is that in other programming langguages there is a main
> procedure which calls others. In metapost in the context of ConteXt I
> can use \starttext ... \stoptext or \startMPpage ... \stopMPpage or
> \beginfig ... \endfig
> And it seems not to be transparent how procedures are called.
> Gerhard

More information about the ntg-context mailing list