2

I'm trying to produce a document using the memoir class and the hyperref package. Unfortunately, I get a lot of errors when I try to use the linktocpage option of the hyperref package with \renewcommand{\cftchapterpagefont}{\textrm}.

I guess the solution will be on the lines of this answer to a similar problem, but I haven't been able to figure it out. Here is a minimal working example:

\documentclass[openany,oneside,11pt]{memoir}
\NeedsTeXFormat{LaTeX2e}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Turkish character and language support
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[turkish,shorthands=:!]{babel}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Required packages
\RequirePackage{amssymb,amsmath,hyperref,multicol,ifthen,graphicx,pifont,rotating,xcolor}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The  TOC
\cftsetindents{part}{0em}{3.0em}% Indendation and numwidth for part titles in the TOC
\cftsetindents{chapter}{1em}{2.0em}% Indendation and numwidth for chapter titles in the TOC
\setlength{\cftbeforechapterskip}{0pt}% No gap between chapter titles in the TOC
\renewcommand{\cftchapterfont}{\textrm}% Chapter title font in the TOC
\renewcommand{\cftchapterpagefont}{\textrm}% Clashes with the "linktocpage" option of the hyperref package
\renewcommand{\cftpartafterpnum}{\par % Thanks to https://tex.stackexchange.com/a/42500
    \vspace{-2\baselineskip} \hskip -\memRTLleftskip\protect\mbox{}\protect\hrulefill\par%
    \vspace{0.5\baselineskip} \hskip -\memRTLleftskip\protect\mbox{}\protect\hrulefill\par}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% hyperref setup
\hypersetup{%
    unicode={true}, % 
    bookmarks={true}, %
    colorlinks={true}, %
    allcolors={kmavi},%
    linktocpage={true}, % In TOC, links and colors for page numbers only.
    pdfdisplaydoctitle={true}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The colors
\definecolor{kmavi}{RGB}{0,80,117}
\definecolor{mavi}{RGB}{0,115,168}

\begin{document}

\currentpdfbookmark{Table of Contents}{name}
\tableofcontents*

\part{My First Part}
\chapter{My First Chapter}
\chapter{My Second Chapter}

\end{document}
3
  • Welcome to TeX.SE. \renewcommand{\cftchapterpagefont}{\textrm} does not look really healthy there. Try \renewcommand{\cftchapterpagefont}{\rmfamily} instead – user31729 Jun 8 '17 at 23:52
  • I can't believe it, your suggestion is so simple and it works perfectly. Thank you very much! – Kutt Jun 9 '17 at 0:02
  • Also load hyperref at the end of the preamble almost always, not somewhere in between. – user31729 Jun 9 '17 at 0:03
1

Since hyperref uses the page number as link anchor, \renewcommand{cftchapterpagefont}{\textrm} will fail due to that fact that is expecting an argument.

Use

\renewcommand{\cftchapterpagefont}{\rmfamily}

instead, which is a font switch not needing an argument.

\documentclass[openany,oneside,11pt]{memoir}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Turkish character and language support
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[turkish,shorthands=:!]{babel}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Required packages
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{ifthen}
\usepackage{graphicx}
\usepackage{pifont}
\usepackage{rotating}
\usepackage{xcolor}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The  TOC
\cftsetindents{part}{0em}{3.0em}% Indendation and numwidth for part titles in the TOC
\cftsetindents{chapter}{1em}{2.0em}% Indendation and numwidth for chapter titles in the TOC
\setlength{\cftbeforechapterskip}{0pt}% No gap between chapter titles in the TOC
\renewcommand{\cftchapterfont}{\rmfamily}% Chapter title font in the TOC
\renewcommand{\cftchapterpagefont}{\rmfamily}% Clashes with the "linktocpage" option of the hyperref package
\renewcommand{\cftpartafterpnum}{\par % Thanks to https://tex.stackexchange.com/a/42500
    \vspace{-2\baselineskip} \hskip -\memRTLleftskip\protect\mbox{}\protect\hrulefill\par%
    \vspace{0.5\baselineskip} \hskip -\memRTLleftskip\protect\mbox{}\protect\hrulefill\par}

\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% hyperref setup
\hypersetup{%
    unicode={true}, % 
    bookmarks={true}, %
    colorlinks={true}, %
    allcolors={kmavi},%
    linktocpage={true}, % In TOC, links and colors for page numbers only.
    pdfdisplaydoctitle={true}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The colors
\definecolor{kmavi}{RGB}{0,80,117}
\definecolor{mavi}{RGB}{0,115,168}

\begin{document}

\currentpdfbookmark{Table of Contents}{name}
\tableofcontents*

\part{My First Part}
\chapter{My First Chapter}
\chapter{My Second Chapter}

\end{document}
1
  • 1
    Thank you very much again for your clear explanation and perfect solution. – Kutt Jun 9 '17 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.