TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to insert source code in LaTeX with using listings, but my code has accents and pdflatex gives me this error:

Unicode char \u8:�\expandafter not set up for use with LaTeX.

This is a code the reproduces the error.







// Código con una tilde

What can I do to generate the PDF correctly?

share|improve this question
up vote 13 down vote accepted

You can load the package listingsutf8 and then set the encoding using \lstset{inputencoding=utf8/latin1}:





share|improve this answer
Thanks for your answer. With the second method the ó is not in its right place, but the first method works perfectly!. – kevinz Oct 5 '11 at 5:06
You're right, I didn't notice the slight misalignment. I've removed the second method. – Jake Oct 5 '11 at 5:08
the accpeted solution doesn´t work for me. – Mika Ike Jun 21 '14 at 9:44
This doesn't seem to work with \usepackage{listings} \usepackage{listingsutf8} \usepackage[french]{babel} and \begin{lstlisting}[breaklines]. Although I'm not getting compilation errors, the french characters aren't displayed properly. – JoErNanO Nov 9 '15 at 10:18

The accepted solution didn't work for me, so here is mine:

\usepackage{listings} % ordinary listings package

and then configure letter mappings - these mappings are for the Czech languaguge but you can configure your own

share|improve this answer
Thnak you, I was in your case. The accepted solution doesn´t works for me, and your solutions has solved my problem in spanish. – Mika Ike Jun 21 '14 at 9:46

Hungarian version based on previous answer:

\lstset{ literate={á}{{\'a}}1 {é}{{\'e}}1 {í}{{{\'\i}}}1 {ó}{{\'o}}1 {ö}{{\"o}}1 {ő}{{\H o}}1 {ú}{{\'u}}1 {Ú}{{\'U}}1 {ü}{{\"u}}1 {ű}{{\H u}}1 {Ü}{{\"U}}1 }
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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