• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download

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
cutlabel:=thelabel top(btex . . .etex, (3cm,0));
% TEX label:\u201d$g\u02d91(x)=0$\u201d
un\ufb01ll bboxcutlabel; drawcutlabel;
cutlabel:=thelabel lrt(btex . . .etex, (2cm,4cm));
% TEX label:\u201d$g\u02d92(x)=0$\u201d
un\ufb01ll bboxcutlabel; drawcutlabel;
cutlabel:=thelabel (btex . . .etex, (\u22123cm,2cm));
% TEX label:\u201d$P$\u201d
un\ufb01ll bboxcutlabel; drawcutlabel;
% Draw the two gradients with a somewhat thicker line.
pickup pencirclescaled 1.2pt ;
drawarrowzast-- (zast+ (0, 1cm));
drawarrowzast-- (zast\u2212(0, 1cm));
end\ufb01g; % The \ufb01rst graphic is \ufb01nished.
The \ufb01nal output can be included into your TEX document in the usual fashion. If you want to create standard
output you can use\epsfbox{nlpgraph.1}. For PDF output use\convertMPtoPDF{nlpgraph.1}{1}{1}.
LaTEX users should be familiar with what they have to do. Note that youmust rename the \ufb01les written by
MetaPost to something likenlpgraph1.mps forpdftex.def\u2019s sake.
x\u2217
x1
x2
\ue000g1(x\u2217)
\ue000g2(x\u2217)
g1(x)=0
g2(x)=0
P

OK, just as I wrote in my announcement in thepdftex list, the code for these graphics is rather quick and dirty. Without comments even I don\u2019t quite understand what the following does. However, I just don\u2019t have the time to \ufb01ll the gaps now. Also the code could be improved by using more parameters and letting MetaPost do the calculations.

On the other hand, the main idea should be clear: de\ufb01ne some \ufb01xed points and their relative positions, draw lines and \ufb01ll areas, \ufb01nally put in labels and special markers. And remember not to overwrite earlier stu\ufb00 that should be visible.

2
begin\ufb01g(2);
pairrightrange, leftrange, toprange, bottomrange;
rightrange= (8cm,0); leftrange= origin;
toprange= (0, 5cm); bottomrange= (0,\u22121cm);
labelbot(btex... etex,rightrange);
% TEX label:\u201d$x\u02d91$\u201d
labellft(btex... etex,toprange);
% TEX label:\u201d$x\u02d92$\u201d
pairxast; xast= (4cm,2cm);
labelllft(btex... etex,xast);
% TEX label:\u201d$x\u02c6% \u201cast$\u201d
pathT; T= (1cm ,5cm ) - - (7cm ,\u22121cm );
labelllft(btex... etex, point0 ofT);
% TEX label:\u201d$T$\u201d
label(btex... etex,(1cm ,2cm ));
% TEX label:\u201d$P$\u201d
pathgi; g i=.75toprange. .{(1,\u22121)}xast...6rightrange;
labelbot(btex... etex, .6rightrange );
% TEX label:\u201d$g\u02d9i(x)=0$\u201d
pathL; L= (2cm ,5cm ){(1,\u22121)}.. {right}(8cm ,2cm );
pairSP, SPT, TSPT;
SP=L intersectionpoint ((xpart(xast),\u2212in\ufb01nity)
- - (xpart(xast),in\ufb01nity));
SPT=point.666667ofL;
labelurt(btex... etex,SP);
% TEX label:\u201d$L(x\u02c6% \u201cast,u\u02c6\u201cast)$\u201d
labelurt(btex... etex,SPT);
% TEX label:\u201d$L(x,u\u02c6\u201cast)$\u201d
TSPT=T intersectionpoint (SPT- - (xpart(SPT),\u2212in\ufb01nity));
pathKonvex;
Konvex= buildcycle(L, SPT-- TSPT- -point 0ofT - -point 0ofL);
\ufb01llKonvex withcolor.8white ;
fori= T,gi, L:draw i;endfor;
drawxast-- SP; drawSPT-- TSPT;
drawarrowleftrange-- rightrange;
drawarrowbottomrange-- toprange;
end\ufb01g; % 2
x1
x2
x\u2217
TP
gi(x)=0
L(x\u2217, u\u2217)
L(x, u\u2217)
3
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...