![西里尔字母列表中的空格](https://linux22.com/image/264888/%E8%A5%BF%E9%87%8C%E5%B0%94%E5%AD%97%E6%AF%8D%E5%88%97%E8%A1%A8%E4%B8%AD%E7%9A%84%E7%A9%BA%E6%A0%BC.png)
我想使用 listing 包包含源文件。该文件中的注释中有一些西里尔符号。
我设置了如下列表:
\lstset{extendedchars=\true,basicstyle=\ttfamily}
结果是,俄语单词之间没有空格:вд
而不是所需的в д
。
不起作用的最小样本:
\documentclass[a4paper]{article}
\usepackage{xltxtra}
\usepackage{xunicode}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{listings}
\lstset{extendedchars=\true,basicstyle=\ttfamily}
\setmonofont[Scale=0.8]{DejaVu Sans Mono}
\begin{document}
\begin{lstlisting}
привет мир
\end{lstlisting}
\end{document}
我正在使用 XeTeX。
@Micha 如果我尝试使用libertine
xetex 包,我会收到如下错误:
Cannot use \XeTeXOTfeaturetag with nullfont; not an OpenType Layout font. [ ]{Linux Libertine O}]
我也尝试使用 literate 设置在 pdflatex 中运行,成功了,谢谢。但在 xetex 中我遇到了同样的问题。
是否可以通过 xetex 以这种方式使用列表?
答案1
现在我明白了这个问题。这与字体无关,这是我第一次提到。这个问题在Роман Химов » листингах LaTeX 中的语法 但我无法使用 xelatex 做到这一点。以下 MWE 可以与 pdflatex 配合使用
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage[T2A]{fontenc}
\usepackage{listings}
\lstset{extendedchars=true,basicstyle=\ttfamily,literate={Ö}{{\"O}}1
{Ä}{{\"A}}1
{Ü}{{\"U}}1
{ß}{{\ss}}1
{ü}{{\"u}}1
{ä}{{\"a}}1
{ö}{{\"o}}1
{~}{{\textasciitilde}}1
{а}{{\selectfont\char224}}1
{б}{{\selectfont\char225}}1
{в}{{\selectfont\char226}}1
{г}{{\selectfont\char227}}1
{д}{{\selectfont\char228}}1
{е}{{\selectfont\char229}}1
{ё}{{\"e}}1
{ж}{{\selectfont\char230}}1
{з}{{\selectfont\char231}}1
{и}{{\selectfont\char232}}1
{й}{{\selectfont\char233}}1
{к}{{\selectfont\char234}}1
{л}{{\selectfont\char235}}1
{м}{{\selectfont\char236}}1
{н}{{\selectfont\char237}}1
{о}{{\selectfont\char238}}1
{п}{{\selectfont\char239}}1
{р}{{\selectfont\char240}}1
{с}{{\selectfont\char241}}1
{т}{{\selectfont\char242}}1
{у}{{\selectfont\char243}}1
{ф}{{\selectfont\char244}}1
{х}{{\selectfont\char245}}1
{ц}{{\selectfont\char246}}1
{ч}{{\selectfont\char247}}1
{ш}{{\selectfont\char248}}1
{щ}{{\selectfont\char249}}1
{ъ}{{\selectfont\char250}}1
{ы}{{\selectfont\char251}}1
{ь}{{\selectfont\char252}}1
{э}{{\selectfont\char253}}1
{ю}{{\selectfont\char254}}1
{я}{{\selectfont\char255}}1
{А}{{\selectfont\char192}}1
{Б}{{\selectfont\char193}}1
{В}{{\selectfont\char194}}1
{Г}{{\selectfont\char195}}1
{Д}{{\selectfont\char196}}1
{Е}{{\selectfont\char197}}1
{Ё}{{\"E}}1
{Ж}{{\selectfont\char198}}1
{З}{{\selectfont\char199}}1
{И}{{\selectfont\char200}}1
{Й}{{\selectfont\char201}}1
{К}{{\selectfont\char202}}1
{Л}{{\selectfont\char203}}1
{М}{{\selectfont\char204}}1
{Н}{{\selectfont\char205}}1
{О}{{\selectfont\char206}}1
{П}{{\selectfont\char207}}1
{Р}{{\selectfont\char208}}1
{С}{{\selectfont\char209}}1
{Т}{{\selectfont\char210}}1
{У}{{\selectfont\char211}}1
{Ф}{{\selectfont\char212}}1
{Х}{{\selectfont\char213}}1
{Ц}{{\selectfont\char214}}1
{Ч}{{\selectfont\char215}}1
{Ш}{{\selectfont\char216}}1
{Щ}{{\selectfont\char217}}1
{Ъ}{{\selectfont\char218}}1
{Ы}{{\selectfont\char219}}1
{Ь}{{\selectfont\char220}}1
{Э}{{\selectfont\char221}}1
{Ю}{{\selectfont\char222}}1
{Я}{{\selectfont\char223}}1
}
\begin{document}
\begin{lstlisting}
(ä ö ü) (a b c) (а б в)
\end{lstlisting}
\end{document}
答案2
我没有CMU 衬线体字体,但它不应该与列表相关。使用:
\usepackage{libertine}
\setmainfont[Mapping=tex-text]{CMU Serif}
文档看起来不错。(TeX-Live 2012 )