我正在尝试申请这很棒的模板。我使用 XeTeX 和俄语——它给出:
! Missing \endcsname inserted.
<to be read again>
\csname\endcsname
l.5 ...ter}{Предисловие}{i}{chapter*.1}
以下是 MWE 的内容:
\RequirePackage[l2tabu,orthodox]{nag} % checks for some discouraged practice
\documentclass[a5paper, oneside]{book}
\usepackage{xltxtra}
% Customizing the page:
\usepackage[top=1.2cm, bottom=1.8cm, left=1.5cm, right=1.7cm]{geometry} % required by MISiS PH
% XeTeX technologies:
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{xecyr}
% fonts:
\setmainfont[Mapping=tex-text]{Arial}
\setsansfont{Arial}
\setromanfont{Arial}
\setmonofont{DejaVu Sans Mono}
% Russian:
\newfontfamily\cyrillicfont{Arial}
\setmainlanguage{russian}
\setdefaultlanguage{russian}
\setotherlanguage{english}
% ToC:
\usepackage{titletoc}
\usepackage{tocloft}
\usepackage[nottoc]{tocbibind}
\usepackage{afterpage}
% Change the name of the ToC
\AtBeginDocument{%
\renewcommand\contentsname{Table of Contents}}
% Headings for every page of ToC, LoF and Lot
\newcommand\tocheading{\par\bigskip\MakeUppercase{\chaptername}\hfill Page\par}
\newcommand\lofheading{\par\bigskip\figurename\hfill Page\par}
\newcommand\lotheading{\par\bigskip\MakeUppercase{\tablename}\hfill Page\par}
% Centering titles for the ToC, Lof and Lot
\renewcommand{\cfttoctitlefont}{\hfill\normalfont\MakeUppercase}
\renewcommand{\cftaftertoctitle}{\hfill}
\renewcommand{\cftloftitlefont}{\hfill\normalfont\MakeUppercase}
\renewcommand{\cftafterloftitle}{\hfill}
\renewcommand{\cftlottitlefont}{\hfill\normalfont\MakeUppercase}
\renewcommand{\cftafterlottitle}{\hfill}
% Chapter entries formatting for frontmatter chapters
\newcommand\frontmatterchaptoc{%
\titlecontents{chapter}
[1.5em]{\addvspace{\baselineskip}}
{\contentslabel{1.5em}\MakeUppercase}
{\hspace*{-1.5em}\MakeUppercase}
{\titlerule*[1pc]{.}\contentspage}
}
% Chapter entries formatting for mainmatter chapters
\newcommand\mainmatterchaptoc{%
\titlecontents{chapter}
[5em]{\addvspace{\baselineskip}}
{\contentslabel{3em}\hspace*{-1em}\MakeUppercase}
{\MakeUppercase}
{\titlerule*[1pc]{.}\contentspage}
}
% Section, subsection, table and figure entries formatting
\titlecontents{section}
[7em]{}{\hspace{-1em}}{}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}
[7.5em]{}{\hspace{-1em}}{}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{figure}
[5em]{}
{\contentslabel{3em}\hspace*{-1em}}{}
{\titlerule*[1pc]{.}\contentspage}
\titlecontents{table}
[5em]{}
{\contentslabel{3em}\hspace*{-1em}}{}
{\titlerule*[1pc]{.}\contentspage}
% figures:
\usepackage{graphicx}
% colors:
\usepackage[usenames,dvipsnames]{xcolor}
% hyperref:
\usepackage{hyperref}
\hypersetup{
xetex,
pdftitle={Электронная теория металлов: задачи с решениями},
pdfauthor={Boris Kheyfets},
pdfcreator={XeLaTeX},
breaklinks,
backref,
colorlinks,
CJKbookmarks=true,
citecolor=black,
filecolor=black,
linkcolor=black,
urlcolor=black,
}
% hyperref links to table/figures issue:
\usepackage[hypcap]{caption}
% better looking tables with `\toprule`,`\midrule`,`\bottomrule`:
\usepackage{booktabs}
\begin{document}
\frontmatter
\frontmatterchaptoc % activation of chapter entries formatting in the frontmatter
\chapter{Предисловие}
\cleardoublepage
\tableofcontents
\cleardoublepage
\addtocontents{lof}{\lofheading}% add heading to the first page in LoF
\listoffigures
\cleardoublepage
\addtocontents{lot}{\lotheading}% add heading to the first page in LoT
\listoftables
\cleardoublepage
\mainmatter
\addtocontents{toc}{\tocheading}% add heading to the first page in ToC, after frontmatter entries
\mainmatterchaptoc% activation of chapter entries formatting in the mainmatter
\chapter{Introduction}
\section{Section One One}
\begin{figure}
\centering
A
\caption{Test figure one}
\label{fig:test}
\end{figure}
\chapter{Policy divergence and traditional research}
\section{Section Two One}
\begin{figure}
\centering
A
\caption{William Adolphe Bouguereau, \emph{Youth of Bacchus} (initial sketch), 1884}
\label{fig:wab}
\end{figure}
\subsection{Section Two One One}
\end{document}
我发现如果我注释 hyperref —— 它就可以工作。此外,如果我从 ToC 中删除一些高级内容 —— 它也可以工作。
答案1
在目录中,包hyperref
在条目标题周围添加了一个链接。通过\MakeUppercase
在内部添加 ,链接宏会中断\protected@edef
。但是,这无助于使链接宏更强大,参数(链接类型、锚点名称)也会转换为大写。
解决方案:hyperref
提供选项linktocpage
。然后只将页码转换为链接。
另一种方式是避免\MakeUppercase
,更简单的示例删除了第二个\MakeUppercase
(\frontmatterchaptoc
类似\mainmatterchaptoc
):
\documentclass[a5paper, oneside]{book}
% XeTeX technologies:
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{xecyr}
% fonts:
\setmainfont[Mapping=tex-text]{Arial}
\setsansfont{Arial}
\setromanfont{Arial}
\setmonofont{DejaVu Sans Mono}
% Russian:
\newfontfamily\cyrillicfont{Arial}
\setmainlanguage{russian}
\setdefaultlanguage{russian}
\setotherlanguage{english}
% ToC:
\usepackage{titletoc}
\newcommand\frontmatterchaptoc{%
\titlecontents{chapter}
[1.5em]{\addvspace{\baselineskip}}
{\contentslabel{1.5em}\MakeUppercase}
{\hspace*{-1.5em}}% \MakeUppercase removed
{\titlerule*[1pc]{.}\contentspage}
}
\usepackage{hyperref}
\hypersetup{
hidelinks,
unicode,
% linktocpage,
}
\usepackage{bookmark}
\begin{document}
\frontmatter
\frontmatterchaptoc
\chapter{???????????}
\tableofcontents
\end{document}
进一步说明
- 您可能希望使用选项
hidelinks
而不是colorlinks
将不同的注释颜色设置为black
。 - 我将
\usepackage{bookmark}
在之后添加hyperref
以获得更快更新的书签(和更多功能)。 - 选项
backref
应在 的选项列表中指定\usepackage
。 xetex
不需要选项hyperref
(指定它并不是错误),因为hyperref
会自动检测 XeTeX。breaklinks
不需要选项(更多是反映驱动程序能力的内部选项),因为 XeTeX 确实支持断开的链接。- 不应使用/启用选项
CJKbookmarks
,因为生成的书签字符串可能违反标准。 直接支持 XeTeX 的 UTF-8/big 字符hyperref
,因此我认为启用 毫无意义CJKbookmarks
。