[XeTeX] Weird character swap when using xelatex+fontspec+listings

Ulrike Fischer news3 at nililand.de
Tue Jun 1 09:51:39 CEST 2010

Am Sun, 30 May 2010 16:30:07 -0400 schrieb Alan Munn:

>> When I compile the attached t.tex with xelatex I get the attached
>> t.pdf, in which the big pi has somehow switched positions with
>> 'a'. What's going on here? :)

> This is a problem with the listings package, which is incompatible  
> with UTF-8 encoded files.

Well with xetex listings is more compatible with utf8 than with
standard 8-bit-pdftex, as now it no longer has the problem that a
character is split at the input in 8-bit-pieces. Non-ASCII-chars
like ä, ö, ü works (even without the extendedchars option) without

The problem here is that listings makes the necessary definitions
only for character up to position 255. 

But adding the code for a new one is quite easy (I used the euro,
which has the same problem than the greek, but is easier to handle
for me). The commented part shows how to replace an input by
arbitrary text:

\lst at CCPut \lst at ProcessLetter {"20AC}\z@

%\lst at CCPutMacro
%    \lst at ProcessOther {"20AC}{EURO}
%    \@empty\z@\@empty


x \lstinline|a€b| y

I don't think that it is a good idea to add all unicode chars as
default, compilation would need much more time if all chars had to
been reset before and after each listings, but some user commands
which allows to extend the possible input for listings would be a
good idea. 

Ulrike Fischer 

More information about the XeTeX mailing list