1

I have the following document (excerpts):

\documentclass[a4paper]{article}

% Paketimporte
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{eurosym}
\usepackage{titlesec}
\usepackage[pdftex]{graphicx}
\usepackage{float} 
\usepackage{url}
\usepackage{wrapfig}
\usepackage{csquotes}
\usepackage{glossaries}
\usepackage[markup=nocolor,deletedmarkup=xout]{changes}
\usepackage{listings}
\usepackage{color}
\usepackage{amssymb}

\DeclareUnicodeCharacter{00A0}{ }
\DeclareUnicodeCharacter{207C6}{\dash}
\DeclareUnicodeCharacter{2192}{\dash}

\begin{document}    
% Titelblatt
\maketitle
\pagebreak

% Inhaltsverzeichnis
\tableofcontents
\pagebreak

\begin{lstlisting}
    foo → bar
\end{lstlisting}
\printglossaries
\end{document}

Which produces the following error when invoking pdflatex:

Package inputenc Error: Unicode char �\lst@FillFixed@\lst@EC� (U+207C6)(inputenc) not set up for use with LaTeX. foo →

I already googled for this error and found some similar, but not equal issues, which encourage to use \ DeclareUnicodeCharacter or \newunicodechar, but which does not work. The file in question is also UTF-8 encoded:

$ file -i test.tex
test.tex.tex: text/x-tex; charset=utf-8

How can I get latex to display the character?

  • @UlrikeFischer I am terribly sorry. – Richard Neumann Dec 18 '17 at 13:36
  • U+207C6 points to an undefined point in the CJK Ideograph Extension B block. Are you sure you meant it? – egreg Dec 18 '17 at 13:36
  • No, is actually U+2192 but according to the tex error message it recognizes it as U+207C6. I have no clue why. – Richard Neumann Dec 18 '17 at 13:37
  • listings is not designed up for multi-character UTF8 input and so it is confused and the number shown in the error message is entirely spurious. – David Carlisle Dec 18 '17 at 13:40
2

listings doesn't really have UTF-8 support, so what happens when it finds is essentially random.

You need not to declare the character if you load textcomp, because LaTeX knows how to translate it to \textrightarrow, but you need to teach it explicitly to listings.

\documentclass[a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{textcomp}

\usepackage{listings}

\lstset{
  literate={→}{\textrightarrow}1
}

\begin{document}

foo → bar

\begin{lstlisting}
foo → bar
\end{lstlisting}

\end{document}

enter image description here

  • Ah. So it's due to a shortcoming in the listings package. Tricky. – Richard Neumann Dec 18 '17 at 13:46
1

You can define an output with literate:

\documentclass[a4paper]{article}

% Paketimporte
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\usepackage{listings}
\lstset{literate={→}{$\rightarrow$}1}

\DeclareUnicodeCharacter{00A0}{ }
\DeclareUnicodeCharacter{2192}{\dash}

\begin{document}
\begin{lstlisting}
    foo → bar
\end{lstlisting}

\end{document}

enter image description here

  • That works, thank you. Now I'm trying to understand why. – Richard Neumann Dec 18 '17 at 13:43

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.