1

In UTF-8 it should be possible to use ä and ö.

But actually in my code listing I use the package listings I receive by this example

\lstset{language=HTML}
 % Set your language (you can change the language for each code-block optionally)
\begin{lstlisting}[caption=Socket Connection, frame=single]  % Start your code-block

// einbinden der Library mittels CommonJs var net = require('net');

// Socket Client erstellen var client = new net.Socket();

// mit dem Server verbinden IP Port angeben client.connect(<PORT>, '<IP>', function() { console.log('Connected'); client.write('Hello, server! Love, Client.'); });

// verschiedene Events Listener // dieser wird ausgelöst s der Server Daten zum Client sendet client.on('data', function(data) { console.log('Received: ' + data); client.destroy(); // kill client after server's response });

client.on('close', function() { console.log('Connection closed'); });

\end{lstlisting}

the error message

! Package inputenc Error: Invalid UTF-8 byte sequence.

And it is denoting to the line with the 'ö' // dieser wird ausgelöst s der Server Daten zum Client sendet

Note: Sure I know it isn't HTML but when I say JavaScript it doesn't work

In the preamble I say

\usepackage[utf8]{inputenc} % Unicode Text 
Ingmar
  • 6,690
  • 5
  • 26
  • 47
  • 1
    (1) please always provide a full example that others can copy and test as is. (2) listings does not really support UTF8 out of the box due to the way listings processes the contents. Which is why I gennerally advise our (Danish) students to always comment in English. You can use literate to add non-ascii to listings parsing, see also https://tex.stackexchange.com/a/411536/3929 – daleif Mar 12 '21 at 08:27
  • Do umlauts work in the rest of your document? Perhaps this answer helps: https://tex.stackexchange.com/questions/378600/unicode-characters-in-lstlisting But really, no way to tell without seeing your document. – Ingmar Mar 12 '21 at 08:32
  • 5
    Does this answer your question? Having problems with listings and UTF-8. Can it be fixed? (I have posted an answer there with most European characters taken care of) – Rmano Mar 12 '21 at 08:37
  • 1
    As also mentioned in some of the linked to questions, it can help switching to xelatex or lualatex that understands UTF8 natively – daleif Mar 12 '21 at 08:50
  • @Rmano yes it answers my question, thanks a lot :) – Aalexander Mar 13 '21 at 08:32

0 Answers0