EDIT:
I solved most of my original problems so I am rewriting the question which is still fundamentally the same but now I can post a much nicer MWE.
The problem I am having is to make the dots in the table of contents into links that link to the relevant section/chapter. Essentially I want the clickable link to span from the text of the section all the way through to the page number, so that it includes the dots in between. I have tried a number of potential solutions but can't seem to get it to work.
Ultimately my goal is to mimic the example page given here, where I believe I have managed to do so except for some minor formating that I'm still finishing off (eg removing numbers in subsections and correcting some indenting). The only piece I can't seem to figure out is making the dots clickable along with the text and page number.
Here is the self-contained MWE: (Keep in mind it's a bit long because part of the problem is the package interaction, so I need to include them all with their settings to make sure any potential solutions avoid package conflicts).
\documentclass{report}
\makeatletter
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage[titles]{tocloft}
\usepackage[linktoc=all]{hyperref}% Use this to provide intra-pdf hyperlinking and better toc
% linktoc=all used to extend the hyperlink across the dotted lines.... in theory.
\hypersetup{% % Setup the coloring of the links.
% % Currently the only necessary one is "colorlinks=true" and "linkcolor=blue".
colorlinks = true, % Colours links instead of ugly boxes
urlcolor = blue, % Colour for external hyperlinks
linkcolor = blue, % Colour of internal links
citecolor = blue % Colour of citations, could be ``red''
}
\usepackage{titlesec}% Use this to manipulate default chapter styling
\usepackage[margin=1in]{geometry}
\raggedright
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand\headrulewidth{0pt}
\lhead{}\chead{}\rhead{}
\cfoot{\vspace*{1.5\baselineskip}\thepage}
\usepackage[nodisplayskipstretch]{setspace}%
\doublespacing% Make everything double spaced by default.
\preto\longtable{\par\singlespacing}% Pre-append using longtables to make sure that tables are single spaced.
\preto\itemize{\par\singlespacing}% Pre-append singlespace to itemize to account for single space bullet point lists.
\titleformat{\chapter}[hang]{\large}{}{0pt}{\centering\singlespacing\MakeUppercase}{\raggedright\doublespacing}
\titleformat{\part}[hang]{\large}{}{0pt}{\centering\singlespacing\MakeUppercase}{\raggedright\doublespacing}
\renewcommand{\contentsname}{TABLE OF CONTENTS}%
\renewcommand{\cftdotsep}{1}
\renewcommand\cftchapfont{\normalfont}% Remove Bold font from TOC
\renewcommand\cftchappagefont{\normalfont}% Remove Bold font from TOC
\renewcommand\cftpartfont{\normalfont}% Remove Bold font from TOC
\renewcommand\cftpartpagefont{\normalfont}% Remove Bold font from TOC
\setlength{\cftbeforechapskip}{1pt}%
\setlength{\cftbeforepartskip}{1pt}%
\setlength{\cftbeforesecskip}{-6pt}%
\setlength{\cftbeforesubsecskip}{-6pt}%
\setlength{\cftbeforesubsubsecskip}{-6pt}%
\def\cftchapleader{\hyperlink{\mylabel}{\cftdotfill{\cftsecdotsep}}}% Add in the dotted lines between the name and page number in TOC
\begin{document}
\setcounter{secnumdepth}{-1}% We don't want chapter numbers until later,
% So let's kill off the table of contents depth detector until we want to start counting.
\chapter{DEDICATION}
Some dedication stuff goes here.
\chapter{ACKNOWLEDGEMENTS}
\label{Acknowledgements}
\hypertarget{acknowledgements}{}
\edef\mylabel{acknowledgements}
Some Acknowledgements Text here.
\tableofcontents
\listoftables
\addcontentsline{toc}{chapter}{LIST OF TABLES}
\hypertarget{LOT}{}
\edef\mylabel{LOT}
%\addtocontents{toc}{\protect\contentsline{chapter}{LIST OF TABLES}{}{\@currentHref}}
\listoffigures
\addcontentsline{toc}{chapter}{LIST OF FIGURES}
\hypertarget{LOF}{}
\edef\mylabel{LOF}
%\addtocontents{toc}{\protect\contentsline{chapter}{LIST OF FIGURES}{}{\@currentHref}}
%\def\cftchapleader{\hyperlink{abbreviations}{\cftdotfill{\cftsecdotsep}}}%
\hypertarget{abbreviations}{}
\chapter{ABBREVIATIONS}
\label{abbreviations}
\edef\mylabel{abbreviations}
Some Abbreviation text would go here.
\chapter{ABSTRACT}
\label{abstract}
Some Abstract text goes here.
\addtocontents{toc}{\protect\contentsline{part}{CHAPTER}{}{}}
\setcounter{secnumdepth}{3}% Now we want toc numbering.
\chapter{First real chapter}
Some intro or something else here
\section{A `section', toc should be indented some.}
Some section info.
\subsection{A `subsection', toc should be indented even more.}
\chapter{Second real chapter}
More text here.
\setcounter{secnumdepth}{-1}% We don't want the Appendix to have a number, but it should be linked.
\chapter*{APPENDIX}
\label{appendix}
\addtocontents{toc}{\protect\contentsline{part}{APPENDIX}{}{\@currentHref}}
\setcounter{secnumdepth}{3}% Now we number again.
\chapter{REFERENCES}
\label{references}
\chapter{BIOGRAPHY}
\label{biography}
\end{document}
To be clear, the specific line of interest is \def\cftchapleader{\hyperlink{\mylabel}{\cftdotfill{\cftsecdotsep}}}%
which is my last attempt at trying to get the dots to link to the correct spot using \hyperlink
from the hyperref package. But even trying to update the \mylabel
each section doesn't seem to allow links to be formed correctly, and neither does the \@currentHref
. I suspect this is an expansion issue due to when the actual ToC is formed versus when the labels and things are formed.
\At(Begin/End)Document
commands... The document must be made out of certain files (one file for each "piece") and those elements must be compiled in a specific order. Rather than having a large template that requires people to make sure they use the\include
commands in the correct order, I am taking in file names, and then using the\At(Begin/End)Document
commands to force the compile in the correct order.