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. Note that TeXShop has a ConTeXt engine.
MetaPost is a MetaFont like system by John Hobby, which can be used to draw elaborate illustrations. See http://tug.org/metapost.html for more details. The MetaPost manual is part of TeX Live; to get it, select "Show Help forPackage:" at the bottom of the TeXShop Help Menu and ask for "MetaPost". Interesting metapost examples can be found at many web sites; for instance see http://www.cs.ucc.ie/~dongen/mpost/mpost.html. TeXShop has three separate MetaPost engines, MetaPost, nv-metafun, and nv-metapost. The first of these is a minimal script which directly calls MetaPost. The second two are elaborate scripts by Nicola Vitacolonna which greatly ease the process of working with MetaPost in TeXShop. A detailed README by Vitacolonna in ~/Library/TeXShop/Engines/Inactive/MetaPost describes the two "nv-" scripts.
Here is a sample MetaPost file:
- % !TEX TS-program = nv-metafun
- 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
Once MetaPost files have been created, then can be displayed like any other illustration.
To try the previous example, create a new TeXShop window. Cut the above example from help and paste it into the window. Save the source file, but when the Save Dialog appears, use the bottom popup menu to select the File Format "mp File". Then typeset as usual.
MetaPost is an extension of Donald Knuth's MetaFont program, used to create TeX fonts. The nv-metapost engine can be used to work directly with metafont sources, although the engine calls MetaPost rather than MetaFont. There are some incompatibilities between these programs, but often MetaFont source files compile without problems. If you'd like to try an example, find the metafont source section of the TeX Live TeX Distribution. For example, if you use TeX Live 2009 or MacTeX-2009, use Terminal and "cd /usr/local/texlive/2009/texmf-dist/fonts/source/public". Then type "open ." to open this directory in the Finder. Select one of the many folders, for instance "concrete" and drag it to the desktop to create a copy there. Open one of the mf files in this copy in TeXShop, say ccr10.mf. Select the nv-metapost engine and typeset. After a fair amount of work, you will see exactly how each character of the concrete font is constructed.
It is also possible to embed MetaPost source code directly in a Latex document using the package mfpic.
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 (with the "MetaPost" engine rather than "nv-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}