1

If I put texts containing French characters outside of \begin{lstlisting}...\end{lstlisting}, it works. For instance,

\documentclass[twoside,12pt]{article}

\usepackage[utf8]{inputenc}

% for source code 
\usepackage{listingsutf8}
\usepackage{listings}
\lstset{frame=single,
  aboveskip=3mm,
  belowskip=3mm,
  columns=flexible,
  basicstyle={\small\ttfamily},
  breaklines=True,
  postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookrightarrow\space}}
}

\begin{document}
\begin{lstlisting}
route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color
\end{lstlisting}

11821949021891662,6192449487677451,67,Arènes / Plaisance Monestié (par Marquisat),Ligne Arènes / Plaisance Monestié (par Marquisat),3,,ffa8ff,FFFFFF

\end{document}

which produces,

enter image description here


However, if I put them inside \begin{lstlisting}...\end{lstlisting},

\begin{lstlisting}
route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color
11821949021891662,6192449487677451,67,Arènes / Plaisance Monestié (par Marquisat),Ligne Arènes / Plaisance Monestié (par Marquisat),3,,ffa8ff,FFFFFF
\end{lstlisting}

it raises the error ! Package inputenc Error: Unicode char �\lst@EC� (U+9EA8).

How do I fix it?

4
  • listingsut8 doesn't work with inline code. Use literate to replace the chars see e.g. tex.stackexchange.com/questions/214828/… Dec 15, 2016 at 13:54
  • Did you read the manual for listingsutf8? It only operates on \lstinputlisting. Listings does not in general support UTF8.
    – daleif
    Dec 15, 2016 at 13:54
  • 1
    @daleif, Thx. Now I know. Dec 15, 2016 at 14:09
  • @UlrikeFischer, thx for pointing out this. Dec 15, 2016 at 14:16

1 Answer 1

2

I made it by defining special characters like so,

\lstset{literate=
  {á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1
  {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1
  {à}{{\`a}}1 {è}{{\`e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1
  {À}{{\`A}}1 {È}{{\'E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1
  {ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1
  {Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1
  {â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1
  {Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1
  {œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1
  {ű}{{\H{u}}}1 {Ű}{{\H{U}}}1 {ő}{{\H{o}}}1 {Ő}{{\H{O}}}1
  {ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1
  {€}{{\euro}}1 {£}{{\pounds}}1 {«}{{\guillemotleft}}1
  {»}{{\guillemotright}}1 {ñ}{{\~n}}1 {Ñ}{{\~N}}1 {¿}{{?`}}1
}

In my case, I got,

enter image description here

Refer to LaTeX/Source Code Listings: Encoding issues.

By default, listings does not support multi-byte encoding for source code. The extendedchar option only works for 8-bits encodings such as latin1.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .