# Clash between the “linktocpage” option of the hyperref package and the “\cftchapterpagefont” command of memoir class

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}, %
allcolors={kmavi},%
pdfdisplaydoctitle={true}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The colors
\definecolor{kmavi}{RGB}{0,80,117}
\definecolor{mavi}{RGB}{0,115,168}

\begin{document}

\tableofcontents*

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

\end{document}

• 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

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}, %
allcolors={kmavi},%
pdfdisplaydoctitle={true}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The colors
\definecolor{kmavi}{RGB}{0,80,117}
\definecolor{mavi}{RGB}{0,115,168}

\begin{document}