Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Please, do you know if there's any possibility how to use the listings package together with XeLaTeX? I have to use XelaTeX and therefore I have UTF-8 encoded files. This is not compatible with listings which allows one-byte encoding. (I know there is listingsutf8 package, but it converts files from UTF-8 which I don't need.)

The listings package works somehow, bu I only can use English letters. I've fond some solution like a list of special characters ( Having problems with listings and UTF-8. Can it be fixed? ) but it seems it works only for some letters. It there anything that would support UTF-8 in listing 'naturally'?

share|improve this question
    
While not having experience with minted as replacement for listings, several comments I've read indicated that it handles such situations in conjunction with XeLaTeX gracefully. –  eudoxos Aug 10 '11 at 14:42
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Mar 1 at 18:56
    

2 Answers 2

The link you are mentioning is for 8-bit engines like pdflatex, it will not work with xetex or luatex.

With xelatex + lualatex chars with unicode positions below 256 will work out of the box:

\documentclass{article}
\usepackage{listings,fontspec}
\begin{document}
\begin{lstlisting}
öäü é è ß 
\end{lstlisting}
\end{document}

Things get more complicated if you want to use chars above 256. E.g. an € or the french "oe" or greek etc. In this case you will have to add them to the processing list of listings first and use extendedchars=true. Here an example which adds the euro and the french oe and Oe (the middle listings shows the problems without the extended definitions):

\documentclass{article}
\usepackage{fontspec}
\usepackage{listings}

\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
 \lst@CCECUse \lst@ProcessLetter
  ^^80^^81^^82^^83^^84^^85^^86^^87^^88^^89^^8a^^8b^^8c^^8d^^8e^^8f%
  ^^90^^91^^92^^93^^94^^95^^96^^97^^98^^99^^9a^^9b^^9c^^9d^^9e^^9f%
  ^^a0^^a1^^a2^^a3^^a4^^a5^^a6^^a7^^a8^^a9^^aa^^ab^^ac^^ad^^ae^^af%
  ^^b0^^b1^^b2^^b3^^b4^^b5^^b6^^b7^^b8^^b9^^ba^^bb^^bc^^bd^^be^^bf%
  ^^c0^^c1^^c2^^c3^^c4^^c5^^c6^^c7^^c8^^c9^^ca^^cb^^cc^^cd^^ce^^cf%
  ^^d0^^d1^^d2^^d3^^d4^^d5^^d6^^d7^^d8^^d9^^da^^db^^dc^^dd^^de^^df%
  ^^e0^^e1^^e2^^e3^^e4^^e5^^e6^^e7^^e8^^e9^^ea^^eb^^ec^^ed^^ee^^ef%
  ^^f0^^f1^^f2^^f3^^f4^^f5^^f6^^f7^^f8^^f9^^fa^^fb^^fc^^fd^^fe^^ff%
  ^^^^20ac^^^^0153^^^^0152% nouveau pour xetex
  ^^00}
\lst@RestoreCatcodes
\makeatother
\begin{document}
\begin{lstlisting}[extendedchars=true]%default je pense
bœuf BŒeuf a€e
Dès Noël où un zéphyr haï me
vêt de glaçons würmiens je
dîne d'exquis rôtis de bœuf
au kir à l'aÿ d'âge mûr \& cætera!
\end{lstlisting}

\begin{lstlisting}[extendedchars=false]
bœuf BŒeuf a€e
Dès Noël où un zéphyr haï me
vêt de glaçons würmiens je
dîne d'exquis rôtis de bœuf
au kir à l'aÿ d'âge mûr \& cætera!
\end{lstlisting}


\begin{lstlisting}[language=XML]
bœuf BŒeuf a€e
Dès Noël où un zéphyr haï me
vêt de glaçons würmiens je
dîne d'exquis rôtis de bœuf
au kir à l'aÿ d'âge mûr \& cætera!
\end{lstlisting}
\end{document}

Output:

enter image description here

share|improve this answer

Thanks for posting this block of code. The same technique can be used to typeset UTF8 APL characters with APL385 Unicode font. Include the following:

% set lstlisting to accept UTF8 APL text
\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
 \lst@CCECUse \lst@ProcessLetter
  ^^80^^81^^82^^83^^84^^85^^86^^87^^88^^89^^8a^^8b^^8c^^8d^^8e^^8f%
  ^^90^^91^^92^^93^^94^^95^^96^^97^^98^^99^^9a^^9b^^9c^^9d^^9e^^9f%
  ^^a0^^a1^^a2^^a3^^a4^^a5^^a6^^a7^^a8^^a9^^aa^^ab^^ac^^ad^^ae^^af%
  ^^b0^^b1^^b2^^b3^^b4^^b5^^b6^^b7^^b8^^b9^^ba^^bb^^bc^^bd^^be^^bf%
  ^^c0^^c1^^c2^^c3^^c4^^c5^^c6^^c7^^c8^^c9^^ca^^cb^^cc^^cd^^ce^^cf%
  ^^d0^^d1^^d2^^d3^^d4^^d5^^d6^^d7^^d8^^d9^^da^^db^^dc^^dd^^de^^df%
  ^^e0^^e1^^e2^^e3^^e4^^e5^^e6^^e7^^e8^^e9^^ea^^eb^^ec^^ed^^ee^^ef%
  ^^f0^^f1^^f2^^f3^^f4^^f5^^f6^^f7^^f8^^f9^^fa^^fb^^fc^^fd^^fe^^ff%
  ^^^^20ac^^^^0153^^^^0152%
  ^^^^20a7^^^^2190^^^^2191^^^^2192^^^^2193^^^^2206^^^^2207^^^^220a%
  ^^^^2218^^^^2228^^^^2229^^^^222a^^^^2235^^^^223c^^^^2260^^^^2261%
  ^^^^2262^^^^2264^^^^2265^^^^2282^^^^2283^^^^2296^^^^22a2^^^^22a3%
  ^^^^22a4^^^^22a5^^^^22c4^^^^2308^^^^230a^^^^2336^^^^2337^^^^2339%
  ^^^^233b^^^^233d^^^^233f^^^^2340^^^^2342^^^^2347^^^^2348^^^^2349%
  ^^^^234b^^^^234e^^^^2350^^^^2352^^^^2355^^^^2357^^^^2359^^^^235d%
  ^^^^235e^^^^235f^^^^2361^^^^2362^^^^2363^^^^2364^^^^2365^^^^2368%
  ^^^^236a^^^^236b^^^^236c^^^^2371^^^^2372^^^^2373^^^^2374^^^^2375%
  ^^^^2377^^^^2378^^^^237a^^^^2395^^^^25af^^^^25ca^^^^25cb%
  ^^00}
\lst@RestoreCatcodes
\makeatother

More details at: http://bakerjd99.wordpress.com/2011/08/15/typesetting-utf8-apl-code-with-the-latex-lstlisting-package/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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