Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
possible duplicate of Include image with spaces in path directory to be processed with dvips –  TH. Jan 7 '11 at 3:35
1  
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 2

up vote 18 down vote accepted
+250

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.

share|improve this answer
    
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

Use package grffile:

\usepackage{graphicx}
\usepackage[space]{grffile}
[ ... ]
\includegraphics[...]{A file with spaces}
share|improve this answer
    
all permutations have been tried, but none works. :-) –  xport Jan 7 '11 at 7:11
    
ok thanks for answering. –  xport Jan 7 '11 at 7:16
    
This worked for me, thanks! –  Adam Nellis Sep 28 '11 at 10:28
    
This also work for me... thanks.. –  Mohammad Fajar Feb 24 at 9:21
    
Worked for me, too. Thanks! –  Raubi May 22 at 11:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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