70

Trying to include a source-file into my latex document using the listings package, i got problems with german umlauts inside of the comments in the code. Using

\lstset{
extendedchars=\true,
inputencoding=utf8x
}

Umlauts in the source files (encoded in UTF-8 without BOM) are processed, but they are somehow moved to the beginning of the word they are contained in. So

// die Größe muss berücksichtigt werden

in the input source file, becomes

// die ößGre muss übercksichtigt werden

in the output file.

NOTE: since i found errors in my initial setup, i heavily edited this question

4
  • 1
    What input encoding did you declare in your document and what encoding do you use in your editor?
    – Gumbo
    Jul 12, 2009 at 15:47
  • 1
    I've had the same problem with French. IMO you should try using non-multibyte encoding, such as Latin-1. Jul 12, 2009 at 16:22
  • 1
    Similar problem with cyrillic. Using one byte encoding solves the problem.
    – Vanuan
    Sep 29, 2009 at 19:50
  • A quite complete literate statement for using with lstlistings is at: tex.stackexchange.com/a/574950/6865
    – Stephen
    May 18 at 17:57

25 Answers 25

64

I found a simpler approach, which works for me:

\usepackage{listings}

\lstset{
  literate={ö}{{\"o}}1
           {ä}{{\"a}}1
           {ü}{{\"u}}1
}
5
  • 1
    this works fine for me, package listingsutf8 is not needed. Best workaround!
    – Chielus
    May 18, 2011 at 9:32
  • 5
    It also works for Turkish. Here is the related code snippet: \lstset{ literate={â}{{\^{a}}}1 {Â}{{\^{A}}}1 {ç}{{\c{c}}}1 {Ç}{{\c{C}}}1 {ğ}{{\u{g}}}1 {Ğ}{{\u{G}}}1 {ı}{{\i}}1 {İ}{{\.{I}}}1 {ö}{{\"o}}1 {Ö}{{\"O}}1 {ş}{{\c{s}}}1 {Ş}{{\c{S}}}1 {ü}{{\"u}}1 {Ü}{{\"U}}1 }
    – petrichor
    Jun 3, 2011 at 16:27
  • 2
    The solution using texcl=true described in another answer seems to be more elegant. Feb 9, 2013 at 16:41
  • 1
    Someone knows how this solution would look like for the norwegian characters æøå? Sep 3, 2013 at 18:06
  • i do not think this is a solution or workaround because this does not help if you have long (maybe generated) content with arbitrary special characters.
    – anion
    Jan 27, 2020 at 15:04
43

For comments only, you can use the texcl option:

\lstset{language=C++,texcl=true}

Than your comments become Latex and you can use "special" characters

\begin{lstlisting}
int iLink = 0x01; // Paramètre entrée
\end{lstlisting}
4
  • 9
    This is one of the most elegant solutions here, needs more upvotes! :) Feb 9, 2013 at 16:39
  • Wow! Then you can even put math formulas into the listings, e.g. double pi = 3.141; // This is $\pi$ or double d = 1.0 // $3 \int_0^1 x^2 dx$. This is really cool! Jan 16, 2015 at 9:21
  • Awesome! The other option (with literate) don't work with XeLaTex.
    – WerWet
    Jan 20, 2018 at 18:53
  • It seems that if there's $ or similar in some comment, they will be interpreted as math formula (which may be unintended, and causes many bugs if they're malformed)
    – user202729
    Dec 8, 2020 at 13:32
27

This should work for other languages (Spanish, Danish) as well:

\documentclass[
a4paper, %% defines the paper size: a4paper (default), a5paper, letterpaper, ...
12pt %% set default font size to 12 point
]{scrartcl} %% article, see KOMA documentation (scrguide.dvi)

\usepackage[utf8]{inputenc}

\usepackage[T1]{fontenc}
\usepackage{listings}

\lstset{language=Pascal}
\lstset{literate=%
{Ö}{{\"O}}1
{Ä}{{\"A}}1
{Ü}{{\"U}}1
{ß}{{\ss}}2
{ü}{{\"u}}1
{ä}{{\"a}}1
{ö}{{\"o}}1
}

\begin{document}

[Latex: kann man Umlaute in lstlisting verwenden?]
\begin{lstlisting}
Test für Umlaut äöü ÄÖÜ ß So geht es
\end{lstlisting}

\end{document} 
3
  • 5
    Thank you - it worked! The same for Polish language: \lstset{literate={ą}{{\k{a}}}1 {ł}{{\l{}}}1 {ń}{{\'n}}1 {ę}{{\k{e}}}1 {ś}{{\'s}}1 {ż}{{\.z}}1 {ó}{{\'o}}1 {ź}{{\'z}}1 {Ą}{{\k{A}}}1 {Ł}{{\L{}}}1 {Ń}{{\'N}}1 {Ę}{{\k{E}}}1 {Ś}{{\'S}}1 {Ż}{{\.Z}}1 {Ó}{{\'O}}1 {Ź}{{\'Z}}1 }
    – GDR
    Jun 29, 2010 at 20:12
  • 4
    And thank you, GDR! It was a time saver. You only forgot ć and Ć. Here is the full list (bonus: sorted) for quick Ctrl+C + Ctrl+V for others: \lstset{literate=% {ą}{{\k{a}}}1 {ć}{{\'c}}1 {ę}{{\k{e}}}1 {ł}{{\l{}}}1 {ń}{{\'n}}1 {ó}{{\'o}}1 {ś}{{\'s}}1 {ż}{{\.z}}1 {ź}{{\'z}}1 {Ą}{{\k{A}}}1 {Ć}{{\'C}}1 {Ę}{{\k{E}}}1 {Ł}{{\L{}}}1 {Ń}{{\'N}}1 {Ó}{{\'O}}1 {Ś}{{\'S}}1 {Ż}{{\.Z}}1 {Ź}{{\'Z}}1 } (obviously comments don't have newlines, so after pasting you have to fix it (e.g. in vim: :.s/ /\r/g)
    – przemoc
    Jun 13, 2011 at 15:00
  • 3
    Thank you - good solution! Anyway, it should be {ß}{{\ss}}1, because "ß" takes only 1 character in the output ;)
    – Simon
    Dec 31, 2011 at 14:29
18

My contribution for Czech language.

\lstset{
    inputencoding=utf8,
    extendedchars=true,
    literate=%
    {á}{{\'a}}1
    {č}{{\v{c}}}1
    {ď}{{\v{d}}}1
    {é}{{\'e}}1
    {ě}{{\v{e}}}1
    {í}{{\'i}}1
    {ň}{{\v{n}}}1
    {ó}{{\'o}}1
    {ř}{{\v{r}}}1
    {š}{{\v{s}}}1
    {ť}{{\v{t}}}1
    {ú}{{\'u}}1
    {ů}{{\r{u}}}1
    {ý}{{\'y}}1
    {ž}{{\v{z}}}1
    {Á}{{\'A}}1
    {Č}{{\v{C}}}1
    {Ď}{{\v{D}}}1
    {É}{{\'E}}1
    {Ě}{{\v{E}}}1
    {Í}{{\'I}}1
    {Ň}{{\v{N}}}1
    {Ó}{{\'O}}1
    {Ř}{{\v{R}}}1
    {Š}{{\v{S}}}1
    {Ť}{{\v{T}}}1
    {Ú}{{\'U}}1
    {Ů}{{\r{U}}}1
    {Ý}{{\'Y}}1
    {Ž}{{\v{Z}}}1
}
1
  • 1
    Thank you! :) Please note that I had to remove the inputencoding=utf8, and extendedchars=true, lines and also the % after literate= for it to work in my case.
    – zbr
    May 4, 2016 at 11:43
13

My contribution for brazilian portuguese.

\lstset{%
        inputencoding=utf8,
        extendedchars=true,
        literate=%
        {é}{{\'{e}}}1
        {è}{{\`{e}}}1
        {ê}{{\^{e}}}1
        {ë}{{\¨{e}}}1
        {É}{{\'{E}}}1
        {Ê}{{\^{E}}}1
        {û}{{\^{u}}}1
        {ù}{{\`{u}}}1
        {ú}{{\'{u}}}1
        {â}{{\^{a}}}1
        {à}{{\`{a}}}1
        {á}{{\'{a}}}1
        {ã}{{\~{a}}}1
        {Á}{{\'{A}}}1
        {Â}{{\^{A}}}1
        {Ã}{{\~{A}}}1
        {ç}{{\c{c}}}1
        {Ç}{{\c{C}}}1
        {õ}{{\~{o}}}1
        {ó}{{\'{o}}}1
        {ô}{{\^{o}}}1
        {Õ}{{\~{O}}}1
        {Ó}{{\'{O}}}1
        {Ô}{{\^{O}}}1
        {î}{{\^{i}}}1
        {Î}{{\^{I}}}1
        {í}{{\'{i}}}1
        {Í}{{\~{Í}}}1
}
0
11

ok, found kinda workaround now:

  1. instead of listings package, use listingsutf8

    \usepackage{listingsutf8}

  2. copy listings.sty to the folder the document resides

  3. find the following lines

    \lst@CCPutMacro
        \lst@ProcessOther {"23}\#
        \lst@ProcessLetter{"24}\textdollar
        \lst@ProcessOther {"25}\%
        \lst@ProcessOther {"26}\&
  4. Enter there the following lines (each "registers" one umlaut)

    \lst@ProcessLetter{"E4}{\"a}
    \lst@ProcessLetter{"F6}{\"o}
    \lst@ProcessLetter{"FC}{\"u}
    \lst@ProcessLetter{"C4}{\"A}
    \lst@ProcessLetter{"D6}{\"O}
    \lst@ProcessLetter{"DC}{\"U}
    \lst@ProcessLetter{"DF}{\ss{}}
  5. Save the file

  6. Use

    \lstset{
        extendedchars=\true,
        inputencoding=utf8/latin1
    }

to enable utf8 character to latin1 character mapping

  1. Convert line endings of your source file from windows (\r\n) to unix (\n)
  2. enjoy

I know this is ugly in many way, but its the only solution that works for me so far.

2
  • I think, 'extendedchars=\true' is equal to 'extendedchars=false'.
    – Vanuan
    Sep 29, 2009 at 19:53
  • I copied listings.sty to listingsutf8.sty in /usr/share/texmf-texlive/tex/latex/listings/ on Ubuntu 10.10. I edited the file, but my listings don't work. Mar 20, 2011 at 21:42
4

Works for most iso-characters. (including swedish åäöÅÄÖ which is what I needed)

\usepackage[utf8]{inputenc}
\usepackage{listings}
\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
  {ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1
  {€}{{\EUR}}1 {£}{{\pounds}}1
}

source: http://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings#Encoding_issue

3

Simpler approach for french.

\documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage[francais]{babel}
    \usepackage[T1]{fontenc}
    \usepackage{listings}
    \lstloadlanguages{R}
    \lstset{language=R}
    \lstset{%
        inputencoding=utf8,
            extendedchars=true,
            literate=%
            {é}{{\'{e}}}1
            {è}{{\`{e}}}1
            {ê}{{\^{e}}}1
            {ë}{{\¨{e}}}1
            {û}{{\^{u}}}1
            {ù}{{\`{u}}}1
            {â}{{\^{a}}}1
            {à}{{\`{a}}}1
            {î}{{\^{i}}}1
            {ô}{{\^{o}}}1
            {ç}{{\c{c}}}1
            {Ç}{{\c{C}}}1
            {É}{{\'{E}}}1
            {Ê}{{\^{E}}}1
            {À}{{\`{A}}}1
            {Â}{{\^{A}}}1
            {Î}{{\^{I}}}1
    }

    \begin{document}
    \begin{lstlisting}
    # Est-ce que ça marche : é ê è à Â Ê É Î ç Ç
    x<-rnorm(100,0,10)
    plot(density(x))
    \end{lstlisting}
    \end{document}
2

Works fine for me!

My 2 cents for the French side:

\lst@ProcessOther {"C0}{\`{A}}
\lst@ProcessOther {"C1}{\'{A}}
\lst@ProcessOther {"C2}{\^{A}}
\lst@ProcessOther {"C4}{\"{A}}
\lst@ProcessOther {"C7}{\c{C}}
\lst@ProcessOther {"C8}{\`{E}}
\lst@ProcessOther {"C9}{\'{E}}
\lst@ProcessOther {"CA}{\^{E}}
\lst@ProcessOther {"CB}{\"{E}}
\lst@ProcessOther {"CE}{\^{I}}
\lst@ProcessOther {"CF}{\"{I}}
\lst@ProcessOther {"D4}{\^{O}}
\lst@ProcessOther {"D6}{\"{O}}
\lst@ProcessOther {"D9}{\`{U}}
\lst@ProcessOther {"DB}{\^{U}}
\lst@ProcessOther {"E0}{\`{a}}
\lst@ProcessOther {"E1}{\'{a}}
\lst@ProcessOther {"E2}{\^{a}}
\lst@ProcessOther {"E4}{\"{a}}
\lst@ProcessOther {"E7}{\c{c}}
\lst@ProcessOther {"E8}{\`{e}}
\lst@ProcessOther {"E9}{\'{e}}
\lst@ProcessOther {"EA}{\^{e}}
\lst@ProcessOther {"EB}{\"{e}}
\lst@ProcessOther {"EE}{\^{\i}}
\lst@ProcessOther {"EF}{\"{\i}}
\lst@ProcessOther {"F4}{\^{o}}
\lst@ProcessOther {"F6}{\"{o}}
\lst@ProcessOther {"F9}{\`{u}}
\lst@ProcessOther {"FB}{\^{u}}
2

Similarly to posts before (yaxz and others) I defined macros for Croatian:

% on top
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[croatian]{babel}

% add listings package
\usepackage{listings}

% set font translations
\lstset{inputencoding=utf8}
\lstset{extendedchars=true}
\lstset{
    literate=%
    {ć}{{\'c}}1
    {č}{{\v{c}}}1
    {đ}{{\dj{}}}1
    {š}{{\v{s}}}1
    {ž}{{\v{z}}}1
    {Ć}{{\'C}}1
    {Č}{{\v{C}}}1
    {Đ}{{\DJ{}}}1
    {Š}{{\v{S}}}1
    {Ž}{{\v{Z}}}1
}

I still have "little" problem with adding keyword "inače". Following won't work for "inače":

\lstset{morekeywords={ponavljaj, ako, inače, dok}}

Keyword "inače" (that appear in code) is not recognized as keyword. Any ideas?

Hope this will help someone (besides me :)).

1
  • I have the same problem, I want to have a keyword with accents. Did any one did it? Jul 5, 2013 at 12:53
2

The Swedish version:

\lstset{literate=%
{å}{{\r{a}}}1
{ä}{{\"a}}1
{ö}{{\"o}}1
{Å}{{\r{A}}}1
{Ä}{{\"A}}1
{Ö}{{\"O}}1
}
2

My contribution for Lithuanian language:

\lstset{%
    literate=%
     {ą}{{\k{a}}}1
     {č}{{\v{c}}}1
     {ę}{{\k{e}}}1
     {ė}{{\.{e}}}1
     {į}{{\k{i}}}1
     {š}{{\v{s}}}1
     {ų}{{\k{u}}}1
     {ū}{{\={u}}}1
     {ž}{{\v{z}}}1
     {Ą}{{\k{A}}}1
     {Č}{{\v{C}}}1
     {Ę}{{\k{E}}}1
     {Ė}{{\.{E}}}1
     {Į}{{\k{I}}}1
     {Š}{{\v{S}}}1
     {Ų}{{\k{U}}}1
     {Ū}{{\={U}}}1
     {Ž}{{\v{Z}}}1
}
2

For Polish:

\lstset{%
literate=%
 {ą}{{\k{a}}}1
 {ę}{{\k{e}}}1
 {Ą}{{\k{A}}}1
 {Ę}{{\k{E}}}1
 {ś}{{\'{s}}}1
 {Ś}{{\'{S}}}1
 {ź}{{\'{z}}}1
 {Ź}{{\'{Z}}}1
 {ń}{{\'{n}}}1
 {Ń}{{\'{N}}}1
 {ć}{{\'{c}}}1
 {Ć}{{\'{C}}}1
 {ó}{{\'{o}}}1
 {Ó}{{\'{O}}}1
 {ż}{{\.{z}}}1
 {Ż}{{\.{Z}}}1
 {ł}{{\l{}}}1
 {Ł}{{\l{}}}1
}

And here's list of symbols so you can create it for your language: https://en.wikibooks.org/wiki/LaTeX/Special_Characters

1

I can confirm that solution provided by Janosch works almost correctly.

In my case I needed to use Spanish characters: á,é,í,ó,ú,ñ,Á,É,Í,Ó,Ú and tried his solution without results until I compiled my file with xelatex instead of pdflatex.

Anyway you should modify listings.sty either in your local copy or directly in the common file and add the following:

\lst@CCPutMacro
    \lst@ProcessOther {"23}\#
    \lst@ProcessLetter{"24}\textdollar
    \lst@ProcessOther {"25}\%
    \lst@ProcessOther {"26}\&
        %spanish letters coded in UTF
    \lst@ProcessOther {"E1}{\'a}
    \lst@ProcessOther {"C1}{\'A}
    \lst@ProcessOther {"E9}{\'e}
    \lst@ProcessOther {"C9}{\'E}
    \lst@ProcessOther {"ED}{\'i}
    \lst@ProcessOther {"CD}{\'I}
    \lst@ProcessOther {"F3}{\'o}
    \lst@ProcessOther {"D3}{\'O}
    \lst@ProcessOther {"FA}{\'u}
    \lst@ProcessOther {"DA}{\'U}
    \lst@ProcessOther {"F1}{ñ}
    \lst@ProcessOther {"D1}{Ñ}

In my .tex file I used the following options for listings:

\usepackage{listingsutf8}
\lstset{
        inputencoding=utf8,
        extendedchars=\true}

Hope it can help anybody and maybe we can construct a listing.sty containing almost every UTF8 char... :)

1

We all know how LaTeX doesn’t play nice with Greek. Nevertheless, here’s my contribution, which requires several workarounds, and doesn’t include diacritics (but works!):

\usepackage[greek]{babel}
\usepackage{textgreek}
\usepackage{listings}

% Notice that here it is spelled ‘omikron’, not ‘omicron’,
% and that I use ‘\textmugreek’ instead of ‘\textmu’,
% which are both part of the textgreek package, but the
% ‘normal’ \textmu conflicts with the textcomp package as
% that uses another font for \textmu.
\DeclareUnicodeCharacter{03BF}{\textomikron}
\DeclareUnicodeCharacter{039F}{\textOmikron}
\DeclareUnicodeCharacter{03BC}{\textmugreek}

\lstset{
    inputencoding=utf8,
    extendedchars=true,
    literate=
    {α}{{\textalpha}}1   {Α}{{\textAlpha}}1
    {β}{{\textbeta}}1    {Β}{{\textBeta}}1
    {γ}{{\textgamma}}1   {Γ}{{\textGamma}}1
    {δ}{{\textdelta}}1   {Δ}{{\textDelta}}1
    {ε}{{\textepsilon}}1 {Ε}{{\textEpsilon}}1
    {ζ}{{\textzeta}}1    {Ζ}{{\textZeta}}1
    {η}{{\texteta}}1     {Η}{{\textEta}}1
    {θ}{{\texttheta}}1   {Θ}{{\textTheta}}1
    {ι}{{\textiota}}1    {Ι}{{\textIota}}1
    {κ}{{\textkappa}}1   {Κ}{{\textKappa}}1
    {λ}{{\textlambda}}1  {Λ}{{\textLambda}}1
    {μ}{{\textmugreek}}1 {Μ}{{\textMu}}1
    {ν}{{\textnu}}1      {Ν}{{\textNu}}1
    {ξ}{{\textxi}}1      {Ξ}{{\textXi}}1
    {ο}{{\textomikron}}1 {Ο}{{\textOmikron}}1
    {π}{{\textpi}}1      {Π}{{\textPi}}1
    {ρ}{{\textrho}}1     {Ρ}{{\textRho}}1
    {σ}{{\textsigma}}1   {Σ}{{\textSigma}}1   {ς}{{\textvarsigma}}1
    {τ}{{\texttau}}1     {Τ}{{\textTau}}1
    {υ}{{\textupsilon}}1 {Υ}{{\textUpsilon}}1
    {φ}{{\textphi}}1     {Φ}{{\textPhi}}1
    {χ}{{\textchi}}1     {Χ}{{\textChi}}1
    {ψ}{{\textpsi}}1     {Ψ}{{\textPsi}}1
    {ω}{{\textomega}}1   {Ω}{{\textOmega}}1
}
1

My contribution for spanish language.

Tested, it works great, both importing files with the code with spanish characters, and pasting snippets of code directly in the latex document.

\usepackage[spanish, activeacute]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{listings}

\lstset{literate=%
    {ñ}{{\~n}}1
    {Ñ}{{\~N}}1
    {á}{{\'a}}1
    {é}{{\'e}}1
    {í}{{\'i}}1
    {ó}{{\'o}}1
    {ú}{{\'u}}1
    {Á}{{\'A}}1
    {É}{{\'E}}1
    {Í}{{\'I}}1
    {Ó}{{\'O}}1
    {Ú}{{\'U}}1
}
0

Author of package suggests using texcl option. Sometimes it helps, sometimes doesn't.

0

Simply don't use UTF-8 in LaTex if you want to use any listings packages. Using latin1 in your documents will display German Umlauts just fine.

I'm writing my thesis in German using this setup:

% Your language, here German
\usepackage[ngerman]{babel} 
% Will work with Umlauts
\usepackage[latin1]{inputenc}
% Euro characters etc.
\usepackage{textcomp}
% Works perfectly with latin1
\usepackage{listings}
0

The cleanest solution for this is to use the listings2 package: http://www.atscire.de/index.php?nav=products/listings2

Simply use \usepackage{listings2} instead of \usepackage{listings} and that's it.

0

Norwegian letters for listings.sty in @Janosch's solution:

\lst@ProcessLetter{"C5}{\AA}
\lst@ProcessLetter{"C6}{\AE}
\lst@ProcessLetter{"D8}{\O}
\lst@ProcessLetter{"E5}{\aa}
\lst@ProcessLetter{"E6}{\ae}
\lst@ProcessLetter{"F8}{\o}
0

For Vietnamese:

\usepackage{vntex}
\usepackage[utf8]{inputenc}
\usepackage{listings}  
\usepackage{tipa}

\lstset{columns=fullflexible,literate=
{đ}{{\dj}}1
{â}{{\^a}}1
{ă}{{\u{a}}}1
{ê}{{\^e}}1
{ô}{{\^o}}1
{ơ}{{\ohorn}}1
{ư}{{\uhorn}}1
{á}{{\'a}}1
{à}{{\`a}}1
{ả}{\h{a}}1
{ã}{{\~a}}1
{ạ}{\textsubdot{a}}1
{ấ}{\'{\^a}}1
{ầ}{\`{\^a}}1
{ẩ}{\h{\^a}}1
{ẫ}{\~{\^a}}1
{ậ}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{É}{{\'E}}1
    {é}{{\'e}}1
    {í}{{\'i}}1
    {Í}{{\'I}}1
    {Ó}{{\'O}}1
    {ó}{{\'o}}1
    {Ú}{{\'U}}1
    {ú}{{\'u}}1
    {Ý}{{\'Y}}1
    {ý}{{\'y}}1
    {Þ}{{\TH}}1
    {þ}{{\th}}1
    {Æ}{{\AE}}1
    {æ}{{\ae}}1
    {Ö}{{\"O}}1
    {ö}{{\"o}}1
}
0

My contribution for Slovak language.

\lstset{
  extendedchars=true,
  literate=
    {á}{{\'a}}1
    {ä}{{\"a}}1
    {č}{{\v{c}}}1
    {ď}{{\v{d}}}1
    {é}{{\'e}}1
    {í}{{\'i}}1
    {ĺ}{{\'l}}1
    {ľ}{{\v{l}}}1
    {ň}{{\v{n}}}1
    {ó}{{\'o}}1
    {ô}{{\^o}}1
    {ŕ}{{\'{r}}}1
    {š}{{\v{s}}}1
    {ť}{{\v{t}}}1
    {ú}{{\'u}}1
    {ý}{{\'y}}1
    {ž}{{\v{z}}}1
    {Á}{{\'A}}1
    {Ä}{{\""A}}1
    {Č}{{\v{C}}}1
    {Ď}{{\v{C}}}1
    {É}{{\'E}}1
    {Í}{{\'I}}1
    {Ĺ}{{\'L}}1
    {Ľ}{{\v{L}}}1
    {Ň}{{\v{N}}}1
    {Ó}{{\'O}}1
    {Ô}{{\^O}}1
    {Ŕ}{{\'{R}}}1
    {Š}{{\v{S}}}1
    {Ť}{{\v{T}}}1
    {Ú}{{\'U}}1
    {Ý}{{\'Y}}1
    {Ž}{{\v{Z}}}1
}
-1

To add copyright support to listings, add this:

\lstset{
    %you may add line below to existed config
    literate={©}{{\copyright}}{4}
}
0
-2

You might need to set the document's input encoding to also be UTF-8. There's a comp.text.tex thread discussing how to do this. The following accomplishes this in TeXLive on GNU/Linux:

\usepackage[utf8]{inputenc}
2
  • My main document is in utf8. (and it works, i can even write äöü in the main document)
    – Janosch
    Jul 12, 2009 at 20:21
  • 1
    listings does its character processing differently than the main document. So inputenc doesn't help, here; the listings packages needs to support utf8 input explicitly (hence listingsutf8). Jul 16, 2009 at 1:31

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.