metafun-introduction.tex /size: 6747 b    last modification: 2023-12-21 09:43
1% language=us runpath=texruns:manuals/metafun
2
3\startcomponent metafun-introduction
4
5\environment metafun-environment
6
7\starttitle[title={Introduction}]
8
9This document is about \METAPOST\ and \TEX. The former is a graphic programming
10language, the latter a typographic programming language. However, in this
11document we will not focus on real programming, but more on how we can interface
12between those two languages. We will do so by using \CONTEXT, a macro package
13written in \TEX, in which support for \METAPOST\ is integrated in the core. The
14\TEX\ macros are integrated in \CONTEXT, and the \METAPOST\ macros are bundled in
15\METAFUN.
16
17When Donald Knuth wrote his typographical programming language \TEX\ he was in
18need for fonts, especially mathematical fonts. So, as a side track, he started
19writing \METAFONT, a graphical language. When you read between the lines in the
20\METAFONT\ book and the source code, the name John Hobby is mentioned alongside
21complicated formulas. It will be no surprise then, that, since he was tightly
22involved in the development of \METAFONT, after a few years his \METAPOST\ showed
23up.
24
25While its ancestor \METAFONT\ was originally targeted at designing fonts,
26\METAPOST\ is more oriented to drawing graphics as used in scientific
27publications. Since \METAFONT\ produced bitmap output, some of its operators make
28use of this fact. \METAPOST\ on the other hand produces \POSTSCRIPT\ code, which
29means that it has some features not present in \METAFONT\ and vice versa.
30
31With \METAFUN\ I will demonstrate that \METAPOST\ can also be used, or misused,
32for less technical drawing purposes. We will see that \METAPOST\ can fill in some
33gaps in \TEX, especially its lack of graphic capabilities. We will demonstrate
34that graphics can make a document more attractive, even if it is processed in a
35batch processing system like \TEX. Most of all, we will see that embedding
36\METAPOST\ definitions in the \TEX\ source enables a smooth communication between
37both programs.
38
39The best starting point for using \METAPOST\ is the manual written by its author
40John Hobby. You can find this manual at every main \TEX\ repository. Also, a copy
41of the \METAFONT\ book from Donald Knuth is worth every cent, if only because it
42will give you the feeling that many years of graphical fun lays ahead.
43
44In this \METAFUN\ manual we will demonstrate how you can embed graphics in a
45\TEX\ document, but we will also introduce most of the features of \METAPOST. For
46this reason you will see a lot of \METAPOST\ code. For sure there are better
47methods to solve problems, but I have tried to demonstrate different methods and
48techniques as much as possible.
49
50I started using \METAPOST\ long after I started using \TEX, and I never regret
51it. Although I like \TEX\ very much, I must admit that sometimes using \METAPOST\
52is even more fun. Therefore, before we start exploring both in depth, I want to
53thank their creators, Donald Knuth and John Hobby, for providing me these
54fabulous tools. Of course I also need to thank \THANH, for giving the \TEX\
55community \PDFTEX, as well as providing me the hooks I considered necessary for
56implementing some of the features presented here. In the meantime Taco Hoekwater
57has created the \METAPOST\ library so that it can be an integral component of
58\LUATEX. After that happened, the program was extended to deal with more than one
59number implementation: in addition to scaled integers we now can switch to floats
60and arbitrary precision decimal or binary calculations. I myself prototyped a
61simple but efficient \LUA\ script interface. With Luigi Scarso, who is now the
62maintainer of \METAPOST, we keep improving the system, so who knows what will
63show up next.
64
65I also want to thank David Arnold and Ton Otten for their fast proofreading, for
66providing me useful input, and for testing the examples. Without David's patience
67and help, this document would be far from perfect English and less complete.
68Without Ton's help, many small typos would have gone unnoticed.
69
70In the second version of this manual the content was been adapted to \CONTEXT\
71\MKIV\ that uses \LUATEX\ and the built in \METAPOST\ library. In the meantime
72some \LUA\ has been brought into the game, not only to help construct graphics,
73but also as a communication channel. In the process some extra features have been
74added and some interfacing has been upgraded. The third version of this document
75deals with that too. It makes no sense to maintain compatibility with \CONTEXT\
76\MKII, but many examples can be used there as well. In the meantime most
77\CONTEXT\ users have switched to \MKIV, so this is no real issue. In the fourth
78update some new features are presented and the discussion of obsolete ones have
79been removed.
80
81The fifth update describes the \MPIV\ version of \METAFUN\ which brings some more
82and improved functionality. Some examples are inspired from questions by users and
83examples that Alan Braslau, Luigi Scarso and I made when testing new features and
84macros. Some examples can be rewritten in a more efficient way but are kept as
85they are. Therefore this manual presents different ways to solve problems.
86Hopefully this is not too confusing. Numerous examples can be found in the other
87manuals and test suite.
88
89The first version of \METAFUN\ evolved in \CONTEXT\ \MKII, and when we moved to
90\MKIV\ some interfaces (especially the extensions) could be made better. We now
91have \LMTX\ so we can make even those better (and often easier). The downside is
92that some features discussed here won't work in \MKII\ and \MKIV. If you run into
93that, just consider updating to \LMTX. The current version should process okay
94with the latest version; thanks to Otared Kavian for keeping an eye on that and
95posting me possible issues. The real new features are part of what is to become
96\LUAMETAFUN, but for that we have a separate manual.
97
98In 2022 Mikael Sundqvist and I spent a lot of time on improving math in both
99\LUAMETATEX\ and \CONTEXT\ \LMTX, which is now the main version. Because we're both
100\METAPOST\ fans we let ourselves being sidetracked to also explore new possibilities
101in the library. Some of the macros that evolved from that made it into \METAFUN\
102which is why we also discuss some here. Be aware of the fact that we do some things
103different in \LMTX\ than in \MKIV, for instance we moved to colors being specified
104as strings (references to colors defined in \CONTEXT). There are also some new
105features that are unique to the library in \LUAMETATEX, like \type {&&}, \type
106{&&&}, \type {&&&&} and \type {nocycle}. THis means that not everything discussed
107here works in \MKIV\ too.
108
109\blank[big,samepage]
110
111\startlines
112Hans Hagen
113Hasselt NL
114\currentdate[month,year]
115\stoplines
116
117\stoptitle
118
119\stopcomponent
120