Difference between revisions of "MetaPost"

From Wiki
Jump to navigation Jump to search
m (Add source=yes)
Line 12: Line 12:
 
* [[manual:metafun-s.pdf|MetaFun]]
 
* [[manual:metafun-s.pdf|MetaFun]]
 
* [http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html Lots of examples]
 
* [http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html Lots of examples]
 +
* [[Color in MetaPost]] describes how to get color mixtures, TeX colors, and transparent effects in MetaPost graphics.
  
 
== Using MetaPost in ConTeXt ==
 
== Using MetaPost in ConTeXt ==

Revision as of 13:20, 26 November 2012

< Math, MetaFun, Graphics

MetaPost is a graphical programming language, based on Donald Knuth's MetaFont. Normally MP graphics are converted to PostScript and used with dvips, but ConTeXt can use it directly with PDF (see the MP to PDF manual).

MetaPost is ConTeXt's native graphics language. MetaFun is a MetaPost module by Hans Hagen that adds a lot of extra features; it is enabled by default, so one could say that MetaFun is ConTeXt's default dialect of MetaPost.

Documentation & Tutorials

Using MetaPost in ConTeXt

With \startuseMPgraphic, you define a piece of graphics code that is processed anew every time the graphic is placed with \useMPgraphic.

\def\mycolor{.625red}

\startuseMPgraphic{name}
  fill fullcircle scaled 20pt withcolor \mycolor;
\stopuseMPgraphic

red: \useMPgraphic{name}

\def\mycolor{.625blue}
blue: \useMPgraphic{name}

For graphics that are the same every time, it is better to use \startreuseableMPgraphic: the graphic is compiled only once, and the one resulting picture can be placed at various points with \reuseMPgraphic.

\def\mycolor{.625red}

\startreusableMPgraphic{name}
  fill fullcircle scaled 20pt withcolor \mycolor;
\stopreusableMPgraphic

red: \reuseMPgraphic{name}

\def\mycolor{.625blue}
blue: \reuseMPgraphic{name}

When reusing a graphic is not important, you can simply use \startMPcode.

\startMPcode
  fill fullcircle scaled 20pt withcolor .625green;
\stopMPcode

See also section 3.3 of MetaFun manual.

Different Packages, Extensions & Applications of Metapost

  • finomaton - drawing finite state automata
  • statsmac - metapost macros for statistics graphs
  • MetaUML - MetaPost library for typesetting UML diagrams
  • METAGRAPH - drawing (un)directed graphs

3D support


TODO: needs major review (See: To-Do List)


MetaPost relatives

Font Creation

3D drawing

  • Asymptote - inspired by MetaPost & fully generalizes MetaPost path construction algorithms to three-dimensions

Testing plain MetaPost

To test whether MetaPost is installed on your system, create a file called test.mp:

beginfig(1)
  draw fullcircle scaled 3cm ;
endfig ;
end ;
  • apply MetaPost on the testfile
mp test.mp
or
mpost test.mp
  • that should create a postscript file test.1
  • open test.1 with a postscript viewer like Ghostview, Okular, … You should see a circle.

Testing MetaPost embedded in ConTeXt

If MetaPost is installed on your system and working correctly, you can

\starttext
\startMPcode
  draw fullcircle scaled 3cm;
\stopMPcode
\stoptext
  • for mkii you need to have write18 support enabled and run
texexec --pdf test.tex
  • for mkiv run
context test.tex
  • that should create a pdf file test.pdf
  • open test.pdf with a pdf viewer like Adobe Acrobat, Okular... You should see a circle.

Other Links