Tex sample embedded metapost
An Example of an Embedded MetaPost Diagram in Plain TeX and AmSTeX
It is now possible to incorporate MetaPost figures in TeX and AmSTeX documents directly; i.e., without having separate MetaPost input and output files. Here is a sample file that incorporates such a figure.
\input luamplib.sty Meta% \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; \endmplibcode Post! \bye
If this was stored in a file named file.tex, then one would produce file.pdf by running the command
luatex file
This is a very convenient way to include MetaPost figures in TeX and AmSTeX documents.
Notes
- This method only works for producing pdf files. It does not work in dvi mode.
- Note that the command to use is luatex. One cannot use pdftex or xetex, since those engines do not support embedding of MetaPost figures.
- For AmSTeX, add a line \input amstex after the initial line \input luamplib.sty. It will not work to add this line at the beginning of the file, because AmSTeX handles the "@" character differently.
- The commands \mplibcode and \endmplibcode must occur on lines of their own. This is because the \mplibcode macro 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