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

  • 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
  • Jimi Damon wonders which of the below solutions work if the filename contains a comma in the name. Comments? – Benjamin McKay Jul 19 '16 at 20:27

Try etoolbox package:

\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
  • 1
    Can you give a full example? I cannot make it work. – Gqqnbig Nov 2 '19 at 0:13
  • @Gqqnbig this patch against an old 2011 version of the code is not suitable. In current latex releases spaces in filenames should work with no special code needed. – David Carlisle Dec 28 '19 at 15:40

Use package grffile:

[ ... ]
\includegraphics[...]{A file with spaces}
  • 1
    all permutations have been tried, but none works. :-) – xport Jan 7 '11 at 7:11
  • 2
    It works perfectly for me, and the @stefankottwitz doesn't. – Peregring-lk Feb 3 '17 at 22:36
  • @xport According to the doc of grffile, to support whitespace in the filename, one should use pdfLaTeX. – Eli4ph Aug 15 '19 at 2:33

A simpler solution would be...

\includegraphics{{"../Current folder/1.This file"}.png}

(For Windows users,) note that the slashes all need to be forward slashes.

  • 1
    It does not work. The following kind of works: \includegraphics{{C:/Users/User/Desktop/b c}.jpg} - It includes the correct graphics file, but also prints " <space> c ". – Antonio Sesto Nov 29 '16 at 14:14
  • The printing is a part of the package I think. But I have used my solution in multiple documents of different types and they all worked. It's strange it didn't work in yours. – Argyll Dec 4 '16 at 23:02
  • 2
    Sorry for not updating earlier. This has worked without any issue: \includegraphics{{"C:/Users/User/Desktop/b c"}.jpg}. The graphics file was 'b c.jpg' in the Desktop. – Antonio Sesto Dec 5 '16 at 14:48
  • The ../ part is for relative path. – Argyll Dec 8 '16 at 15:04
  • 2
    Works great in overleaf! Wonder why png is outside of quotes and brackets? – Ben Usman Mar 29 '19 at 19:51

In the LaTeX2e 2019-10-01 Patch Level 2 release that should be arriving in distributions any day soon, you can use

\includegraphics[...]{A file with spaces}

just using the core graphicx package, no additional packages or quoting of spaces should be needed.

The same is true with \input{A file with spaces} which will input A file with spaces.tex

Despite the fact that some effort has gone into making this work, it is still a good idea not to use spaces in filenames.

  • Thank you for this comment! I had a slightly different problem: my PDFs suddenly stopped rendering images! The output log showed some extraneous quotes around the image path. I realized I had \usepackage[multidot]{grffile} in my preamble, after removing it - the images began rendering again! – Igal Tabachnik Feb 13 '20 at 22:17
  • Works fine with .pdf pictures, but when trying to include .eps pictures I'm getting rectangle box instead of the figure. Replacing spaces with underscores solves the issue. – Lev K. Jul 23 '20 at 0:45

Since this issue was never quite sufficiently answered, I just want to add that for some commands in packages where a file path needs to be specified, if you put the space in quotations (i.e., " "), this will also work (dependent on the package and how the programmer designed the package, of course).

For example:

% Preamble
\newcommand{\relativedir}{./../../Some/Directory/Directory" "Name}
% Within the Document

This would include a file in ../../Some/Directory/Directory Name/NameOfFile.tex (e.g., in a relative directory: with the single dot ./ representing the current directory and the double-dot ../ representing a directory higher in the hierarchy).


Just surround the path with double quotes like this "./path with spaces/images/". That would the simplest solution.


this post is quite old now but I encountered the same problem when compiling with biber. For me the solution was to provide the path to \addbibresource replacing 'Folder with spaces' with 'Folder*'. So for example:


Just make sure that there are no other folders that starts with 'Folder' under the same folder level (here no other folder under D:/ should start with OneDri)

Cheers, Piotr

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