ConTeXt is a general purpose TeX macro package by Hans Hagen; for some, it will be a serious alternative to LaTeX. See http://www.pragma-ade.com/ for details.

MetaPost is a MetaFont like system by John Hobby which can output postscript and pdf files. The package can be used to draw elaborate postscript illustrations. See http://cm.bell-labs.com/who/hobby/MetaPost.html for more details. Interesting metapost examples can be found at many web sites; for instance see http://www.cs.ucc.ie/~dongen/mpost/mpost.html. TeXShop now supports MetaPost.

Here is a sample MetaPost file:

prologues:=2;
color yellow; yellow = green + red;

def star (expr size, n, pos, color)=
for a=0 step 360/n until 360:
draw (origin -- (size/2,0))
rotatedaround (origin, a)
shifted pos withcolor color;
endfor ;
enddef;

beginfig(1);
pickup pencircle scaled 2mm; star (2cm,5,origin,red);
endfig;

beginfig(2);
pickup pencircle scaled 2mm; star (2cm,7,origin,yellow);
endfig;

beginfig(3);
pickup pencircle scaled 2mm; star (2cm,11,origin,green);
endfig;

beginfig(4);
pickup pencircle scaled 2mm; star (2cm,13,origin,blue);
endfig;

end

Suppose this file is named "metademo.mp." When the file is processed by MetaPost, it will generate four different postscript files, named metademo.1, metademo.2, metademo.3, metademo.4. These names are determined by the number parameter of "beginfig()." If this number is nonnegative, like beginfig(0) or beginfig(10), the resulting file will be named metademo.0 or metademo.10. If this number is negative, like beginfig(-10), the resulting file will be named metademo.ps, overwriting any earlier metademo.ps file created by the source.

In its default configuration, TeXShop assumes that one of the numbers is zero. TeXShop calls the script pstopdf, which runs MetaPost and thus creates all of these postscript files. The script then converts each postscript file to a pdf file. Finally, the script renames the zeroth pdf file to the name of the source with extension "pdf", for instance metademo.pdf and displays this figure in the preview screen.

When you are editing a MetaPost file, change the number of the figure being edited from positive to zero. TeXShop will then display this figure as it is being debugged. When you are satisfied with this figure, change its number back to positive and change the number of another figure from positive to zero.

Once MetaPost files have been created, then can be displayed like any other illustration. Pdflatex can be used if the illustrations are converted to pdf form, or TeX and Ghostscript can be used to include the postscript illustrations without conversion. For example, the four illustrations created by the above MetaPost file can be displayed by typesetting the following file with TeX and Ghostscript:

\documentclass[11pt] {article}
\usepackage{graphicx}
\begin{document}
Here are some illustrations.
\vspace{.2in}
\includegraphics[width=1cm]{metademo.1}
\hfill
\includegraphics[width=1cm]{metademo.2}
\hfill
\includegraphics[width=1cm]{metademo.3}
\hfill
\includegraphics[width=1cm]{metademo.4}
\hfill
\end{document}

It is also possible to embed MetaPost source code directly in a Latex document using the package mfpic. When this method is used, the MetaPost preference should be set to "mpost" rather than "mptopdf" in the Preferences dialog so MetaPost will run directly when the MetaPost engine is selected. A document containing MetaPost source code is first typeset with pdflatex or latex, creating a mp source file with all of the document's illustrations. This file is then compiled with MetaPost. Finally, the document is typeset again with pdflatex or latex to show the resulting illustrations.

Below is an example created by Claus Gerhardt. Save this example as "MetaPostTest". Notice the line "\opengraphsfile{MetaPostTest}" in the source. Although the mfpic package permits any name for this graph file, its name must be the same as the document name to use the following procedure in TeXShop. Typeset the document once, switch to MetaPost and typeset again, switch back to LaTeX and typeset a final time. In this process, either pdflatex or latex + ghostscript can be used for the first and third steps.

% This example is a shortened version of an example provided by
% Claus Gerhardt.

\documentclass[11pt]{article}
\usepackage[metapost]{mfpic}
\usepackage{amsmath}
\opengraphsfile{MetaPostTest}

\title{Brief Article}
\author{The Author}
\begin{document}
\maketitle

\begin{mfpic}[20]{-0.5}{11}{-0.5}{11}
{\drawcolor{red}\function{0,10,0.05}{10-x}}
{\drawcolor{blue}\function{0.99,10,0.05}{10/x}}
{\drawcolor{green}\dashed\lines{(0.0,4),(10,4)}}
\tlabelcolor{black}
\drawcolor{black}\ymarks[4pt]{4}
\headcolor{black}
\drawcolor{2*black}\axes
\tlabel{(4,6.5)}{$P_{\negthickspace c}$}
\tlabel{(6,6.5)}{$P_{c}$}
\tlabel(5,3.5){$A$}
\tlabel{(-.6,3.9)}{$4$}
\end{mfpic}

\begin{center}
\begin{mfpic}[15]{-2.2}{5}{-2.2}{2.2}
\store{a}{\circle{(0,0),2}}
\store{b}{\circle{(2 *sqrt 2,0),2}}
\store{c}{\arc[p]{(0,0),-45,45,2}}
\gfill[0.7white]\lclosed\mfobj{a}
\gfill[white]\lclosed\mfobj{b}
\draw\mfobj{a}\draw\mfobj{b}
\tlabel(-1,-0.3){ $A$ }
\tlabel(3,-0.3){ $B$ }
\end{mfpic}
\end{center}

\closegraphsfile
\end{document}

The following example, also provided by Claus Gerhardt, shows the power of MetaPost.

% This example was provided by Claus Gerhardt
% Most of the figures and the text are taken from G.'s book
% "Analysis I" published by International Press, Boston,
% which will appear at the beginning of 2004.

\documentclass[11pt]{amsart}
\usepackage[metapost]{mfpic}
\usepackage{amsmath}
\usepackage{amsthm}
\RequirePackage{amssymb}
\RequirePackage[mathscr]{eucal}
\opengraphsfile{MetaPostTest}

\DeclareMathOperator*{\Au}{\forall}
\DeclareMathOperator*{\Eu}{\exists}
\newcommand{\msc}{\protect\mathscr}
\newcommand\su{\subset}
\newcommand{\pri}[1]{#1^\prime}
\newcommand{\tit}[1]{\textit{\ignorespaces #1\ignorespaces}}
\newcommand{\Cc}{{\protect\mathbb C}}
\newcommand\ra{\rightarrow}
\newcommand{\abs}[1]{\lvert#1\rvert}
\newcommand{\fv}[2]{#1\hspace{0pt}_{|_{#2}}}
\newcommand{\set}[2]{\{\,#1\colon #2\,\}}
\newcommand\inn[1]{{\overset{\msp[9]\circ}{#1}}}
\newcommand{\msp}[1][1]{\mspace{#1mu}}
\newcommand{\Si}{\varSigma}

\theoremstyle{remark}
\newtheorem*{definition}{\bf Definition}
\theoremstyle{theorem}
\newtheorem*{theorem}{Theorem}

\title{An Example of Using MetaPost with mfpic}
%\author{The Author}

\begin{document}
\maketitle
\thispagestyle{empty}

\bigskip
\begin{mfpic}[20]{-0.5}{11}{-0.5}{11}
{\drawcolor{red}\function{0,10,0.05}{10-x}}
{\drawcolor{blue}\function{0.99,10,0.05}{10/x}}
{\drawcolor{green}\dashed\lines{(0.0,4),(10,4)}}
\tlabelcolor{black}
\drawcolor{black}\ymarks[4pt]{4}
\headcolor{black}
\drawcolor{2*black}\axes
\tlabel{(4,6.5)}{$P_{\negthickspace c}$}
\tlabel(5,3.5){$A$}
\tlabel{(-.6,3.9)}{$4$}
\end{mfpic}

\bigskip
\begin{definition}
Let $E,\pri E$ be metric spaces and $f:E\rightarrow \pri E$ a map. $f$ is called \tit{continuous} at $x_0\in E$ if
\begin{equation}\notag
\Au_{\pri U\in \msc U(f(x_0))}\; \Eu_{U\in \msc U(x_0)}\quad f(U)\su \pri U.
\end{equation}
$f$ is called continuous in $E$ if $f$ is continuous at every point of $E$.
\end{definition}

\bigskip
\begin{center}
\begin{mfpic}[15]{-4.2}{16}{-4.2}{4.2}
\store{R}{\rect{(-4,-4),(4,4)}}
\store{U}{\cyclic[.75]{(-2,-2),(0,-1.5),(2,-2.4),(1.8,2),(0.5,1.8),(-2.3,1.7)}}
\store{FU}{\shiftpath{(12,0)}\cyclic[.75]{(-1.5,-1.5),(0,-1.2),(2,-1.7),(1.8,2),(0,1.6),(-2,1)}}
\store{UU}{\shiftpath{(12,0)}\cyclic[.75]{(-2.8,-3),(0,-2),(3,-2.4),(2.8,2.8),(0.5,2.4),(-2.9,1.7)}}
\gfill[0.6white]\mfobj{U}
\gfill[0.8white]\mfobj{UU}
\gfill[0.6white]\mfobj{FU}
\draw\mfobj{U}
\draw\mfobj{UU}
\draw\mfobj{R}
\draw\mfobj{FU}
\arrow\curve[1]{(3,2),(6,3),(9,2)}
\point{(0,0),(12,0)}
\shiftpath{(12,0)}\mfobj{R}
\tlabel[tc](0,3.5){$E$}
\tlabel[tc](12,3.5){$E'$}
\tlabel[tl](-2,0){$U$}
\tlabel[tl](10.1,1){$f(U)$}
\tlabel[tl](9,-1){$U'$}
\tlabel[tl](0.1,0){ $x_0$ }
\tlabel[tl](12.1,0){ $f(x_0)$ }
\tlabel[tc](6.1,3.8){$f$}
\end{mfpic}
\end{center}

\noindent
\parbox[c]{7.51cm}
{The picture on the right shows the intersection of two
sets $A$ and $B$. Notice that this intersection consists of
all points which belong to both sets.}
\hfill
\begin{minipage}{40mm}
\begin{mfpic}[15]{-2.2}{5}{-2.2}{2.2}
\store{a}{\circle{(0,0),2}}
\store{b}{\circle{(2 *sqrt 2,0),2}}
\store{c}{\arc[p]{(0,0),-45,45,2}}
\store{de}{ \arc[p]{(2 *sqrt 2,0),135,225,2}}
\store{dd}{\lclosed\connect\mfobj{de}\mfobj{c}\endconnect}
\gfill[0.7white]\mfobj{dd}
\draw\mfobj{a}\draw\mfobj{b}
\tlabel(-1,-0.3){ $A$ }
\tlabel(3,-0.3){ $B$ }
\end{mfpic}
\end{minipage}

\bigskip
\begin{definition}[Complex logarithm\index{complex logarithm}]
The \tit{complex logarithm}, $\log: \Cc^* \ra S_l$, is defined by
\begin{equation}\notag
\log z=\log\abs z+i\arg_lz.
\end{equation}
It is the inverse of $\fv\exp{S_l}$, the so-called \tit{ main branch}
of the exponential function.
\end{definition}

The region of discontinuity
is now the axis
$\set{z\in\Cc^*}{\arg z=\pi}$. Thus, the exponential function
is not only bijective in the
open strip
$\inn S_l$,
but also a differentiable homeomorphism onto
$\Si=\set{z\in\Cc^*}{\arg z\neq \pi}$ with
$\pri\exp z=\exp z\neq 0$, and therefore, in view of the previous theorem, we may conclude

\begin{theorem}
The complex logarithm is infinitely often differentiable in $\Si$
and
$\pri\log z=\frac{1}{z}$.
\end{theorem}

\begin{mfpic}[15]{0}{20}{-2.5}{3}
\gfill[0.6white]\rect{(12,-2),(20,2)}
\gfill[0.6white]\circle{(4,0),2}
\arrow[l 5pt]\lines{(4,0),(8,0)}
\arrow[l 5pt]\lines{(4,-2.5),(4,3)}
\arrow[l 5pt]\lines{(12,0),(20,0)}
\gfill[white]\circle{(4,0),0.05}
\arrow\curve[1]{(7,2.5),(10,3.5),(13,2.5)}
\penwd{1pt}
\draw[white]\lines{(0,0),(4,0)}
\penwd{0.5pt}
\arrow[l 5pt]\lines{(16,-2.5),(16,3)}
\tlabel[cr](17.2,2.3){$\pi$}
\tlabel[cr](17.2,-2.3){$-\pi$}
\tlabel[cc](10,4){ log}
\tlabel[cc](2,2.5){ $\Si$}
\end{mfpic}%

\closegraphsfile
\end{document}
Advanced Help
ConTeXt and MetaPost