Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listings in Latex with UTF-8 (or at least german umlauts)

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

like image 882
Janosch Avatar asked Jul 12 '09 15:07

Janosch


People also ask

What is UTF-8 in latex?

UTF-8 is the most widely used character encoding on the web today. You can use it to represent any unicode character, which includes an enormous variety of letters, numbers and symbols, including Greek letters and letters with accents.

Is UTF-8 or UTF-8?

It's definitely UTF-8.

What UTF-8 means?

UTF-8 (UCS Transformation Format 8) is the World Wide Web's most common character encoding. Each character is represented by one to four bytes. UTF-8 is backward-compatible with ASCII and can represent any standard Unicode character.


2 Answers

I found a simpler approach, which works for me:

\usepackage{listings}  \lstset{   literate={ö}{{\"o}}1            {ä}{{\"a}}1            {ü}{{\"u}}1 } 
like image 171
yaxu Avatar answered Sep 17 '22 05:09

yaxu


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} 
like image 25
Seb DA ROCHA Avatar answered Sep 18 '22 05:09

Seb DA ROCHA