TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

To include MetaPost pictures in a latex file compiled by pdflatex I usually do something like


but this requires all metapost output to have extension .mps (which is usually fine — one can just add the line filenametemplate "%j-%c.mps"; into .mp source). Is there a way to include mps pictures with their usual filenames (smth.1, smth.2, etc.)?

Update: I usually need it to recompile some old files with PDFLaTeX — so I need some recipe that adds couple of lines in the preamble but not requires to changes everything.

I tried to invent some hack (for Windows, to be compiled with pdflatex -enable-write18):

\DeclareGraphicsRule{.1}{pdf}{.1.pdf}{`copy #1 #1.eps && epstopdf #1.eps}

which indeed generates smth.1.pdf but fails with the error

! Package pdftex.def Error: File `smth-1-converted-to.1.pdf' not found.

Update 2: The question was answered but maybe someone knows how to make this hack work?

share|improve this question
@vanden it's not a question about metapost — are you sure it needs metapost tag? – Grigory M Aug 11 '10 at 20:38
I don't do much graphics. I took the presence of "metapost" in the title and the details about metapost extensions to indicate metapost content. But, as you as asker think not, I've reverted. – vanden Aug 11 '10 at 20:59
up vote 8 down vote accepted

Just do:

% etc. 
share|improve this answer
Now I'm feeling infinitely stupid – Grigory M Aug 11 '10 at 21:49
Even "\DeclareGraphicsRule{}{mps}{}{}", maybe. But AFAIR it didn't work in some situation... – Grigory M Aug 11 '10 at 22:32

Do you know that there's a package for encapsulating metapost figures in LaTeX? It's called emp.

share|improve this answer
Didn't know about it, thanks (but it certainly doesn't resolve my problem). – Grigory M Aug 11 '10 at 20:33
Just trying add helpful information. :) – Stefan Kottwitz Aug 11 '10 at 20:47
Does emp have any support for Luatex/mplib? – Charles Stewart Aug 11 '10 at 21:04
LuaTeX is based on PDFTeX and has mplib baked in so there should be no need for encapsulation of MetaPost graphics. – Sharpie Aug 11 '10 at 22:12
@Charles, @Sharpie: in luatex, emp is superceded by the 'luamplib' package, which defines an environment and makes sure the library results are correctly included in the output. – Taco Hoekwater Aug 15 '10 at 15:44

Almost five years after the question.

With the latest versions of Metapost it is possible to change the default naming scheme for output files: the statement

outputtemplate := "%j-%c.mps";

will produce, from file name.mp. files named as name-1.mps and so on. This is much preferable, because no further instruction is needed under pdflatex, which knows how to process MPS files.

Under LuaLaTeX, the luamplib package allows for direct embedding of Metapost code in the document.

The same is possible under all engines with the packages gmp or mpgraphics. The package emp also allows something similar, but with several limitations.

share|improve this answer
It should be said, however, that the embedding of MetaPost code by mpgraphics and gmp is necessarily less direct than the one allowed by luamplib with LuaLaTeX: you have to activate the shell-escape option with gmp as with mpgraphics if you want your pictures processed in one run. This is not the case with luamplib. This one having still the obvious disadvantage of being compatible with Lua(La)TeX only :-) – Franck Pastor Apr 23 '15 at 6:03
@fpast Everything you said is correct. – egreg Apr 23 '15 at 8:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.