Difference between revisions of "MetaPost"

From Wiki
Jump to navigation Jump to search
(→‎Troubleshooting plain MetaPost: - removed whitespaces)
Line 59: Line 59:
 
* [http://www-math.univ-poitiers.fr/~phan/statsmac.html statsmac] - metapost macros for statistics graphs
 
* [http://www-math.univ-poitiers.fr/~phan/statsmac.html statsmac] - metapost macros for statistics graphs
 
* [http://metauml.sourceforge.net/ MetaUML] - MetaPost library for typesetting UML diagrams
 
* [http://metauml.sourceforge.net/ MetaUML] - MetaPost library for typesetting UML diagrams
 +
* [http://vigna.dsi.unimi.it/metagraph/ METAGRAPH] - drawing (un)directed graphs
  
 
=== 3D support ===
 
=== 3D support ===

Revision as of 01:09, 15 February 2011

< 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 MPtoPDF).

MetaPost is ConTeXt's "native" graphics mode, see MetaFun.


Documentation & Tutorials


Troubleshooting plain MetaPost

  • Test if MetaPost is installed on your system.
  • create test.mp containing this:
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.

Troubleshooting MetaPost embedded in ConTeXt

  • create test.tex containing this:
\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 acroread, okular... You should see a circle.

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

Using MP in ConTeXt

The first way is a usable graphic. Such a graphic is calculated anew each time it is used. An example:

\startuseMPgraphic{name}
  fill fullcircle scaled 5cm withcolor red;
\stopuseMPgraphic

\useMPgraphic{name}

As said, this graphic is calculated each time it is placed, which can be time consuming. Apart from the time aspect, this also means that the graphic itself is incorporated many times. Therefore, for graphics that don’t change, CONTEXT provides reusable graphics:

\startreusableMPgraphic{name}
  fill fullcircle scaled 200pt withcolor .625yellow;
\stopreusableMPgraphic

\reuseMPgraphic{name}

When reusing a graphic is not so important and you just want to include something inline, you can also use the following:

\startMPcode
  fill fullcircle scaled 200pt withcolor .625yellow;
\stopMPcode

See also section 3.3 of MetaFun manual.

Examples


TODO: Enable support for Metapost code when running ConTeXt online. This will allow easy creation of Metapost examples, including both source code and resulted figure. (See: To-Do List)


Currently, running online Metapost code, like this example, does not return anything.

<context source="yes" text="produces">
\startMPcode
  fill fullcircle scaled 200pt withcolor .625yellow;
\stopMPcode
</context>

Other Links