# metapost and pdflatex

I'm trying to use figures created with metapost in a TeX document compiled with pdflatex, but I have some troubles. I did as advised here, but it fails!

My code is this :

\documentclass[10pt]{article}
\usepackage{graphics}
\begin{document}
\includegraphics{figures/TryMetaPost.1}
\end{document}


With plain latex I have no problem but with pdflatex I obtained:

LaTeX Error: Unknown graphics extension: .1


I tried also with .mps and in this case I have (with pdflatex)

Cannot convert figures/TryMetaPost1.mps from MPS to PDF


Does anybody see my mistake?

-
possible duplicate of \includegraphics: Dots in filename –  diabonas Mar 18 '12 at 18:01

The first message simply means that pdfLaTeX doesn't know the extension. You can get around this problem either by changing the extension to .mps or by declaring a rule:

\DeclareGraphicsRule{.1}{mps}{*}{}


The second message is more problematic: It indicates that pdflatex has problems to convert the mps. Which means that either the mps itself is broken or something doesn't work in your system. Could you show the offending mps and the log-file?

-
I will search in this way. I think the problem comes from the fact that I have only version 0.993 of mpost. What do you think? –  PanAkry Mar 19 '12 at 8:31
I will certainly not start to guess around without some more reliable informations. And if you have an old mpost everything else is probably old too. So don't look only in one direction. –  Ulrike Fischer Mar 19 '12 at 8:35
The log file (metapost) LaTeX Error: Missing \begin{document}. l.12 / bd{bind def}bind def/fshow {exch findfont exch scalefont setfont show}bd ? ! Emergency stop. ... l.12 / bd{bind def}bind def/fshow {exch findfont exch scalefont setfont show}bd –  PanAkry Mar 19 '12 at 8:43
Don't send information snippets. Make a complete example, with a tex-file, the mp, the resulting mps and the complete log-file in a zip-file and put them somewhere for download. –  Ulrike Fischer Mar 19 '12 at 8:46

Adding \DeclareGraphicsRule{.1}{mps}{*}{} to a tex file works for pdflatex, which is OK with respect to the subject of this question. But it has the side-effect of breaking latex, because mps is not a pre-defined file extension for latex. To circumvent this, one should check for the actual TeX engine used, e.g.,

\usepackage{ifpdf}
\ifpdf
\DeclareGraphicsRule{*}{mps}{*}{}
\fi


The MetaPost manual suggests another method, though. Recent MetaPost versions have a file name template mechanism that can be used to change the format of MetaPost output file names. Adding the line

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


to the preamble of a MetaPost input file named figs.mp, makes output files have names figs-1.mps, figs-2.mps etc. Files ending mps can easily be included in LaTeX documents by giving the full name to \includegraphics like

\includegraphics{figs-1.mps}


This works with latex as well as pdflatex without messing with \DeclareGraphicsRule. See the MetaPost manual and Keith Reckdahl's Using Imported Graphics in LaTeX and pdfLaTeX for why that works.

-