3

I get this error when trying to load .png file

I import

\usepackage[pdftex]{graphicx}
\graphicspath{ {C:\Users\Daniel\Desktop\projectfigures} }

\begin{document}
\includegraphics[width=2.5cm]{definitiongraphexample.png}

\end{document}

The problem is I get this error

! Undefined control sequence.

\reserved@b ->C:\Users 
                       \Daniel \Desktop \projectfigures 
l.423 ...[width=2.5cm]{definitiongraphexample.png}

I can't seem to load it. I've tried to load include{path} and that didn't work. So I'm now trying to graphicspath

What am I doing wrong?

\usepackage[pdftex]{graphicsx} doesn't get an error and it doesn't say to download it so I don't know why this isn't working.

egreg
  • 1,121,712
  • Welcome to TeX.sx! Use direct and not reverse slashes: C:/Users/Daniel/Desktop/projectfigures – egreg Apr 04 '13 at 23:04
  • egreg I have tried that, but I get this error ! Package pdftex.def Error: File `definitiongraphexample.png' not found. – simplicity Apr 04 '13 at 23:06
  • 2
    Add also a trailing /: \graphicspath{{C:/Users/Daniel/Desktop/projectfigures/}}. See also the related question http://tex.stackexchange.com/questions/15387/specifying-an-absolute-windows-path-for-includegraphics Finally, remove the pdftex option to graphicx – egreg Apr 04 '13 at 23:07
  • egreg thanks that solved the problem. The image loads now. Thank you. – simplicity Apr 04 '13 at 23:19

1 Answers1

6

As explained in the related question Specifying an absolute Windows path for \includegraphics one has to use "direct" and not "reverse" slashes for specifying paths in Windows.

The TeX programs know how to replace the slashes for going to the required directory; this is because the backslash is interpreted as usual in TeX as prefixing a command name.

Moreover, you should add a trailing slash for the path:

\graphicspath{{C:/Users/Daniel/Desktop/projectfigures/}}

so when the whole string is prepended to the file name you get the correct

C:/Users/Daniel/Desktop/projectfigures/definitiongraphexample.png

Two more tips.

  1. Don't specify an extension; pdflatex will find the file and this adds to portability:

    \includegraphics[width=2.5cm]{definitiongraphexample}
    
  2. Don't specify the pdftex option to graphicx

    \usepackage{graphicx}
    

    is sufficient.

egreg
  • 1,121,712