7

I need to copy and past some UTF8 code into a lstlisting, but unfortunately, I receive the following error :

! Package inputenc Error: Unicode char \u8:�\lst@FillFixed@\lst@EC� not set up for use with LaTeX.

Keyboard character used is undefined

What is weird was that I didn't noticed any weird characters in my lstlisting code (it's some bash code). Furthermore I got the package in header:

 \usepackage[utf8]{inputenc}

What should I do?

  • 3
    Please check the following TeX.sx link: tex.stackexchange.com/q/25391/19384. It explains the problem an dhow to get UTF8 into the lstlistings – Peter Jansson Jan 6 '13 at 22:07
  • 1
    A related potential issue is with \lstinputlisting:that you've used an editor that's been too clever, and the file that you thought wasn't utf8 now is, with some odd unicode characters hidden by the editor at the start. I was getting the same error message as this on the first line, whatever I put at the start of the file. The � may be a real unicode character U+FFFD:REPLACEMENT CHARACTER in the output. – Chris H Mar 14 '14 at 13:20
10

I just solved it in using

  inputencoding=latin1

I hope it can help some in the same case than me.

  • 2
    Sorry, but where did you put this? – Bex Jan 9 '17 at 18:54
  • 1
    @Bex You put this as an optional argument of \lstinputlisting. For instance, if my "test.m" MATLAB file just contains the text "% é", I use the following: \lstinputlisting[inputencoding=latin1]{test.m} and it works – R. Bourgeon May 27 '17 at 15:30
10

listings cannot handle UTF8-characters. Search in the docs for the keyword literate. Then you'll see how UTF-8 characters can be mapped to TeX commands, eg ü->\"u: \lstset{literate={ü}{{\"u}}1}

2

I solved adding texcl=true to the \lstset configuration.

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.