Hello,

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:

\starttext

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

\startMPcode
n := n + 1 ;
draw textext(decimal n) ;
\stopMPcode

\stoptext

yielding:
1
3

(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

\startMPcode
save n ; n := 0 ;
...
\stopMPcode

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
subject.


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.

Alan



On Fri, 30 Mar 2018 13:31:30 +0200
Gerhard Kugler <g.w.kug...@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
> 
> 

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to