1

I want to specify path-to-image\image.png but for obvious reasons that will not work because \... is interpreted as a command. How do I include a path to my image? (I'm on Windows 7).

\documentclass[12pt]{article}
\usepackage{graphicx}

\begin{document}
\includegraphics[scale=1]{Data Analysis Files\InteractionPlotforTransLog10(X+1)Count.png}
\end{document}

I also tried reversing the slash and using the grffile package with the space option as follows:

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage[space]{grffile}

\begin{document}
\includegraphics[scale=1]{Data Analysis Files/InteractionPlotforTransLog10(X+1)Count.png}
\end{document}
Caramdir
  • 89,023
  • 26
  • 255
  • 291
ptrcao
  • 6,603
  • Possible duplicate: http://tex.stackexchange.com/questions/15387/specifying-an-absolute-windows-path-for-includegraphics – doncherry Jun 05 '11 at 14:26
  • Forgive me, I saw some of those previous threads but I tried a number of permutations of the solutions but couldn't get it to work including reverse the slash, invoke grffile pkg with space option, but no luck still...I would be grateful if someone would suggest an explicit solution... – ptrcao Jun 05 '11 at 14:50
  • The source of problem is the path with spaces, see http://tex.stackexchange.com/questions/8422/how-to-include-graphics-with-spaces-in-their-path/9030#9030 – Display Name Jun 05 '11 at 15:00
  • @ptrcao Put quotes around the name: "Data Analysis Files/InteractionPlotforTransLog10(X+1)Count.png" – egreg Jun 05 '11 at 15:02
  • @egreg: Quotes do not help. I have tried several month ago, see this http://tex.stackexchange.com/questions/8422/how-to-include-graphics-with-spaces-in-their-path/9030#9030 – Display Name Jun 05 '11 at 15:04
  • @ptrcao: I reproduced your folder structure and was able to compile your second example (the one with \usepackage[space]{grffile}) without getting any errors or warnings, using MiKTeX 2.9 on Win7. Which distribution do you use? Make sure grffile is installed and updated. – doncherry Jun 05 '11 at 15:13
  • @ptrcao: Asking the other way round: What kind of error messages or warnings do you get when compiling the grffile example? – doncherry Jun 05 '11 at 15:23

2 Answers2

3

Try:

\documentclass[12pt]{article}

\usepackage{a4wide}
\usepackage{graphicx}

\begin{document}
\includegraphics[scale=1]{\string"Data Analysis Files\string\InteractionPlotforTransLog10(X+1)Count"}
\end{document}
Marco Daniel
  • 95,681
  • ! LaTeX Error: File `"Data Analysis Files\InteractionPlotforTransLog10(X+1)Count"' not found. – ptrcao Jun 05 '11 at 14:57
  • I work with Ubuntu and it works for me. Sorry. Is the name of the file Data Analysis Files\InteractionPlotforTransLog10(X+1)Count – Marco Daniel Jun 05 '11 at 15:01
  • This one works for me, too (MiKTeX 2.9 on Win7). ...Count.png"} doesn't work; ...Count".png} and ...Count"} (Marco's) work. – doncherry Jun 05 '11 at 15:16
  • The path is "Data Analysis Files" The filename is "InteractionPlotforTransLog10(X+1)Count" Is that what you meant? – ptrcao Jun 05 '11 at 16:52
  • Relative links are allowed right? – ptrcao Jun 05 '11 at 16:59
  • Yes, it finally works - \includegraphics[scale=0.7]{"Data Analysis Files/InteractionPlotforTransLog10(X+1)Count"} is sufficient apparently, reverse the slash and insert inside inverted commas. \string works but is not apparently needed. Thanks Marco :) – ptrcao Jun 05 '11 at 17:09
  • 1
    @ptrcao: Great, I'm glad your problem could be helped. A tip: you can use backticks ``` to mark your inline code in comments as well as in questions and answers. It just makes it much easier to read. – doncherry Jun 05 '11 at 17:17
  • thx for the tip ;) – ptrcao Jun 05 '11 at 17:47
1

An alternative that works is to use the short DOS path name. In the DOS prompt window enter dir /x to obtain the short names. Use \detokenize to get around the tildes ~ in the file names.

\includegraphics{\detokenize{DATAAN~1/INTERA~1}}

I normaly use a Python script to get needed short names by copying an exsiting path into the script below.

import win32api

#Copy and paste an existing path here
path = r'C:\Users\dnjels\Documents\DE-LaTeX\Temp\Tests\Data Analysis Files\InteractionPlotforTransLog10(X+1)Count.png'

shortpath = win32api.GetShortPathName(path)
shortpath = shortpath.replace('\\','/')

print  shortpath
print  r'\detokenize{' + shortpath + '}'

This will give (on my system)

C:/Users/dnjels/DOCUME~1/DE-LaTeX/Temp/Tests/DATAAN~1/INTERA~1.PNG

Danie Els
  • 19,694
  • Thanks Danie, apparently the solution was simpler than I thought but the nobel effort has been recognised with an upvote. I'm probably not knowledgeable enough to get my head around this yet, but someone else will find it useful, I'm sure :) – ptrcao Jun 05 '11 at 17:12