3

When I use the EPS images made by Metapost in XeLaTeX. The image is not in the right place.

Here is my code:

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}   
\usepackage{epsfig}

\begin{document}

    \begin{tabular}{|c|}\hline 
        \psfig{figure=pix-1.eps} \\ \hline
    \end{tabular}

\end{document}

And the output is:

Output

If I use other EPS images not made by Metapost, I have no problem. How can I fix the issue?

The xelatex and metapost compiler is MikTex 2.9.6210 64-bit.

EDIT: the source code of image:

prologues:=3;
filenametemplate "%j-%c.eps"; 

verbatimtex
%&latex
\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
etex

input TEX

TEXPRE("%&latex" & char(10) & "\documentclass{article}\begin{document}");
TEXPOST("\end{document}");

beginfig(1)
    u := 1cm;
    lx := 1u;   
    sx := -1.2;
    ex := 1.2;
    rx := (ex - sx)/40;

    drawarrow (-1.5u,0) -- (1.2u,0);
    drawarrow (0,-3u) -- (0,3u);
    drawoptions(withpen pensquare scaled 1.2);
    for i = .5 step 0.5 until 2:
        draw (sx,i*sx*sx)*lx for j = 1 upto 40:
                .. (sx + j*rx,i*((sx + j*rx)**2))*lx
            endfor;
        label.rt("a=" & decimal(i),(ex,i*ex*ex)*lx);
    endfor;
    drawoptions();
endfig;
4
  • 1
    that's a bit odd but why are you using epsfig and \epsfig not the standard graphics inclusion. (I doubt it makes any difference as \epsfig just expands to \includegraphics but it looks a bit odd to be using that emulation unless the document was written in the 1980's) – David Carlisle Feb 27 '17 at 13:49
  • Use \includegraphics has the same result. – Prester Feb 27 '17 at 14:07
  • Yes that's expected (although using that simplifies debugging, one less layer to go through) I would guess the eps has the wrong bounding box what happens if you try your test with latex+dvips? can you make the eps (or metapost source) available somewhere? – David Carlisle Feb 27 '17 at 14:16
  • The source code is posted above. And the eps file link is here. Thanks for the help. – Prester Feb 27 '17 at 14:26
5

XeLaTeX (actually xdvipdfmx) has some problems with EPS inclusion.

The fix is very simple: change

filenametemplate "%j-%c.eps"; 

into

filenametemplate "%j-%c.mps"; 

and your document can be

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}

\begin{document}

\begin{tabular}{|c|}\hline
\includegraphics{figure-pix-1.mps} \\ \hline
\end{tabular}

\end{document}

enter image description here

With the .mps extension the graphic file is read in with a different driver, which directly translates the Metapost produced Postscript code into PDF code.

0
4

This is partially documented in xetex.def comments but the default behaviour seems wrong, however the current situation is that you need to rename the file to .mps extension or use the --vorigin option to xdvipdfmx.

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}   


\begin{document}

    \begin{tabular}{|c|}\hline 
        \includegraphics{pix-1.eps} \\ \hline
    \end{tabular}

\end{document}

with a command line of

xelatex -output-driver='xdvipdfmx --mvorigin ' file

produces

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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