# How to use \graphicspath + epstopdf

Background: I am using MiKTeK and TeXnicCenter. Since I am using Windows, I have to deal with folders whose names have spaces, such as C:/Documents and Settings/... and I use \usepackage[space]{grffile} to deal with this problem.

Problem: I saved a bunch of .eps figures in a folder and I use the \graphicspath to specify that folder in my LaTeX document. I tried to things to get a PDF with pictures:

1) If I use the package epstopdf then it doesn't know that it must save the PDF version of the figure in that folder, and it just complains that it cannot find the figure. It ends up producing a PDF file without pictures.

2) If I use LaTeX => PS => PDF compilation, then it complains it cannot find the figure, but shows it anyway (!?). The problem is that it displays the picture in a chaotic manner. puts all the pictures I try to load in the first page. (This is a document with several pages, and pictures).

Attempted solutions:

1) If I write a short LaTeX file in my pictures' folder with the epstopdf package, then it saves a PDF version of my pictures in that folder. Later, when I try to compile the document I am trying to produce, it works just fine. But that is a hassle...

This is added by xport. In my previous answer (that I have deleted), JJ O said as follows:

-

If you want a graphic (or any other file) available to several LaTeX documents, the normal way is to put it in a local tree rather than referred to by path. Thus for example I keep my shared graphics (logos, etc.) in %USERPROFILE%\texmf\tex\latex\local. The location of %USERPROFILE% varies a bit, but as you seem to be using Windows XP it will be C:\Document and Settings\<username>. You can do the same inside My Documents, but do need to have the tex\latex\... structure.

Create the appropriate structure, then using the MiKTeX Package Manager add the root (in my example, %USERPROFILE%\texmf) as a local package folder. MiKTeX should now be able to find your graphics files without needing \graphicspath.

The alternative is to do the conversion yourself, then use a relative inclusion path. For example, if you have a structure

C:\Documents and Settings\myuser\My Documents\Project\LaTeX\main.tex
C:\Documents and Settings\myuser\My Documents\Project\OtherStuff\graphic.eps


then you can use the Command Line version of epstopdf to do the conversion, giving you a file

C:\Documents and Settings\myuser\My Documents\Project\OtherStuff\graphic.pdf


This would then be included in main.tex using \graphicspath{{../OtherStuff/}}. (Automatic conversion cannot happen for a file which needs a ../ or absolute path as this is a security issue.)

-
Thanks a lot. if I got it right, your alternative solution is what I stated in the "Attempted Solutions" part of the original question? If not, I am missing something that could help me a lot. In your first suggestion, can I put subfolders inside this mother folder texmf\tex\latex\local? –  JJ O Jul 19 '11 at 17:13
OK, just manage to pull it off using relative paths. It is then not a security problem. More precisely, it on the answer given below. –  JJ O Jul 19 '11 at 20:24

1) If I use the package epstopdf then it doesn't know that it must save the PDF version of the figure in that folder, and it just complains that it cannot find the figure. It ends up producing a PDF file without pictures.

Have you tried the command \epstopdfsetup{outdir=./} (to be executed after the epstopdf package is loaded)? This should write the PDF files in the same directory as your main file.

-
I tried this after reading your answer. But it did not work. If I understood it correctly, I should keep: (a) \graphicspath pointing to the folder containing the pictures (b) \epstopdfsetup{outdir=./}. This should save the pictures in the folder where I have my latex document. Doing exactly this, it didn´t work (notice that, when using the \includegraphics command I just put the file name, expecting that it knows the directory containing the images - perhaps this is what I am getting wrong?) –  JJ O Jul 19 '11 at 17:05
Thanks a lot Mico for your suggestion. Without your help I wouldn´t learn about outdir=./. I am now using it quite a lot in different circunstances and helps wonders! –  JJ O Jul 20 '11 at 16:30

Run your document with xelatex then you do not need the package epstopdf. xelatex does the conversion on the fly.

-
But it will do this conversion at every run, thus slowing the compilation time. –  Martin Schröder Jul 17 '11 at 11:29
Thank you, Herbert. I will try to learn about xelatex now. –  JJ O Jul 19 '11 at 17:14
Would you know if it is possible to write a code in my document (a macro?) that tells the program to save a copy of a file in a new folder? –  JJ O Jul 19 '11 at 17:26
that can be done with using package auto-pst-pdf, it saves all eps images in a container file <file>-pics.pdf one image per page –  Herbert Jul 19 '11 at 17:48
what about a general file? I can ask it to make a copy of a eps file into a new folder? –  JJ O Jul 19 '11 at 17:49

Please do the following steps. It has been tested and works perfectly.

1. Setup your directory structures as follows.

• Images and Project directories are in xport directory.

• All EPS images are in Images directory.

• The main input file, named main.tex is in Project directory.

2. Write the main input file, named main.tex as follows.

% main.tex
\documentclass{article}

\usepackage{graphicx}
\graphicspath{{../Images/}}

\begin{document}
This is a figure \includegraphics{figure}
\end{document}

3. Create a batch file using Notepad, as follows.

rem automatic.bat takes input file name without extension.
echo off
latex %1
dvips %1
ps2pdf %1.ps


You are recommended to save this batch file in Project folder for simplicity, named it as automatic.bat. Note: don't forget to choose Save as type: All Files.

4. On the command prompt, change to Project directory and typeautomatic main without .tex extension, and hit enter as follows.

5. Done! You get the main.pdf as follows.

Update in response to JJO's own answer:

1. When you choose latex=>ps=>pdf output profile, TeXniCCenter internally invokes commands that I specify in my automatic.bat. This workflow is designed for compiling an input file (file with .tex extension) that imports EPS.
2. When you choose latex=>pdf output profile, TeXniCCenter internally invokes a command as in

rem xport.bat
echo off
pdflatex %1


This workflow is designed for compiling an input file (file with .tex extension) that imports PDF, PNG, JPEG.

3. latex=>pdf output profile can be used to compile input file that imports EPS whenever you load epstopdf package. But the compilation becomes slower because each of your existing EPS will be converted to PDF first. Therefore, I suggest you don't use latex=>pdf output profile. It is not efficient!!!!

-

Here is what worked for me in the end:

1. Make sure that the folders between your main LaTeX file and the eps figures do not have space in their names
2. when using the \includegraphics command, use relative a directory specification. For example, in my case I use

\begin{figure}[h! ht]

\includegraphics[width=0.3 \textwidth{../../ProjectName/Output/Images/surv.eps}

\end{figure}


In particular, I went back two folders and then opened the folder /ProjectName/Output/Images/.

3. If you do not like the idea of having to write ../../ProjectName/Output/Images/ all the time, write a newcommand

\newcommand{\directions}{../../ProjectName/Output/Images/}


and then when using \includegraphics, use

\includegraphics[width=0.3 \textwidth]{\directions surv.eps}


(does this defeat the purpose of using \graphicspath?)

This approach works with the restriction that the folders name between the main LaTeX file and the figure file do not have space in between. (So, in a nutshell, I believe that something went wrong along the way that \usepackage[space]{grffile} was not able to fix, for I tried several combinations using \graphicspath and \epstopdfsetup, both using latex => ps => pdf and \usepackage{epstopdf} but none seemed to work. Besides when you use epstopdf in the following manner: save a copy of your document first in the Images folder, compile it, and then compile your main LaTeX file again in the original folder.)

Overall, from this exercise in LaTeX, it seems to me that the latex => ps => pdf compiles much faster than the \usepackage{epstopdf} approach.

-
So what is the difference between yours and mine? –  xport Jul 19 '11 at 21:11
Please see the time stamp of my answer, it was july 15 but I deleted because there was no response. :-) –  xport Jul 19 '11 at 21:16
(you mean the answer right below this one?) I guess I did not understood the part of the batch file. –  JJ O Jul 19 '11 at 21:42
Open a file using Notepad, type the given code as if, save as automatic.bat (don't forget to choose Save as type: all files rather than Save as type: text document (txt)). –  xport Jul 19 '11 at 21:44
pdflatex will not work if your input file imports EPS so latex->dvips->ps2pdf or xelatex is used to compile. There is no improvement using batch file. I provided this batch file because I want to minimize the surface of investigation. If TeXnicCenter works, then use it. –  xport Jul 19 '11 at 22:03