How to include graphics with spaces in their path?

I want to import graphics into my main input file using the macro `\includegraphics`. It does not work if the filename contains spaces.

Include image with spaces in path directory to be processed with dvips also discusses this subject, but there is no solution there.

My compilation routine is latex->dvips->ps2pdf (because of PSTricks).

-
 possible duplicate of Include image with spaces in path directory to be processed with dvips – TH. Jan 7 '11 at 3:35 Is it the path that contains spaces (e.g., with the `\graphicspath` command), or the filename? Those aren't the same. – frabjous Jan 7 '11 at 3:43 @frabjous, for generalization, both `\graphicspath` and `\includegraphics` contain paths with spaces. – xport Jan 7 '11 at 3:52 @TH., there is no solution there :-) – xport Jan 7 '11 at 3:53

2 Answers

Try:

``````\usepackage{etoolbox}
\makeatletter
\patchcmd{\Ginclude@eps}{"#1"}{#1}{}{}
\makeatother
...
\includegraphics{"file name.eps"}
``````

The macro `\Ginclude@eps` is defined in the file dvips.def. It uses `\special{PSfile="#1"\space ...` which causes problems if additional "" are used. I patched this, such that it behaves like it was written `PSfile=#1` and it worked for me in a test with an eps file with a space in the name and dvips.

-
 Thanks for answering. However, it does work only when we don't use `\graphicspath`. – xport Jan 16 '11 at 1:19 @xport: I'm glad to hear that it works. Since `\graphicspath` was not part of the question, it did not test with it. I'll do later. – Stefan Kottwitz♦ Jan 16 '11 at 2:20

try

``````\usepackage{graphicx}
\usepackage[space]{grffile}
[ ... ]
\includegraphics[...]{A file with spaces}
``````
-
 @xport: No real idea, I am a Linux user ... but I suppose `"directory with spaces/filename with space.eps"` – Herbert Jan 7 '11 at 6:53 all permutations have been tried, but none works. :-) – xport Jan 7 '11 at 7:11 @xport: I'll test it later, had some real work now :-) – Herbert Jan 7 '11 at 7:14 ok thanks for answering. – xport Jan 7 '11 at 7:16 This worked for me, thanks! – Adam Nellis Sep 28 '11 at 10:28