metafun-document.tex /size: 4301 b    last modification: 2023-12-21 09:43
1% language=us runpath=texruns:manuals/metafun
2
3\startcomponent metafun-document
4
5\environment metafun-environment
6
7\startchapter[title={This document}]
8
9\startintro
10
11This document is produced in \CONTEXT\ and can serve as an example of how to
12integrate \METAPOST\ graphics into \TEX. In this appendix we will discuss some
13details of producing this document.
14
15\stopintro
16
17We did not use any special tricks, so most of the examples you have seen are
18coded just as shown. We used buffers to ensure that the code used to produce the
19accompanying graphic is identical to the typeset code in the document. Here is an
20example.
21
22\starttyping
23\startbuffer[dummy]
24draw fullcircle
25  xscaled 3cm yscaled 2cm
26  rotatedaround(origin,30)
27  withcolor .625red ;
28\stopbuffer
29\stoptyping
30
31Instead of using \type {\getbuffer}, we used the following command:
32
33\starttyping
34\startlinecorrection[blank]
35\processMPbuffer[dummy]
36\stoplinecorrection
37\stoptyping
38
39The line correction commands take care of proper spacing around the graphic. If
40you want to process more buffers at once, you can pass their names as a comma
41separated list. Alternatively, we could have said:
42
43\starttyping
44\startuseMPgraphic{dummy}
45  draw fullcircle
46    xscaled 3cm yscaled 2cm
47    rotatedaround(origin,30)
48    withcolor .625red ;
49\stopuseMPgraphic
50\stoptyping
51
52When including this graphic, we again take care of spacing.
53
54\starttyping
55\startlinecorrection[blank]
56\useMPgraphic{dummy}
57\stoplinecorrection
58\stoptyping
59
60The first version of this manual was produced with \PDFTEX\ and call|-|outs to
61\METAPOST. Because the number of graphics is large, we processed that version
62using the \type {--automp} directive (at that moment we were using \TEXEXEC). And
63even then runtime was so unconveniently long that updating this manual became
64less and less fun. The current version is produced with \LUATEX\ and \CONTEXT\
65\MKIV, which brings down the runtime (including runtime calls to independent
66\CONTEXT\ runs for the outline examples) to some 45 seconds on a 2.2 Gig Dell
67M90. Given that (at the time of writing this) over 1700 graphics are generated on
68the fly, this is not bad at all. On my current machine, a Dell M6700 with an
69Intel Core i7|-|3840QM running at 2.8 (3.9) Ghz (and Windows~8) the runtime of
70the third version was just above 20 seconds all|-|in and some 25\percent\ less
71when using \LUAJITTEX. When I started with updating to version 4 of this manual,
72I timed about 15 seconds on the same machine (but with Windows-10) which means
73that in the meantime the \CONTEXT|/|\LUATEX\ combination gained some 25\%
74performance. Using the new Bash|-|On|-|Windows subsystem gives the same
75performance. Of course each update adds pages so in the end we need more time
76with each update but it remains a nice test case. The tight integration of \TEX,
77\METAPOST\ and \LUA\ pays off.
78
79The document style is not that complicated. The main complication in such a
80document is to make sure that \METAPOST\ is operating under the same font regime,
81but in \MKIV\ this happens automatically. As document font we use the URW
82Palatino for the running text combined with Computer Modern Typewriter. Because
83this document is available as paper and screen document, some large graphics are
84scaled down in the screen version.
85
86We don't use any special tricks in typesetting this document, but when we added
87the section about transparency, a dirty trick was needed in a few cases in order to
88get the described results. Because the screen document has gray backgrounds,
89exclusive transparencies come out \quote {wrong}. In the function drawing example
90we use the following trick to get a black background behind the graphics only. We
91have a buffer that contains a few lines of code:
92
93% buffer only available in screen mode
94
95\starttyping
96picture savedpicture ;
97savedpicture := currentpicture ;
98currentpicture := nullpicture ;
99draw savedpicture withcolor black ;
100draw savedpicture ;
101\stoptyping
102
103Since we use buffers for the graphics as well, we can now process a buffer with
104name \type {example} as follows:
105
106\starttyping
107\processbuffer[example,wipe]
108\stoptyping
109
110This means that the example code is included two times. After it is processed, we
111recolor the currentpicture black, and after that we add the original picture once
112again.
113
114\stopchapter
115
116\stopcomponent
117