1

I am attempting to display a long Python Regexp in LaTeX lstlistings. When compiling I get the following error message though.

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

I believe it is caused by the quote marks ' and ´. How do I correctly display them in lstlisting the simplest way possible? I am a LaTeX beginner, and have searched and tried many other solutions, however none has helped me.

\lstset{
language=Python,
basicstyle=\footnotesize,
captionpos=t,
texcl=true,
numbers=left,                    
numbersep=7pt,                   
showspaces=false,                
showstringspaces=false,          
showtabs=false,                  
stepnumber=1,   
breaklines=true,
}          

\begin{lstlisting}[frame=single, caption=Full source code]

pattern_p = re.finditer("(\t|; )((\w{2,}( |-)?)+) ?(\((m|f|n)\))? ?(\(((\w{2,}\'?-?’?\?? ?)+)(\)|,|’))?", decoded_line)

\end{lstlisting}
  • 1
    (1) Welcome, (2) always post MWEs that are things we can (attempt to) compile. Here we do not know the preamble. Are you sure you are not looking for ' (the apostrophe) and ` (sometimes called the back ping). Those are ascii chars. When I copy your text those are UTF8 chars. – daleif May 26 '15 at 11:32
  • If I change those to ascii chars, then the code works fine. – daleif May 26 '15 at 11:35
  • Yes, those are UTF-8 chars because they are the ones I'm looking for with the Regexp. – user2768479 May 26 '15 at 11:54
  • listings does not like utf8 (it cannot handle 2bit chars very well). You might want to use literate in order to tell it how to handle those two chars. – daleif May 26 '15 at 12:09
  • This at least compiles: literate={’}{`}1 might want to use a different output symbol – daleif May 26 '15 at 12:13
2

lstlistings does not work well with UTF-8. By adding

\lstset{
literate={’}{\textquoteright}1 {ʹ}{\textquoteright}1
}

The UTF-8 chars were replaced with close LaTeX produced counterparts. Solution provided by daleif above.

| improve this answer | |

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.