[Tex/LaTex] Typesetting UTF8 listings with German Umlaute

germanlistings

I'm having some issues with listings that include German Umlaute. The following example code generates a completely messed up PDF.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[]{listings}
\begin{document}
\begin{lstlisting}[language={[LaTeX]TeX},inputencoding={utf8},extendedchars=false]
Staatsangehörigkeit
\end{lstlisting}
\end{document}

Does anyone have an idea how to fix this?

Umlaute

Best Answer

the normal listings package doesn't provide unicode support. I use the following code to work around the Problem

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[]{listings}

\lstset{literate=%
    {Ö}{{\"O}}1
    {Ä}{{\"A}}1
    {Ü}{{\"U}}1
    {ß}{{\ss}}1
    {ü}{{\"u}}1
    {ä}{{\"a}}1
    {ö}{{\"o}}1
    {~}{{\textasciitilde}}1
}
\begin{document}
    \begin{lstlisting}[language={[LaTeX]TeX}]
    Staatsangehörigkeit
    \end{lstlisting}
\end{document}

I also tried listingsutf8 and listings2 which ist BETA, but for me the literate solution just works perfekt ;)

edit:sry, marco has the same solution earlier...