Ryan's Blog

Metapost Graphs

Posted in latex by ryanlayer on October 24, 2009

Data file: data.d

1 4
2 2
3 1
4 2
5 4

Metapost file:

draw begingraph(3in,2in);
gdraw “data.d”;
glabel.bot(btex $x$-axis etex, OUT);
glabel.lft(btex $y$-axis etex, OUT);
glabel.top(btex The graph of $y=f(x)$. etex, OUT);
glabel.rt(btex $y={1\over{4-x^2}}$ etex, 2,3);

Tagged with: , ,

Practical Latex and Metapost Tips

Posted in latex by ryanlayer on October 24, 2009

Found what looks like a great collection of practical Latex and Metapost tips.


Tagged with: ,

Latex in Metapost

Posted in latex by ryanlayer on October 23, 2009

You can even embed TeX inside your pictures for labels and the like.  First lets start with a plain label

label.pos(“label text”, <coordinates>;

where <coordinates> can be just a point like (0,0) or the midpoint of a line 1/2[A,B], where A and B are two points, or some other expression. ‘pos’ is a relative position indicator for the label which can be top, bot, lft, rt, or on the corners: ulf, urt, llf, lrt. We can add TeX to a label by putting TeX commands between the commands btex and etex:

label.bot(btex $ TeX commands $ etex,(0,0));

Note that this will only work for TeX commands, not LaTeX specific ones like \frac! If you need to use LaTeX commands you need to put the following at the top of the .mp file


Note that the ‘%&latex’ line is not a comment, though it starts with % – it is a command to use LaTeX, and that no \end{document} is necessary. Furthermore, the TeX will be typset in text style by default, so you’ll need to add a \displaystyle inside the $’s so that your \frac’s aren’t squashed. Note furthermore that if your metapost contains TeX then a standard postscript viewer will not be able to read it. This is no real limitation since you’ll probably want these in a TeX document anyway. To view them, you’ll have to wrap it in a TeX documents and view the DVI output, or convert that to ps (or you can use the script linked at the bottom of the page). Another option is to add the line ‘prologues := 1’ at the beginning of the mpost file, which will try to substitue postscript fonts for the TeX. This can be good for previewing, but the results are never satisfying. Finally there is the dotlabel command, which works exactly as label, except it places a dot at the indicated point.

SOURCE: http://www.physics.drexel.edu/liki/index.php/Metapost

Tagged with: