luametafun-introduction.tex /size: 4705 b    last modification: 2021-10-28 13:50
1% language=us runpath=texruns:manuals/luametafun
2
3\environment luametafun-style
4
5\startcomponent luametafun-introduction
6
7\startchapter[title={Introduction}]
8
9For quite a while, around since 1996, the integration of \METAPOST\ into
10\CONTEXT\ became sort of mature but, it took decades of stepwise refinement to
11reach the state that we're in now. In this manual I will discuss some of the
12features that became possible by combining \LUA\ and \METAPOST. We already had
13quite a bit of that for a decade but in 2018, when \LUAMETATEX\ showed up a next
14stage was started.
15
16Before we go into details it is good to summarize the steps that were involved in
17integrating \METAPOST\ and \TEX\ in \CONTEXT. It indicates a bit what we had and
18have to deal with which in turn lead to the interfaces we now have.
19
20Originally, \TEX\ had no graphic capabilities: it just needed to know dimensions
21of the graphics and pass some basic information about what to include to the
22\DVI\ post processor. So, a \METAPOST\ graphic was normally processed outside the
23current run, resulting in \POSTSCRIPT\ graphic, that then had to be included. In
24\PDFTEX\ there were some more built in options, and therefore the \METAPOST\ code
25could be processed runtime using some (generic) \TEX\ macros that I wrote.
26However, that engine still had to launch \METAPOST\ for each graphic, although we
27could accumulate them and do that between runs. Immediate processing means that
28we immediately know the dimensions, while a collective run is faster. In \LUATEX\
29this all changed to very fast runtime processing, made possible because the
30\METAPOST\ library is embedded in the engine, a decision that we made early in
31the project and never regret.
32
33With \PDFTEX\ the process was managed by the \type {texexec} \CONTEXT\ runner but
34with \LUATEX\ it stayed under the control of the current run. In the case of
35\PDFTEX\ the actual embedding was done by \TEX\ macros that interpreted the
36(relatively simple) \POSTSCRIPT\ code and turned it into \PDF\ literals. In
37\LUATEX\ that job was delegated to \LUA.
38
39When using \PDFTEX\ with independent \METAPOST\ runs support for special color
40spaces, transparency, embedded graphics, outline text, shading and more was
41implemented using specials and special colors where the color served as reference
42to some special extension. This works quite well. In \LUATEX\ the pre- and
43postscript features, which are properties of picture objects, are used.
44
45In all cases, some information about the current run, for instance layout related
46information, or color information, has to be passed to the rather isolated
47\METAPOST\ run. In the case if \LUATEX\ (and \MKIV) the advantage is that
48processing optional text happens in the same process so there we don't need to
49pass information about for instance the current font setup.
50
51In \LUATEX\ the \METAPOST\ library has a \type {runscript} feature, which will
52call \LUA\ with the given code. This permitted a better integration: we could now
53ask for specific information (to the \TEX\ end) instead of passing it from the
54\TEX\ end with each run. In \LUAMETATEX\ another feature was added: access to the
55scanners from the \LUA\ end. Although we could already fetch some variables when
56in \LUA\ this made it possible to extend the \METAPOST\ language in ways not
57possible before.
58
59Already for a while Alan Braslau and I were working on some new \METAFUN\ code
60that exploits all these new features. When the scanners came available I sat down
61and started working on new interfaces and in this manual I will discuss some of
62these. Some of them are illustrative, others are probably rather useful. The core
63of what we could call \LUAMETAFUN\ (or \METAFUN\ XL when we use the file
64extension as indicator) is a key|-|value interface as we have at the \TEX\ end.
65This interface relates to \CONTEXT\ \LMTX\ development and therefore related
66files have a different suffix: \type {mpxl}. However, keep in mind that some are
67just wrappers around regular \METAPOST\ code so you have the full power of
68traditional \METAPOST\ at hand.
69
70We can never satisfy all needs, so to some extent this manual also demonstrates
71how to roll out your own code, but for that you also need to peek into the
72\METAFUN\ source code too. It will take a while for this manual to complete. I
73also expect other users to come up with solutions, so maybe in the end we will
74have a collection of modules for specific tasks.
75
76\startlines
77Hans Hagen
78Hasselt NL
79August 2021 (and beyond)
80\stoplines
81
82\stopchapter
83
84\stopcomponent
85
86% I started writing this in 2019, a few days after seeing Wende live in Zeist (
87% (YT: WENDE - # MENS), one of the best shows of that year, a clear reminder of
88% timeless versatility.
89