Let me start with a few notes about how this document with the pretty-printed MetaPost source code was
created. Since John Hobby\u2019s MetaPost is almost (but not quite) similar to Don Knuth\u2019sMETAFONT, it\u2019s
easy to use theMFT utility which convertsMETAFONT source to TEX source.
Prior to this conversion it is necessary to apply a few modi\ufb01cations. This is best done by Ulrik Vieths\u2019s
SEDscript mp2mft.sedfrom CTAN:graphics/metapost/contrib/misc/. MFTshould be invoked with the -s
mp2option, also supplied by Ulrik\u2019s bundle. The resulting \ufb01le can be processed by either plain TEX or (as
for this application) by PDFTEX.
In the \ufb01rst case it is necessary to include Tom Rokicki\u2019sepsf.tex macros, in the latter you\u2019ll need Hans
Hagen\u2019ssupp-pdf.tex and the usual\pdfoutput=1 and\pdfcompresslevel=9.
Including MetaPost graphics in LaTEX documents is straightforward with thegraphicx bundle and the
latestpdftex.def by David Carlisle, Sebastian Rahtz, and Hans Hagen.
begin\ufb01g(1); % Start the \ufb01rst graphic.
% Declare a bunch of variables; points. . .
pairzast, leftrange, rightrange, bottomrange, toprange;
pairtopleft, topright, bottomleft, bottomright;
pathrestrictiontwo, inrange; % paths. . .
picturecutlabel; % and an image.
% Set the coordinates;origin equals (0, 0).
zast= origin; leftrange= (\u2212 4cm,0); rightrange= (4cm,0);
bottomrange= (0,\u22121cm); toprange= (0, 4cm);
topleft= (\u2212 4cm,4cm); bottomleft= (\u2212 4cm,0);
topright= (4cm,4cm); bottomright= (4cm,0);
% MetaPost does not (yet) provide the possibility for plotting functions,
% so we have to use intermediate points for the parabola.
restrictiontwo= (\u2212 2cm,4cm)
fori=\u22128 upto8: . . (i/4, (i/4)\u2217 (i/4))\u2217 1cm endfor;
% buildcycle creates a closed path from several (sub)paths.
inrange= buildcycle(bottomleft-- topleft-- (\u22122cm,4cm),
restriction two,(2cm,4cm) -- topright-- bottomright-- bottomleft);
% Note that PostScript works in an \u201cadditive\u201d way, so we have to start
% with the background. Instead of \u2018white\u2019 you can use brilliant
% TEXnicolor.
\ufb01llinrange withcolor.8white ;
% Introduce thex andy axis.
drawarrowleftrange-- rightrange;
drawarrowbottomrange-- toprange;
drawrestrictiontwo; % Draw the parabola.
% Mark various points of interest. This is done by TEX itself.
labellrt(btex... etex,zast);
% TEX label:\u201d$x\u02c6% \u201cast$\u201d
labelbot(btex... etex,rightrange);
% TEX label:\u201d$x\u02d91$\u201d
labellft(btex... etex,toprange);
% TEX label:\u201d$x\u02d92$\u201d
cutlabel:=thelabel rt(
btex... etex,zast+ (0,1cm ));
% TEX label:\u201d$\u201cnabla g\u02d91(x\u02c6\u201cast)$\u201d
un\ufb01ll bboxcutlabel; drawcutlabel;
labellft(btex... etex,zast\u2212(0,1cm ));
% TEX label:\u201d$\u201cnabla g\u02d92(x\u02c6\u201cast)$\u201d
1
Leave a Comment