Main Page | See live article | Alphabetical index


MetaPost is both a programming language and the only known interpreter of the MetaPost programming language. Both are derived from Donald Knuth's Metafont language and interpreter. MetaPost excels at producing diagrams in the PostScript programming language from a geometric/algebraic description. The language shares Metafont's elegant declarative syntax for manipulating lines, curves, points and geometric transformations. However,

Table of contents
1 Availability, usage
2 Examples
3 References and External Links

Availability, usage

MetaPost is distributed with many current distributions of the TeX and Metafont framework. In particular, it is included in teTeX distribution, common on Linux and Unix (including Mac OS X) platforms. The encapsulated postscript produced by Metapost is easily included in TeX and LaTeX documents either via standard eps-inclusion commands. Particularly useful is the ability to include this output in the PDFTeX dialect of TeX, thus giving Portable Document Format output from TeX in a single step. This ability is implemented in the LaTeX graphics package, and can be used from plain TeX via the supp-pdf.tex macro file.


This is a single file which when processed by the MetaPost interpreter (via the command mpost on Linux) produces three eps files example.1, example.2, example.3. These are pictured on the right.

transform pagecoords;
pagecoords:=identity scaled 10mm shifted (100mm,150mm);

    fill ((0,0)--(2,0)--(2,1)--(1,1)--(1,2)--(0,2)--cycle)
        transformed pagecoords withcolor green;
    draw ((2,0)..(2,1)..(1,1)..(1,2)..(0,2))
        transformed pagecoords;
    drawarrow ((0,0)--(2,2)) transformed pagecoords;

    draw (for i=0 upto 7: dir(135i)-- endfor cycle)
        transformed pagecoords;
pagecoords:=identity scaled 15mm shifted (100mm,150mm);
    % declare paths to be used
    path p[],p[]t;
    % set up points by defining relationships
    z1=(0,0);   z2=z1+2up;
    % set up paths
    p0=fullcircle yscaled .5 rotated 45 shifted z0 ;
    p2=p1 cutbefore p0 cutafter p0;
    p3=p0 cutbefore p1 cutafter p1;
    % define transformed versions of paths and points
    for i=0 upto 4: p[i]t=p[i] transformed pagecoords; endfor
    for i=0 upto 5: z[i]t=z[i] transformed pagecoords; endfor
    % do some drawing
    fill p4t withcolor (1,1,0.2);
    draw z1t--z2t withcolor .5white;
    draw z3t--z4t withcolor .5white;
    pickup pencircle;
    draw p0t dashed withdots scaled .3;
    draw p1t dashed evenly;
    draw p2t withcolor blue;
    draw p3t withcolor red;
    label.lrt(btex $z_0$ etex, z0t);
    label.llft(btex $z_1$ etex, z1t); $z_2$ etex, z2t);
    label.rt(btex $z_3$ etex, z3t);
    label.llft(btex $z_4$ etex, z4t);
    for i=0 upto 4:
        drawdot z[i]t withpen pencircle scaled 2;

The resulting three eps files can be used in TeX via LaTeX's \\includegraphics command, Plain TeX's \\epsfbox command, or (in Plain pdftex) the \\convertMPtoPDF command from supp-pdf.tex. To view or print the third diagram, this inclusion is necessary, as the TeX fonts are not included in the eps files produced by MetaPost.

References and External Links