MetaPost
Encyclopedia
MetaPost refers to both a programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 and the interpreter of the MetaPost programming language. Both are derived from Donald Knuth
Donald Knuth
Donald Ervin Knuth is a computer scientist and Professor Emeritus at Stanford University.He is the author of the seminal multi-volume work The Art of Computer Programming. Knuth has been called the "father" of the analysis of algorithms...

's Metafont
METAFONT
Metafont is a programming language used to define vector fonts. It is also the name of the interpreter that executes Metafont code, generating the bitmap fonts that can be embedded into e.g. PostScript...

 language and interpreter. MetaPost excels at producing diagrams in the PostScript programming language from a geometric/algebraic description. The language shares Metafont
METAFONT
Metafont is a programming language used to define vector fonts. It is also the name of the interpreter that executes Metafont code, generating the bitmap fonts that can be embedded into e.g. PostScript...

's elegant declarative syntax for manipulating lines, curves, points and geometric transformations. However,
  • Metafont
    METAFONT
    Metafont is a programming language used to define vector fonts. It is also the name of the interpreter that executes Metafont code, generating the bitmap fonts that can be embedded into e.g. PostScript...

     is set up to produce fonts, in the form of image files (in .gf format) with associated font metric files (in .tfm format), whereas MetaPost produces encapsulated PostScript
    Encapsulated PostScript
    Encapsulated PostScript, or EPS, is a DSC-conforming PostScript document with additional restrictions which is intended to be usable as a graphics file format...

     files
  • The output of Metafont
    METAFONT
    Metafont is a programming language used to define vector fonts. It is also the name of the interpreter that executes Metafont code, generating the bitmap fonts that can be embedded into e.g. PostScript...

     consists of the fonts at a fixed resolution in a raster-based format, whereas MetaPost's output is vector-based postscript graphics (lines, Bézier curve
    Bézier curve
    A Bézier curve is a parametric curve frequently used in computer graphics and related fields. Generalizations of Bézier curves to higher dimensions are called Bézier surfaces, of which the Bézier triangle is a special case....

    s)
  • Metafont
    METAFONT
    Metafont is a programming language used to define vector fonts. It is also the name of the interpreter that executes Metafont code, generating the bitmap fonts that can be embedded into e.g. PostScript...

     output is monochrome, whereas MetaPost uses a simple RGB colour specification.
  • The MetaPost language can include text labels on the diagrams, either strings from a specified font, or pretty much anything that can be typeset with TeX
    TeX
    TeX is a typesetting system designed and mostly written by Donald Knuth and released in 1978. Within the typesetting system, its name is formatted as ....

  • The Metafont interpreter was written by Donald Knuth
    Donald Knuth
    Donald Ervin Knuth is a computer scientist and Professor Emeritus at Stanford University.He is the author of the seminal multi-volume work The Art of Computer Programming. Knuth has been called the "father" of the analysis of algorithms...

     under an open source
    Open source
    The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

     license, allowing John D. Hobby to adapt the interpreter to his own ends, giving us MetaPost.


Many of the limitations of MetaPost derive from features of Metafont. For instance, numbers have a low-precision fixed-point representation, sufficient for representing the coordinates of points in a glyph, but this can be restrictive when working with figures in a larger coordinate space. Moreover, MetaPost does not support all features of PostScript. Most notably, paths can have only one segment (so that regions are simply connected), and regions can be filled only with uniform colours. PostScript level 1 supports tiled patterns and PostScript 3 supports Gouraud shading
Gouraud shading
Gouraud shading, named after Henri Gouraud, is an interpolation method used in computer graphics to produce continuous shading of surfaces represented by polygon meshes...

. To this end, the Asymptote
Asymptote (vector graphics language)
Asymptote is a descriptive vector graphics language, developed by Andy Hammerlindl, John C. Bowman , and Tom Prince, that provides a natural coordinate-based framework for technical drawing. Asymptote runs on all major platforms...

 graphics language has been developed to address these shortcomings.

Availability, usage

MetaPost is distributed with many current distributions of the TeX
TeX
TeX is a typesetting system designed and mostly written by Donald Knuth and released in 1978. Within the typesetting system, its name is formatted as ....

 and Metafont
METAFONT
Metafont is a programming language used to define vector fonts. It is also the name of the interpreter that executes Metafont code, generating the bitmap fonts that can be embedded into e.g. PostScript...

 framework. In particular, it is included in the teTeX
TeTeX
teTeX is a TeX distribution for Unix-like systems. As of May 2006 teTeX is no longer actively maintained and its former maintainer Thomas Esser recommended TeX Live as the replacement....

 and the TeX Live
TeX Live
TeX Live is a TeX distribution which is the replacement of its no-longer supported counterpart teTeX.It is now the default TeX distribution for several Linux distributions such as Fedora, Debian, Ubuntuand Gentoo....

 distribution, common on Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

 and Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 (including Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

) platforms.

The encapsulated postscript produced by Metapost is easily included in TeX
TeX
TeX is a typesetting system designed and mostly written by Donald Knuth and released in 1978. Within the typesetting system, its name is formatted as ....

, ConTeXt
ConTeXt
ConTeXt is a general-purpose document processor. It is especially suited for structured documents, automated document production, very fine typography, and multi-lingual typesetting. It is based in part on the TeX typesetting system, and uses a document markup language for manuscript preparation...

, and LaTeX
LaTeX
LaTeX is a document markup language and document preparation system for the TeX typesetting program. Within the typesetting system, its name is styled as . The term LaTeX refers only to the language in which documents are written, not to the editor used to write those documents. In order to...

 documents via standard eps-inclusion commands. Particularly useful is the ability to include this output in the PDFTeX
PdfTeX
The computer program pdfTeX is an extension of Knuth's typesetting program TeX, and was originally written and developed into a publicly usable product by Hàn Thế Thành as a part of the work for his PhD thesis at the Faculty of Informatics, Masaryk University, Brno...

 dialect of TeX
TeX
TeX is a typesetting system designed and mostly written by Donald Knuth and released in 1978. Within the typesetting system, its name is formatted as ....

, thus giving Portable Document Format
Portable Document Format
Portable Document Format is an open standard for document exchange. This file format, created by Adobe Systems in 1993, is used for representing documents in a manner independent of application software, hardware, and operating systems....

 output from TeX
TeX
TeX is a typesetting system designed and mostly written by Donald Knuth and released in 1978. Within the typesetting system, its name is formatted as ....

 in a single step. This ability is implemented in ConTeXt
ConTeXt
ConTeXt is a general-purpose document processor. It is especially suited for structured documents, automated document production, very fine typography, and multi-lingual typesetting. It is based in part on the TeX typesetting system, and uses a document markup language for manuscript preparation...

 and in the LaTeX graphics package, and can be used from plain TeX via the supp-pdf.tex macro file. ConTeXt even supports the creation of MetaPost files from within the TeX file.

Although MetaPost itself cannot generate fonts, there is another program, METATYPE1
METATYPE1
METATYPE1 is a tool for creating Type 1 fonts using METAPOST, developed by the Polish JNS team ....

, that is designed to create Type1 fonts through MetaPost.

Examples

This is a single file example.mp which when processed by the MetaPost interpreter (via the command mpost on Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

) 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);
beginfig (1)
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;
endfig;
beginfig (2)
draw (for i=0 upto 7: dir (135i)-- endfor cycle)
transformed pagecoords;
endfig;
pagecoords:=identity scaled 15mm shifted (100mm,150mm);
beginfig (3);
% declare paths to be used
path p[],p[]t;
% set up points by defining relationships
z1=(0,0); z2=z1+2up;
z3=z1+whatever*dir (60)=z2+whatever*dir (-50);
z4=z3+(-1.5,-.5);
z5=z1+dir (135);
z0=whatever[z1,z2]=whatever[z3,z4];
% set up paths
p0=fullcircle yscaled .5 rotated 45 shifted z0 ;
p1=z2---z4..z0..z3---z1;
p2=p1 cutbefore p0 cutafter p0;
p3=p0 cutbefore p1 cutafter p1;
p4=p2---p3---cycle;
% 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);
label.top (btex $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;
endfor
endfig;
bye


The resulting three eps files can be used in TeX
TeX
TeX is a typesetting system designed and mostly written by Donald Knuth and released in 1978. Within the typesetting system, its name is formatted as ....

 via LaTeX
LaTeX
LaTeX is a document markup language and document preparation system for the TeX typesetting program. Within the typesetting system, its name is styled as . The term LaTeX refers only to the language in which documents are written, not to the editor used to write those documents. In order to...

's \includegraphics command, ConTeXt
ConTeXt
ConTeXt is a general-purpose document processor. It is especially suited for structured documents, automated document production, very fine typography, and multi-lingual typesetting. It is based in part on the TeX typesetting system, and uses a document markup language for manuscript preparation...

's \externalfigure, 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 font (Metafont
METAFONT
Metafont is a programming language used to define vector fonts. It is also the name of the interpreter that executes Metafont code, generating the bitmap fonts that can be embedded into e.g. PostScript...

) is not included in the eps files produced by MetaPost.

See also

  • PSTricks
    PSTricks
    PSTricks is a set of macros that allow the inclusion of PostScript drawings directly inside TeX or LaTeX code.It is originally the work of Professor Timothy Van Zandt and in recent years it has been maintained by Denis Girou, Sebastian Rahtz and Herbert Voss....

  • PGF/TikZ
    PGF/TikZ
    PGF/TikZ is a tandem of languages for producing vector graphics from a geometric/algebraic description. PGF is a lower-level language, while TikZ is a set of higher-level macros that use PGF. The top-level PGF and TikZ commands are invoked as TeX macros, but in contrast with PSTricks, the PGF/TikZ...

  • MetaFont
    METAFONT
    Metafont is a programming language used to define vector fonts. It is also the name of the interpreter that executes Metafont code, generating the bitmap fonts that can be embedded into e.g. PostScript...

  • METATYPE1
    METATYPE1
    METATYPE1 is a tool for creating Type 1 fonts using METAPOST, developed by the Polish JNS team ....

  • Asymptote
    Asymptote (vector graphics language)
    Asymptote is a descriptive vector graphics language, developed by Andy Hammerlindl, John C. Bowman , and Tom Prince, that provides a natural coordinate-based framework for technical drawing. Asymptote runs on all major platforms...


External links

  • The TeX users group (TUG) http://www.tug.org/ has a page devoted to MetaPost: http://www.tug.org/metapost.html
  • Active development of MetaPost continues at http://foundry.supelec.fr/projects/metapost/
  • Functional MetaPost allows MetaPost to be used from the functional programming language Haskell
    Haskell (programming language)
    Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...

  • John D. Hobby has a homepage at http://ect.bell-labs.com/who/hobby/index.shtml and some other pages and publications devoted to MetaPost, though these are now a little dated
    • Historic MetaPost homepage: http://ect.bell-labs.com/who/hobby/MetaPost.shtml
    • A User's Manual for MetaPost John D. Hobby. Available as a file mpman.ps distributed with MetaPost, or from the Bell Labs web site. Also available in PDF format from CTAN
      CTAN
      CTAN is an acronym for the Comprehensive TeX Archive Network.It is the authoritative place where TeX related material and software can be found for download...

      .
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK