
1 1 Hans Hagen metafun 1 1 2 2 2 2 3 3 For them I owe much inspiration to both my parents. My mother Jannie constantly demonstrates me that computer graphics will never improve nature. She also converted one of my first METAPOST graphics into a patchwork that will remind me forever that handcraft is more vivid than computer artwork. My father Hein has spent a great deal of his life teaching math, and I’m sure he would have loved METAPOST. I inherited his love for books. I therefore dedicate this document to them. Colofon METAPOST This manual is typeset with CONTEXT and . No special tricks are used and everything you see in here, is available for CONTEXT users. The text is typeset in Palatino and Courier. We used PDFTEX as TEX processing engine. Since this document is meant to be printed in color, some examples will look sub--optimal when printed in black and white. Copyright Hans Hagen, PRAGMA Advanced Document Engineering, Hasselt NL copyright: October 27, 2000 Info internet: www.pragma-ade.com support: [email protected] email: [email protected] 3 3 4 4 4 4 5 5 1 Introduction METAPOST This document is about and TEX. The former is a graphic programming language, the latter a typographic programming language. However, in this document we will not focus on real programming, but more on how we can interface between those two languages. We will do METAPOST so by using CONTEXT, a macro package written in TEX, where support for is integrated METAPOST in the core. The TEX macros are integrated in CONTEXT, and the macros are bundled in MetaFun. When Donald Knuth wrote his typographical programming language TEX he was in need for fonts, especially mathematical fonts. So, as a side track, he started writing METAFONT, a graphical language. When you read between the lines in the METAFONT book and the source code, the name John Hobby is mentioned alongside complicated formulas. It will be no surprise then, that, since he was tightly involved in the development of METAFONT, after a few years his METAPOST showed up. While its ancestor METAFONT was originally targeted at designing fonts, METAPOST is more ori- ented to drawing graphics as used in scientific publications. Since METAFONT produced bitmap out- put, some of its operators make use of this fact. METAPOST on the other hand produces POSTSCRIPT code, which means that it has some features not present in METAFONT and vise versa. With MetaFun I will demonstrate that METAPOST can also be used, or misused, for less technical METAPOST drawing purposes. We will see that can fill in some gaps in TEX, especially its lack of graphic capabilities. We will demonstrate that graphics can make a document more attractive, even if it is processed in a batch processing system like TEX. Most of all, we will see that embedding METAPOST definitions in the TEX source enables a smooth communication between both programs. The best starting point for using METAPOST is the manual written by its author John Hobby. METAFONT You can find this manual at every main TEX repository. Also, a copy of the book from Donald Knuth is worth every penny, if only because it will give you the feeling that many years of graphical fun lays ahead. In this MetaFun manual we will demonstrate how you can embed graphics in a TEX docu- ment, but we will also introduce most of the features of METAPOST. For this reason you will see a lot of METAPOST code. For sure there are better methods to solve problems, but I have tried to demonstrate different methods and techniques as much as possible. METAPOST I started using long after I started using TEX, and I never regret it. Although I like METAPOST TEX very much, I must admit that sometimes using is even more fun. Therefore, before we start exploring both in depth, I want to thank their creators, Donald Knuth and John Hob- by, for providing me these fabulous tools. Of course I also need to thank Hàn Thê´ Thành, for giving the TEX community PDFTEX, as well as providing me the hooks I considered neccessary for implementing some of the features presented here. I also want to thank David Arnold and Ton Otten for their fast proofreading, for providing me useful input, and for testing the examples. Without Davids patience and help, this document would be far from perfect English and less complete. Without Tons help, many small typo’s would have gone unnoticed. Hans Hagen, October 27, 2000 Preliminary Version October 27, 2000 5 5 6 6 2 Preliminary Version October 27, 2000 6 6 7 7 3 Content Conventions . 5 4 Enhancing the layout . 101 1 Welcome to METAPOST .......... 7 4.1 Overlays . 101 4.2 Overlay variables . 103 1.1 Paths ......................... 7 4.3 Stacking overlays . 103 1.2 Transformations . 10 4.4 Foregrounds . 104 1.3 Constructing paths . 14 4.5 Typesetting graphics . 105 1.4 Drawing pictures . 23 4.6 Graphics and macros . 107 1.5 Variables . 27 1.6 Conditions . 28 5 Positional graphics . 115 1.7 Loops . 29 1.8 Macros . 30 5.1 The concept . 115 1.9 Pens . 32 5.2 Anchors and layers . 116 1.10 Colors . 35 5.3 Some examples . 119 1.11 Dashes . 35 1.12 Text ......................... 36 6 Page backgrounds . 121 1.13 Linear equations . 37 1.14 Clipping . 44 6.1 The basic layout . 121 1.15 Cutting and pasting . 45 6.2 Setting up backgrounds . 125 6.3 Multiple overlays . 128 2 A few more details . 49 6.4 Crossing borders . 129 6.5 Advanced features . 136 2.1 Making graphics . 49 2.2 Bounding boxes . 50 7 Shapes, symbols and buttons . 137 2.3 Units . 53 2.4 Scaling and shifting . 55 7.1 Interfacing to TEX ............ 137 2.5 Curve construction . 58 7.2 Random graphics . 138 2.6 Inflection, tension and curl . 63 7.3 Graphic variables . 141 2.7 Transformations . 70 7.4 Shape libraries . 141 2.8 Only this far . 73 7.5 Symbol collections . 143 2.9 Directions . 79 2.10 Analyzing pictures . 80 8 Special effects . 145 2.11 Additional operators . 88 8.1 Shading . 145 3 Embedded graphics . 89 8.2 Clipping . 149 8.3 Patterns . 153 3.1 Getting started . 89 8.4 Fonts . 153 3.2 External graphics . 90 3.3 Integrated graphics . 91 9 Typesetting in METAPOST . 155 3.4 Graphic buffers . 94 3.5 Communicating color . 96 9.1 The process . 155 3.6 Common definitions . 97 9.2 Environments . 155 3.7 One page graphics . 98 9.3 Labels . 156 3.8 Managing resources . 99 Preliminary Version October 27, 2000 7 7 8 8 4 9.4 TEX text . 156 A.2 TEX ........................ 241 9.5 Talking to TEX . 166 A.3 ConTEXt .................... 241 A.4 TEXExec . 242 10 Debugging . 183 A.5 MPtoPDF . 242 A.6 Test case . 243 11 Defining styles . 189 B METAPOST syntax . 245 11.1 Adaptive buttons . 189 B.1 Syntax diagrams . 245 12 Functions . 197 B.2 List of things . 254 13 A few applications . 199 C This document . 255 13.1 Simple drawings . 199 D Reference . 257 13.2 Free labels . 202 13.3 Marking angles . 207 D.1 Paths . 257 13.4 Color circles . 213 D.2 Transformations . 265 13.5 Fool yourself . 218 D.3 Points . 273 13.6 Puzzles . 222 D.4 Attributes . 275 13.7 Flow charts . 222 D.5 Text . 280 13.8 Chemistry . 222 13.9 Growing graphics . 223 E Literature . 283 13.10 Simple Logos . 230 13.11 Animations . 235 E.1 METAFONT and METAPOST . 283 E.2 TEX . 283 14 MetaFun macros . 237 E.3 CONTEXT . 283 E.4 Tools . 283 15 Example graphics . 239 E.5 Distributions . 283 A Programs . 241 Index . 285 A.1 METAPOST ................. 241 Preliminary Version October 27, 2000 8 8 9 9 5 Conventions When reading this manual, you may be tempted to test the examples shown. This can be done in several ways. You can make a file and process that file by METAPOST. Such a file looks like: input mp-tool ; % some initializations and auxiliary macros input mp-spec ; % macros that support special features beginfig(1) ; fill fullcircle scaled 5cm withcolor red ; % a graphic endfig ; end . Don’t forget the semi--colons that end the statements. If the file is saved as yourfile.mp, then the file is processed by: mpost yourfile The results are available in yourfile.1 and can be viewed with GHOSTSCRIPT. You don’t need to close the file so reprocessing is very convenient. Alternatively you can use CONTEXT. In that case, a simple file looks like: \starttext \startuseMPgraphic{dummy} fill fullcircle scaled 5cm withcolor red ; \stopuseMPgraphic \useMPgraphic{dummy} \stoptext If the file is saved as yourfile.tex, then you can produce a DVI file with: texexec yourfile A PDF file, viewable in ACROBAT or GHOSTVIEW, is produced with: texexec --pdf yourfile METAPOST Depending on how your system is set up, CONTEXT will run during the TEX run or after- METAPOST wards. If you want to process a file separately using TEXEXEC, you should say: texexec --mptex yourfile.mp This is the preferred way when a graphic contains TEX directives (btex cum suis) or when the METAPOST file is generated by CONTEXT. We will use lots of color. Don’t worry if your red is not our red, or your yellow does not match ours. We’ve made color definitions to match the overall design of this document, but you should feel free to use any color of choice in the upcoming examples.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages294 Page
-
File Size-