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?

8 Answers 8


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





  • Thanks for your answer. With the second method the ó is not in its right place, but the first method works perfectly!.
    – kevinz
    Oct 5, 2011 at 5:06
  • You're right, I didn't notice the slight misalignment. I've removed the second method.
    – Jake
    Oct 5, 2011 at 5:08
  • 7
    the accpeted solution doesn´t work for me.
    – Mika Ike
    Jun 21, 2014 at 9:44
  • 1
    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, 2015 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

  • 2
    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, 2014 at 9:46
  • Better solution than the accepted one. Very useful for me for french comments in the code.
    – 3isenHeim
    Jan 12, 2021 at 8:07
  • Yes, it worked for well nicely in French. Why are there numbers 1 at the end of each line? Jun 26, 2021 at 20:40

In Brazilian portuguese, this solution worked for me

\usepackage{listings} % for including code

language=R,   % R code

None of the above worked here, just this way:



    language=bash,   %% PHP, C, Java, etc... bash is the standard
  • This last solution does not work if your source code is in utf-8 and you replace latin1 by utf8 ;-(
    – Tsf
    Jun 23, 2017 at 13:47

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 }

LaTex magyar ékezetes karakterek.


Set for Polish language:


Set for the Greek language:


Set for French language :

  • Welcome to SE. Notice that the question you answered to was very old. In this day and age, that sort of workaround is no longer necessary. I've been using plain listings with regional characters (including French) for years without any need to any configuration. So unless you're stuck on a very old system, using those workarounds should be avoided.
    – Miyase
    Jun 4 at 16:35
  • On overleaf I'm still getting this issue @Miyase
    – Butanium
    Jun 15 at 16:55
  • @Butanium Then you probably have a problem elsewhere in your preamble. I have my students use Overleaf and most of them have code typeset with listings, and the workaround you mention has never been necessary. You should make a pass over your packages and check with CTAN if some of them were deprecated.
    – Miyase
    Jun 15 at 17:16
  • Maybe, I'm using a ieee template so I a lot of packages are included by default
    – Butanium
    Jun 15 at 17:26

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.