Document ClassesNational characters inside lstlisting environment

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
lalelale
Posts: 6
Joined: Fri Sep 19, 2008 3:02 pm

National characters inside lstlisting environment

Post by lalelale »

Hello everyone,
are you aware of any way to include special characters (è,ò,à...) inside listings with the listings package? I tried the extendedchars=true option of the package, as well as using inputenc, fontenc, and their combination, but no way, it fails every time.
Or, should I try an alternate package?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

National characters inside lstlisting environment

Post by phi »

I've just tried inputenc with latin1 (ISO-8859-1) encoding, this seems to work fine. UTF-8 on the other hand doesn't work. If you only use Latin-1 characters, this could be an option for you. extendedchars should be enabled by default in newer versions of the listings package.

Code: Select all

\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{listings}
% ...
\begin{lstlisting}
èàò
\end{lstlisting}
lalelale
Posts: 6
Joined: Fri Sep 19, 2008 3:02 pm

Re: National characters inside lstlisting environment

Post by lalelale »

Thank you, this is similar to the answer the package author gave. I'll try this ASAP. My fault was always using UTF8
User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

National characters inside lstlisting environment

Post by Stefan Kottwitz »

Hi,

there's the package listingsutf8 that provides a workaround for using utf8 with listings when \lstinputlisting would be used.

Stefan
LaTeX.org admin
Post Reply