Ryan's Blog

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

verbatimtex
%&latex
\documentclass{article}
\begin{document}
etex

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

Advertisements
Tagged with:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: