# An Example of an Embedded MetaPost Diagram in LaTeX

It is now possible to incorporate MetaPost figures in LaTeX documents directly; i.e., without having separate MetaPost input and output files. Here is a sample file that incorporates such a figure.

\documentclass{minimal}
\usepackage{luamplib}

\begin{document}
Meta%
\begin{mplibcode}
beginfig(1);
numeric u; u=10pt;
pickup pencircle scaled .4pt;
draw fullcircle scaled 1u;
draw (-.3u,-.1u)..(0,-.3u)..(.3u,-.1u);
pickup pencircle scaled .8pt;
draw (0,0);
draw (-.2u,.2u); draw (.2u,.2u);
endfig;
\end{mplibcode}
Post!

\end{document}


If this was stored in a file named file.tex, then one would produce file.pdf by running the command

lualatex file


This is a very convenient way to include MetaPost figures in LaTeX files.

## Notes

• This method only works for producing pdf files. It does not work in dvi mode.
• Note that the command to use is lualatex. One cannot use pdflatex or xelatex, since those engines do not support embedding of MetaPost figures.
• The commands \begin{mplibcode} and \end{mplibcode} must occur on lines of their own. This is because the mplibcode environment changes handling of certain characters.
• This method does not currently support btex...etex.
• The MetaPost code should not contain blank lines (these will be converted by TeX to \par).
• If you want to have a space before the figure, delete the % sign just after "Meta". If you want a space after the figure, add "\ " just before "Post" (not at the end of the previous line—see the note just above this one).

## Do Try This at Home

If you try this on a machine not on the Math Department network, you will likely find that there is extra space between the characters "Meta" and the figure. This is because of bugs in the file luamplib.sty. The version of this file on the Math department network has been modified to fix this bug. To fix it for your home machine, copy the file from the math department to your home machine. On the math department, the file luamplib.sty is available in one of the following locations (depending on which computer is being used):

/local/depot/4/texlive-2010/tex/luatex/luamplib/luamplib.sty
/local/depot/texlive-2010/tex/luatex/luamplib/luamplib.sty


You should copy this file to the corresponding place on your home machine. This location can be found by running the command

kpsewhich luamplib.sty