我可以确认 Janosch 提供的解决方案几乎可以正常工作。
就我而言,我需要使用西班牙语字符:á,é,í,ó,ú,ñ,Á,É,Í,Ó,Ú 并尝试了他的解决方案但没有结果,直到我用 xelatex 而不是 pdflatex 编译我的文件。
无论如何,您应该在本地副本或直接在公共文件中修改 Listings.sty 并添加以下内容:
\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}{Ñ}
在我的 .tex 文件中,我使用了以下列表选项:
\usepackage{listingsutf8}
\lstset{
inputencoding=utf8,
extendedchars=\true}
希望它可以帮助任何人,也许我们可以构建一个包含几乎每个 UTF8 字符的listing.sty ... :)