42

I have a file called xxxx_0.1.png, and want to import it as an image in my document. I am using graphicx with the following command:

\includegraphics[width=0.5\textwidth]{images/xxxx_0.1.png}

and LaTex gives me the error:

Unknown graphics extension: .1.png

Basically, it is treating everything after the first dot as the file type, rather than only the stuff after the last dot.

Other than the obvious solution (renaming the files so it only has one dot), does anyone know if there a way to get LaTex to play ball?

  • 3
    putting the name inside {} maybe? – Mario S. E. Apr 24 '13 at 15:41
  • I know it won't solve the problem because it would then see .1 as the extension, but you don't actually need the last .png. – Betohaku Apr 24 '13 at 15:43
  • LaTeX can manipulate strings using regular expressions. Seems rather like overkill in this case. – Ethan Bolker Apr 24 '13 at 15:43
  • Welcome to TeX.SX. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}) or hit Ctrl+K. – Claudio Fiandrino Apr 24 '13 at 15:54
58

The LaTeX graphics/graphicx package uses the first dot to find the extension. Package grffile changes the algorithm to check for known extensions (option multidot, enabled by default):

\usepackage{graphicx}
\usepackage{grffile}
  • 3
    And many thanks to you for that wonderfull grffile package, which makes it much more comfortable to include files. – Keks Dose Apr 24 '13 at 16:02
  • That's like the worst possible way to find the extension... Why did no one fix this? – Stefan Fabian Nov 15 '17 at 14:05
  • 1
    According to the second answer of David Carlisle in LaTeX problem report graphics/2614 "filenames not handled correctly in graphics", the reason is (was) speed. However, the answer was given 1997. I do not know the official opinion of the LaTeX maintainers two decades later. – Heiko Oberdiek Nov 15 '17 at 18:53
  • 1
    @HeikoOberdiek the official position is that I plan to change the default parsing (actually I'd planned to have already done it by now, but real life got in the way, most likely for the next release....) – David Carlisle Nov 15 '17 at 19:06
18

Of course the obvios answer is just to rename the file so it doesn't have any dots in its name, but you can try using {} braces for the name and get a good result. e.g.:

\includegraphics[width=0.5\textwidth]{images/{xxxx_0.1}.png}

Edit: moved the closing brace before the extension, as mentioned in the comments.

  • 1
    Shouldn't the inner brace close before the .png - i.e. {images/{xxxx_0.1}.png} ? – sdaau Aug 1 '13 at 22:16
  • I am having the same issue and this thread helped! And btw, @sdaau is correct with his comment. – EverythingRightPlace Oct 15 '14 at 14:40
10

You can disable the filename parser by specifying the extension and file type as attributes. For pdftex that would be

\includegraphics[width=0.5\textwidth ext=.png type=png]{images/xxxx_0.1}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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