1

I'm trying to apply this awesome template. I'm using XeTeX and russian -- and it gives:

! Missing \endcsname inserted.
<to be read again> 
                   \csname\endcsname
l.5 ...ter}{Предисловие}{i}{chapter*.1}

Here's 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}

I found that if I comment hyperref -- it works. Also if I remove some advanced stuff from ToC -- it also works.

Adobe
  • 3,037

1 Answers1

3

In the table of contents package hyperref adds a link around the entry titles. The link macros break by adding \MakeUppercase inside \protected@edef. However, it does not help to make the link macros robust, the arguments (link type, anchor name) would be converted into uppercase, too.

Solution: hyperref provides option linktocpage. Then only the page number is converted to a link.

Another way is avoiding \MakeUppercase, the more minimal example removes the second \MakeUppercase in \frontmatterchaptoc (similar \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}

Further remarks

  • You might want to use option hidelinks instead of colorlinks with setting the different annotation colors to black.
  • I would add \usepackage{bookmark} after hyperref to get faster updated bookmarks (and more features).
  • Option backref should be specified in the option list of \usepackage.
  • Option xetex for hyperref is not needed (it is not an error to specify it), because hyperref automatically detects XeTeX.
  • Option breaklinks (more an internal option to reflect the driver ability) is not needed, because XeTeX does support broken links.
  • Option CJKbookmarks should not be used/enabled, because the resulting bookmark strings might violate the standard. UTF-8/big chars of XeTeX are directly supported by hyperref, thus I do not see the point in enabling CJKbookmarks.
Heiko Oberdiek
  • 271,626
  • Thank You. And if I'd remove \MakeUppercase -- but have titles be hyperlinks -- which \MakeUppercase should I remove? You said "inside \protected@edef" -- but I don't understand where it is. – Adobe Nov 29 '12 at 14:30