Download Learning METAPOST by Doing

Transcript
2
André Heck
MAPS 32
beginfig(1);
draw unitsquare scaled 1cm;
endfig;
The exercises give you the opportunity to practice METAPOST, instead of only
reading about the program. Compare your answers with the ones in the section
‘Solutions to the Exercises’.
A Simple Example
METAPOST is not a WYSIWYG drawing tool like xfig or xpaint. It is a graphic
document preparation system. First, you write a plain text containing graphic
formatting commands into a file by means of your favourite editor. Next, the METAPOST program converts this text into a PostScript document that you can preview
and print. In this section we shall describe the basics of this process.
Running METAPOST
EXERCISE 1
Do the following steps:
1. Create a text file, say example.mp, that contains the following very simple METAPOST document:
beginfig(1);
draw (0,0)--(10,0)--(10,10)--(0,10)--(0,0);
endfig;
end;
For example, you can use the editor XEmacs:
xemacs example.mp
The above UNIX command starts the editor and creates the source file
example.mp. It is common and useful practice to always give a METAPOST
source file a name with extension .mp. This will make it easier for you to distinguish the source document from files with other extensions, which METAPOST
will create during the formatting.
2. Generate from this file PostScript code. Here the METAPOST program does the
job:
mpost example
It is not necessary to give the filename extension here. METAPOST now creates
some additional files:
example.1 a PostScript file that can be printed and previewed;
example.log METAPOST’s log file.
3. Check that the file example.1 contains the following normal Encapsulated PostScript code:3
3
Notice that the bounding box is larger than you might expect, due to the default width of the line
drawing the square.