[Tex/LaTex] How to include graphics with spaces in their path

external filesgraphicspaths

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).

Best Answer

Try etoolbox package:

\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.