\tableofcontents 与 lualatex 的编码问题

\tableofcontents 与 lualatex 的编码问题

我在尝试使用俄语版 lualatex 生成目录时遇到问题。以下示例无法构建代表! Undefined control sequence. \contentsname ->{\cyr \CYRS \cyro \cyrd \cyre \cyrr \cyrzh \cyra \cyrn \cyri...“Содержание”(俄语中的“内容”)

\documentclass{article}

\usepackage{fontspec}
\usepackage{xunicode}
\setmainfont[Ligatures=TeX]{DejaVu Serif}
\usepackage[russian]{babel}

\begin{document}
\tableofcontents
\clearpage
\section{тест 1}
\section{тест 2}
\section{тест 3}
\end{document}

当我加载英文版的 babel 时一切正常,除了目录标题为英文“Contents”。有没有办法在 lualatex 中正确指定 babel 的编码?

答案1

以下内容涵盖俄语字母:

\documentclass{article}
\usepackage[russian]{babel}

\DeclareTextCommand{\CYRA}{EU2}{А}
\DeclareTextCommand{\cyra}{EU2}{а}
\DeclareTextCommand{\CYRB}{EU2}{Б}
\DeclareTextCommand{\cyrb}{EU2}{б}
\DeclareTextCommand{\CYRV}{EU2}{В}
\DeclareTextCommand{\cyrv}{EU2}{в}
\DeclareTextCommand{\CYRG}{EU2}{Г}
\DeclareTextCommand{\cyrg}{EU2}{г}
\DeclareTextCommand{\CYRD}{EU2}{Д}
\DeclareTextCommand{\cyrd}{EU2}{д}
\DeclareTextCommand{\CYRE}{EU2}{Е}
\DeclareTextCommand{\cyre}{EU2}{е}
\DeclareTextCommand{\CYRYO}{EU2}{Ё}
\DeclareTextCommand{\cyryo}{EU2}{ё}
\DeclareTextCommand{\CYRZH}{EU2}{Ж}
\DeclareTextCommand{\cyrzh}{EU2}{ж}
\DeclareTextCommand{\CYRZ}{EU2}{З}
\DeclareTextCommand{\cyrz}{EU2}{з}
\DeclareTextCommand{\CYRI}{EU2}{И}
\DeclareTextCommand{\cyri}{EU2}{и}
\DeclareTextCommand{\CYRISHRT}{EU2}{Й}
\DeclareTextCommand{\cyrishrt}{EU2}{й}
\DeclareTextCommand{\CYRK}{EU2}{К}
\DeclareTextCommand{\cyrk}{EU2}{к}
\DeclareTextCommand{\CYRL}{EU2}{Л}
\DeclareTextCommand{\cyrl}{EU2}{л}
\DeclareTextCommand{\CYRM}{EU2}{М}
\DeclareTextCommand{\cyrm}{EU2}{м}
\DeclareTextCommand{\CYRN}{EU2}{Н}
\DeclareTextCommand{\cyrn}{EU2}{н}
\DeclareTextCommand{\CYRO}{EU2}{О}
\DeclareTextCommand{\cyro}{EU2}{о}
\DeclareTextCommand{\CYRP}{EU2}{П}
\DeclareTextCommand{\cyrp}{EU2}{п}
\DeclareTextCommand{\CYRR}{EU2}{Р}
\DeclareTextCommand{\cyrr}{EU2}{р}
\DeclareTextCommand{\CYRS}{EU2}{С}
\DeclareTextCommand{\cyrs}{EU2}{с}
\DeclareTextCommand{\CYRT}{EU2}{Т}
\DeclareTextCommand{\cyrt}{EU2}{т}
\DeclareTextCommand{\CYRU}{EU2}{У}
\DeclareTextCommand{\cyru}{EU2}{у}
\DeclareTextCommand{\CYRF}{EU2}{Ф}
\DeclareTextCommand{\cyrf}{EU2}{ф}
\DeclareTextCommand{\CYRH}{EU2}{Х}
\DeclareTextCommand{\cyrh}{EU2}{х}
\DeclareTextCommand{\CYRC}{EU2}{Ц}
\DeclareTextCommand{\cyrc}{EU2}{ц}
\DeclareTextCommand{\CYRCH}{EU2}{Ч}
\DeclareTextCommand{\cyrch}{EU2}{ч}
\DeclareTextCommand{\CYRSH}{EU2}{Ш}
\DeclareTextCommand{\cyrsh}{EU2}{ш}
\DeclareTextCommand{\CYRSHCH}{EU2}{Щ}
\DeclareTextCommand{\cyrshch}{EU2}{щ}
\DeclareTextCommand{\CYRHRDSN}{EU2}{Ъ}
\DeclareTextCommand{\cyrhrdsn}{EU2}{ъ}
\DeclareTextCommand{\CYRERY}{EU2}{Ы}
\DeclareTextCommand{\cyrery}{EU2}{ы}
\DeclareTextCommand{\CYRSFTSN}{EU2}{Ь}
\DeclareTextCommand{\cyrsftsn}{EU2}{ь}
\DeclareTextCommand{\CYREREV}{EU2}{Э}
\DeclareTextCommand{\cyrerev}{EU2}{э}
\DeclareTextCommand{\CYRYU}{EU2}{Ю}
\DeclareTextCommand{\cyryu}{EU2}{ю}
\DeclareTextCommand{\CYRYA}{EU2}{Я}
\DeclareTextCommand{\cyrya}{EU2}{я}


\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{DejaVu Serif}

\begin{document}
\tableofcontents
\clearpage
\section{тест 1}
\section{тест 2}
\section{тест 3}
\end{document}

可以使用 David Carlisle 编写的代码来获得获取(几乎)所有已知西里尔字符的更抽象的方法(参见https://tex.stackexchange.com/a/110016/4427

\documentclass{article}

\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{DejaVu Serif}

% This code must go after xunicode is loaded (by fontspec),
% but before babel.
\makeatletter
\let\KeptDeclareUnicodeCharacter\DeclareUnicodeCharacter
\def\DeclareUnicodeCharacter#1#2{\@declare{#1}#2!!}%
\def\@declare#1#2#3!!{%
  \ifdefined#2\else
    \begingroup
    \lccode`E=`E \lccode`U=`U
    \lccode`A="#1\relax
    \lowercase{\endgroup\DeclareTextCommand{#2}{EU2}{A}}%
\typeout{Redefined \string#2}
  \fi}
\input{x2enc.dfu}% this contains all the cyrillic characters
\let\DeclareUnicodeCharacter\KeptDeclareUnicodeCharacter
\let\KeptDeclareUnicodeCharacter\@undefined
\let\@declare\@undefined
\makeatother

\usepackage[russian]{babel}

\begin{document}
\tableofcontents
\clearpage
\section{тест 1}
\section{тест 2}
\section{тест 3}
\end{document}

另一种方法可能是重新定义\captionsrussian和其他相关命令(取自gloss-russian.ldfpolyglossia)

\def\captionsrussian{%
   \def\prefacename{Предисловие}%
   \def\refname{Список литературы}%
   \def\abstractname{Аннотация}%
   \def\bibname{Литература}%
   \def\chaptername{Глава}%
   \def\appendixname{Приложение}%
   \ifdefined\thechapter
     \def\contentsname{Оглавление}%
   \else
     \def\contentsname{Содержание}%
   \fi
   \def\listfigurename{Список иллюстраций}%
   \def\listtablename{Список таблиц}%
   \def\indexname{Предметный указатель}%
   \def\authorname{Именной указатель}%
   \def\figurename{Рис.}%
   \def\tablename{Таблица}%
   \def\partname{Часть}%
   \def\enclname{вкл.}%
   \def\ccname{исх.}%
   \def\headtoname{вх.}%
   \def\pagename{с.}%
   \def\seename{см.}%
   \def\alsoname{см.~также}%
   \def\proofname{Доказательство}%
}
\def\daterussian{%
  \def\today{\number\day%
  \space\ifcase\month\or%
  января\or
  февраля\or
  марта\or
  апреля\or
  мая\or
  июня\or
  июля\or
  августа\or
  сентября\or
  октября\or
  ноября\or
  декабря\fi%
  \space \number\year\space г.}}
\makeatletter
\def\@Asbuk#1{\ifcase#1\or
   А\or Б\or В\or Г\or Д\or Е\or Ж\or
   З\or И\or К\or Л\or М\or Н\or О\or
   П\or Р\or С\or Т\or У\or Ф\or Х\or
   Ц\or Ч\or Ш\or Щ\or Э\or Ю\or Я\else\@ctrerr\fi}
\def\@asbuk#1{\ifcase#1\or
   а\or б\or в\or г\or д\or е\or ж\or
   з\or и\or к\or л\or м\or н\or о\or
   п\or р\or с\or т\or у\or ф\or х\or
   ц\or ч\or ш\or щ\or э\or ю\or я\else\@ctrerr\fi}
\makeatother

2013 年 4 月添加:即将推出的 3.9 版babel应该会通过检查排版引擎是否原生理解 Unicode 并相应地设置固定单词来解决这个问题。此版本的babel已经在 CTAN 上,但尚未在 TeX Live 中找到自己的出路。很快就会找到。

答案2

遗憾的是 polyglossia 仍未适用于 lualatex。它使用 xetex 特定命令,而 lualatex 不存在与之对应的命令。但据我所知 gloss-russian.ldf 不需要它们,因此您可以尝试以下操作:

\documentclass[a4paper]{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{DejaVu Serif}
\def\newXeTeXintercharclass#1{} %hack to fool polyglossia
\usepackage{polyglossia}
\setmainlanguage{russian}
\begin{document}

abc
\end{document}

注意力!如果您加载法语等多语种语言,而该语言确实需要此\XeTeXintercharclass功能,则可能会出现严重问题。在这种情况下,egreg 的解决方法更好。

答案3

目前还没有 (完全)babel或 (任何)polyglossia对 lualatex 的支持。因此,除非您需要特定的附加功能(例如直接 lua 代码),否则您应该polyglossia暂时使用 xelatex + 或使用 Ulrike 和 egreg 发布的解决方案。

答案4

尝试使用[russian]作为参数来\documentclass代替 Babel。至少对我来说,使用 lualatex 0.60 和 texlive 2010(包括所有更新)是可行的。

相关内容