[Tex/LaTex] Umlauts in filenames using the grffile package

graphicsinput-encodingsmiktexpdftex

"Never ever use non-ASCII characters and spaces in your filenames. Never!"

That's what I'm telling my students for years. But if for any reasons there is an urgent need to include an image file with umlauts in its filename, the grffile package could be used.

Unfortunately, I was not able to get the following example compiled:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[ngerman]{babel}

\usepackage{graphicx}
\usepackage[extendedchars]{grffile}

\begin{document}

\includegraphics{Bäckerstraße}

\end{document}

I'm using MiKTeX (recently updated) upon Windows 7. My MWE is saved in Cp1252 Windows encoding. The same is valid for the existing file Bäckerstraße.png on my file system.

I compiled with pdflatex. The compilation produces no PDF output with no error message in the log file. The compilations stops with an error message in the command shell:

pdflatex: Windows API error 1113: F��r das Unicode-Zeichen ist kein zugeordnetes Zeichen in der Mehrbytecodepage vorhanden.

I googled for this problem and found some forum discussion from 2011 and 2012 indicating that this could be a general pdflatex problem using MiKTeX.

I'm asking, if there is just a dumb error of mine inside the MWE code or if there is just no chance to run this with MiKTeX.

If there is an error in the MWE, please, let me know how to correct it. But if this cannot run at all, please, stop me wasting time trying.

Best Answer

Since the file name encoding seems to be UTF-8, the file name needs to be reencoded from Latin-1 to UTF-8. This is also supported by package grffile:

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{graphicx}
\usepackage[encoding,filenameencoding=utf8]{grffile}

\begin{document}
\includegraphics{Bäckerstraße}
\end{document}

Alternatively the TeX source could be encoded in UTF-8 entirely.

BTW, the full range of code page for CP 1252 is provided by options ansinew or x-cp1252 for package inputenc (the latter option comes from package inputenx and can be used as cp1252 there).