[Tex/LaTex] Unknown Graphics Extension PNG/PDF

graphicsgummipdftex

I was having no problem with this until a couple of hours ago. Everything was working perfectly, until pdftex suddenly decided to throw errors on including graphics (example is png, but was originally pdf).

The following are the packages I'm using:

\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{colortbl}
\usepackage{placeins}
\usepackage[margin=2.5cm]{geometry}
\usepackage{multirow}

The following is the code I'm using to load the image:

\begin{figure}[h]
\centering
\includegraphics[width=0.8\textwidth]{ test.png }
\end{figure}

geometry driver: auto-detecting
geometry detected driver: pdftex

LaTeX Warning: No \author given.

./.Report.tex.swp:15: LaTeX Error: Unknown graphics
extension : .png .

See the LaTeX manual or LaTeX Companion for explanation. Type H
for immediate help. …

l.15 …egraphics[width=0.8\textwidth]{ test.png

./.Report.tex.swp:15: ==> Fatal error occurred, no
output PDF file produced! Transcript written on
/tmp/.Report.tex.log.

I've also tried specifying the type and extension, but it provides me with a different error. So, for the code…

\begin{figure}[h]
\centering
\includegraphics[width=0.8\textwidth, type=png, ext=.png]{ test }
\end{figure}

with the following error…

geometry driver: auto-detecting
geometry detected driver: pdftex

LaTeX Warning: No \author given.

./.Report.tex.swp:15: LaTeX Error: Cannot determine
size of g raphic in test .png (no size specifed).

See the LaTeX manual or LaTeX Companion for explanation. Type H
for immediate help. …

l.15 …0.8\textwidth, type=png, ext=.png]{ test }
./.Report.tex.swp:15: ==> Fatal error occurred, no output PD F file produced! Transcript written on /tmp/.Report.tex.log.

Few things of note: I'm using Gummi, but pdflatex has the same errors when I run it in a terminal. The images are generated by python's matplotlib library. This all seemed to start when I first used the grffile package (as my original files had multiple ., now removed) but it's definitely not being used anymore.

I presume something has gone wrong with the installation here, but I thought I would ask in case I'm missing something. Please let me know if you want any additional details.

Thanks

Best Answer

Rarely use spaces in file names, and be extra careful when including images that have spaces in their names. So, your use of

\includegraphics[..]{ test }

is interpreted as looking for file test .ext - note the space before and after (where .ext is one of the approved graphic file extensions associated with your driver). Similarly,

\includegraphics[..]{ test.png }

can't find a file extension .png - note the space at the end. So, use

\includegraphics[..]{filename}

where the driver will look for the appropriate file name filename (no spaces).

A work-around for when you actually do have spaces in your file names, are provided by the grffile package.


Somewhat unrelated, but the following will also be problematic:

\documentclass{<class><space>}

as in \documentclass{article }. However, it's fine to use

\usepackage{ <package> , <package> , ... }