6

I seem to be having problems with certain EPS files, generated by Matlab. Using epstopdf, it generates an empty pdf file (which it then inserts into the document, leaving a void there).

It seems like my issue may be similar to this one, but it seems that that was never resolved. It also appears to be similar to this one as well, but again, it does not appear resolved.

I am using MiKTeX 2.9, on Windows 8.1, and the following MWE sort of works:

\documentclass{article}

\usepackage{graphicx}
\usepackage{epstopdf}

\begin{document}

% test.eps can be found at: http://1drv.ms/1EOjokZ
\includegraphics{test.eps}

% prob1_pdfa.eps can be found at: http://1drv.ms/11gMHjb
\includegraphics{prob1_pdfa.eps}

\end{document}

By that I mean that the first EPS displays properly, but the second does not. There are no errors in the console output (other than the 'Overfull \hbox' error I always seem to get).

This same MWE works on ShareLatex, which is what I used in the interim.

The EPS file which does not work was generated in Matlab r2014b using something like:

f=figure;
hist(rand(1,1e4),25)
print(f,'-depsc','sample.eps')
8
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. You probably don't need to include epstopdf and may be better off leaving graphicx to work things out, if so. Can you convert the files outside TeX? Or does that fail as well?
    – cfr
    Nov 16, 2014 at 23:29
  • I include the epstopdf package because I'm using pdfLaTeX, and PDFs don't natively support EPSs. I also believe it to be a problem with epstopdf. Also, I don't know how to convert the files outside of using the epstopdf package, although I can open up the file in an EPS viewer, and it does contain the right graphic. Nov 16, 2014 at 23:45
  • 1
    It might be a problem with MiKTeX's GhostScript. The latest version of GhostScript is 9.15, while MiKTeX's is 9.05. You might try converting with epspdf-extra, which is the windows version of epspdf and can be found here.
    – Bernard
    Nov 16, 2014 at 23:45
  • 2
    Recent versions of graphicx handle EPS files correctly regardless. With a recent installation, you don't need to load epstopdf.
    – cfr
    Nov 17, 2014 at 1:16
  • 1
    @cfr If someone wants to be independence from a graphics.cfg, then epstopdf can also be loaded explicitly, even with options(, which are just passed to \epstopdfsetup). That's the reason, why I have divided the package into a user package epstopdf and an more internal package epstopdf-base without options. This avoids LaTeX's option clash errors. Nov 17, 2014 at 18:40

5 Answers 5

2

GUI

As Bernard pointed out, the epspdf-extra bundle is one possible choice. All you need to do is download epspdf-extra.zip and use the Windows installer provided to install epspdf with a buit-in Tcl/Tk runtime, which can be used as a GUI application (illustrated on page 3 of the user manual to the epspdf package).

command line

Alternatively you can download epspdf.0.6.0.zip from tex.aanhet.net/epspdf, and follow these instructions:

  • Extract all files into a folder <path to>\epspdf (e.g. C:\Program Files\epspdf).
  • In <path to>\epspdf create an empty text file with the name epspdf.bat. Then copy the following lines into the batchfile and adjust the script path to your settings:

    @echo off
    set ScriptPath=<path to>\epspdf
    texlua %ScriptPath%\epspdf.tlu %*
    

    where <path to> could be, for example, C:\Programs or "C:\Program Files" (the quotes " " are included).

  • Add <path>\epspdf to the system variable Path (Start Menu > right-click on Computer > Properties > Advanced System Settings > Environment Variables under the Advanced tab > look for the system variable Path and edit its value).

This approach allows you to use epspdf from the command line in combination with the \write18 feature (add --enable-write18, or the alias --shell-escape, to the list of arguments passed to the pdflatex compiler). With regard to the problematic EPS file, here's a MWE:

\documentclass{article}
\usepackage{graphicx}

\begin{document}
\immediate\write18{epspdf prob1_pdfa.eps}
\includegraphics[keepaspectratio=true,width=0.9\textwidth]{prob1_pdfa.pdf}
\end{document}

enter image description here


A somewhat more creative approach based on LaTeX code found on page 3 of this document is to define a command \includeeps with a mandatory argument that accepts the name of the EPS file (without the .eps extension) you wish to include in your document, and an optional argument that can pass options to the \includegraphics command:

\newcommand{\executeiffilenewer}[3]{%
\ifnum\pdfstrcmp%
{\pdffilemoddate{#1}}%
{\pdffilemoddate{#2}}%
>0%
{\immediate\write18{#3}}%
\fi%
}
\newcommand{\includeeps}[2][]{%
\IfFileExists{./#2.pdf}%
{\executeiffilenewer{#2.eps}{#2.pdf}{epspdf #2.eps}}%
{\immediate\write18{epspdf #2.eps}}%
\includegraphics[#1]{#2.pdf}
}

When a file is included via \inclueeps, the epspdf program is only called when no .pdf file exists, or the EPS file has been updated.

Examples of usage with file abc.eps as input:

\includeeps[width=6cm]{abc}
\includeeps{figures/abc}
\includeeps{../section/abc}
\includeeps[keepaspectratio=false,height=9cm]{../section/abc}
2
  • My definition of \includeeps leaves no room for passing options to the epspdf program. But such a requirement can be accommodated by redefining the \includeeps command to include a third argument.
    – nnunes
    Nov 18, 2014 at 3:14
  • I think the problem ultimately boils down to a big flaw in MiKTeX 2.9, with their implementation of GhostScript. While I don't really like defining a new command like you've done here (because then I have to copy/paste it into every document, or lose portability by putting it in a package), my ultimate goal was to be able to compile LaTeX documents on my own system, and you gave me two easy-to-follow methods here. Thanks! Nov 21, 2014 at 16:30
0

A quick but dirty work-around: 1. Convert the stubborn .eps outside of the editing enviornrmetn you are working in to PDF (you can use Inkscape for the conversion). 2. Save the PDF at the desired location. 3. Compile again, but this time epstopdf will skip the conversion since there is already a PDF version of the EPS. 4. Rendering should be fine now.

1
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. In that case, you can make pdflatex use the PDF file directly by prioritizing .pdf over .eps (which is the default anyways) -- can't you?
    – yo'
    Apr 17, 2015 at 17:11
0

I was facing a similar problem (foo.eps file converts to pdf correctly but goo.eps converts to a blank pdf). I also searched google a lot and came up on the unresolved questions the OP has mentioned. Please note that my foo.eps and goo.eps were not generated by the same software. I used pdflatex. Here is how I solved it on linux using Gwenview:

  • Initial code:

    \documentclass{beamer}
    \usepackage{graphicx}
    \usepackage{epstopdf}
    
    \begin{document}
    \begin{frame}{}
    
    \includegraphics{goo.eps}
    
    \end{frame}
    \end{document}
    

    This was not working. The eps converted to pdf file was blank.

  • I then opened goo.eps using gwenview, which was default on my linux system. I saved file as goo.jpg. Then I modified my code like so:

    \documentclass{beamer}
    \usepackage{graphicx}
    \usepackage{epstopdf}
    
    \begin{document}
    \begin{frame}{}
    
    \includegraphics{goo.jpg}
    
    \end{frame}
    \end{document}
    

    This seemed to work. But I want to work only with eps figures!

  • So I opened goo.jpg with gwenview again and saved the file as goo.eps, overwriting the original file. I changed the code back to the initial code. This time the goo.eps file was correctly converted to a pdf file and appeared in the final pdf as well!

I don't know why or how this worked for me, but it did. As I said the foo.eps and goo.eps files were generated by different software. Perhaps some software might not export figures as eps correctly.

1
  • 1
    The problem with this method is that you're converting a vector or mixed-vector graphics to a purely raster graphics object, and then back to a 'vector' graphics format; although all of the original vector information will be lost. The whole reason to use EPS in the first place is to avoid using raster graphics, to avoid any resolution problems. Aug 13, 2015 at 1:20
0

I had the same problem creating eps files from MATLAB for tex. I ran epstopdf on the eps file from the command line and found that it throws an error while creating blank pdfs. Using code from an answer here: epstopdf error: /undefined in uageLevel:

You can create a MATLAB function to fix all of your eps files to work with miktex running epstopdf:

function FixEpsFiles()
fileList = dir('*.eps');
for k=1:length(fileList)
    eps = fileread(fileList(k).name);
    fd = fopen(fileList(k).name, 'wt');
    fwrite(fd, eps);
    fclose(fd);
end
0
0

Simple solution If you are using Texworks to compile the LaTeX file, just change the Typeset to XeLaTeX + MakeIndex + BiBTeX. It worked with me even without using the package \usepackage{epstopdf}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .