0

Using the following mwe:

% vim: spell spelllang=en ft=tex
\documentclass[12pt,twoside,openright,english]{book}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}

\renewcommand{\thechapter}{\Roman{chapter}} \newcommand\periodafter[1]{#1.}

\titleformat{\chapter}[display] {\normalfont\large\filcenter}{\filcenter\MakeUppercase{\chaptertitlename\ \periodafter{\thechapter}}}{0pt}{\periodafter{\uppercase{#1}}}

\titleformat{\subsection} {\normalfont\small}{}{0em}{\hangindent=0.25in#1}

\titlecontents{chapter} [0em] {\filcenter\normalfont\scshape} {\MakeUppercase{\chaptertitlename\ \thecontentslabel}\\addvspace{5pt}\uppercase} {\MakeUppercase{\thecontentslabel}\\addvspace{5pt}\uppercase} {}[\addvspace{5pt}]

\titlecontents{section} [0em] {\hangindent=0.25in\small} {\contentslabel{0em}} {\contentslabel{0em}} {\titlerule*[1em]{.}\contentspage}[\addvspace{5pt}]

\titlecontents{subsection} [0em] {\hangindent=0.25in\small} {} {} {\titlerule*[1em]{.}\contentspage}[\addvspace{5pt}]

\setcounter{secnumdepth}{0} \hypersetup{ bookmarksdepth=1 }

\begin{document} \tableofcontents \frontmatter \chapter{Foreword} \mainmatter \chapter{A} \subsection{\lipsum[1]} \chapter{B} \subsection{\lipsum[1]} \backmatter \chapter{C} \subsection{1} \lipsum[10] \newpage \subsection{2} \lipsum[10] \end{document}

Section C.1 and C.2 show, in the toc, the proper page numbers (5 and 6 respectively) However, clicking the red boxed number of either both bring you to page 5.

This question's answers and comments suggests it to be an issue regarding versions and says its fixed in titletoc 2.11; however my (freshly updated and upgraded as I write this) texlive installation (using lualatex 1.17.0 (TeX Live 2023)) has versions v2.14 of titletoc/titlesec, and v7.00y of hyperref.

Using the MWE from the accepted answer as is seems to produce the same issue.

hanetzer
  • 147
  • 6
  • 1
    as the subsection is unnumbered there is no target. You can add one e.g. with \titleformat{\subsection}{\normalfont\small}{}{0em}{\hangindent=0.25in\MakeLinkTarget[subsection]{}#1}. Unreleted but you have duplicated page numbers. Ensure that every page has an unique name. – Ulrike Fischer Jun 10 '23 at 12:48
  • That did it. Turn this comment into an answer and I'll accept it. – hanetzer Jun 10 '23 at 16:02
  • the duplicated page numbers prolly have to do with my usage of \[front|main|back]matter; in my 'real' projects, I initially set the numbering to alphabetic (to cover a titlepage/similar before anything is 'visibly' numbered), and frontmatter switches to roman, and mainmatter switches to arabic. – hanetzer Jun 10 '23 at 16:21

1 Answers1

1

As the subsection is unnumbered there is no target, as mentioned in the documentation hyperref doesn't fully support titlesec (and hyperref will not change here, we avoid to add more patches to hyperref, titlesec should add support for targets).

You can add one e.g. with

\titleformat{\subsection}{\normalfont\small}{}{0em}{\hangindent=0.25in\MakeLinkTarget[subsection]{}#1}
Ulrike Fischer
  • 327,261