29.11.2012 Views

MetaFun - Pragma ADE

MetaFun - Pragma ADE

MetaFun - Pragma ADE

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2 A few more details<br />

In this chapter we will see how to define a METAPOST graphic, and how to include it in a document. Since<br />

the exact dimensions of graphics play an important role in the placement of a graphic, we will explore the<br />

way a bounding box is constructed.<br />

We will also pay attention to the usage of units and the side effects of scaling and shifting, since they can<br />

contradict our expectations in unexpected ways. Furthermore we will explore a few obscure areas.<br />

2.1 Making graphics<br />

In this manual we will use METAPOST in a rather straightforward way, and we will try to avoid<br />

complicated math as much as possible. We will do a bit of drawing, clipping, and moving around.<br />

Occasionally we will see some more complicated manipulations.<br />

When defined as stand--alone graphic, a METAPOST file looks like this:<br />

% Let's draw a circle.<br />

beginfig (7) ;<br />

draw fullcircle scaled 3cm withpen pencircle scaled 1cm ;<br />

endfig ;<br />

end .<br />

The main structuring components in such a file are the beginfig and endfig macros. Like in<br />

a big story, the file has many sub--sentences, where each sub--sentence ends with a semi--colon.<br />

Although the end command at the end of the file concludes the story, putting a period there is<br />

a finishing touch. Actually, after the end command you can put whatever text you wish, your<br />

comments, your grocery list, whatever. Comments in METAPOST, prefixed by a percent sign, as in %<br />

Let's draw a circle, are ignored by the interpreter, but useful reminders for the programmer.<br />

If the file is saved as yourfile.mp, then the file is processed by METAPOST by issuing the following<br />

command:<br />

mpost yourfile<br />

after which you will have a graphic called yourfile.7, which contains a series of POSTSCRIPT commands.<br />

Because METAPOST does all the work, this file is efficient and compact. The number of<br />

distinct POSTSCRIPT operators used is limited, which has the advantage that we can postprocess<br />

this file rather easily. Alternatively METAPOST can generate SVG output. It does when you say<br />

outputformat := "svg" ;<br />

Here we will not go into details about this format. Even POSTSCRIPT is not covered in detail as we<br />

use METAPOST mostly in embedded form.<br />

Making graphics A few more details<br />

65

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!