0

I realize that this question appears to be similar to the following but it is different:

Using hyperref with \addcontentsline

I was unable to use the link above to solve my problem.

I am writing a document using the book class.

There is a preamble which has notation and the preamble should not have a chapter number in the table of contents.

Code for notation in preamble:

\addcontentsline{toc}{chapter}{Notation}
\phantomsection
\label{chnotation}

% table of notation goes here

In the main body I am using hyper ref to try and get links to pages.

\documentclass[12pt,letterpaper,openany,oneside]{book}

\usepackage[bookmarks,hypertexnames=false,debug,linktocpage=true]{hyperref}
\hypersetup{colorlinks,linkcolor={blue!90},citecolor={blue!90},urlcolor={blue!80}}


\begin{document}

\chapter*{Acknowledgements}
\include*{Preamble/acknowledgements}

\clearpage
\listoftables 
\addcontentsline{toc}{chapter}{List of Tables}

\clearpage
\listoffigures
\addcontentsline{toc}{chapter}{List of Figures}

\clearpage
\chapter*{Notation}
\include*{Preamble/notation}

\setcounter{tocdepth}{3}
\clearpage
\tableofcontents 

\include{"Sections/Chapter 1/chapter1"} 
\include{"Sections/Chapter 2/chapter2"}
\end{document}

The result of the table of contents page is given below

enter image description here

this is correct since the sections in the preamble should not have a chapter number associated with them.

I would like to use use \ref to refer to the notation section, however using \ref{chnotation} (where chnotation is the label of the notation section) does not work. I get the following error message

Package hyperref Warning: Suppressing empty link on input line 16.

Is there away I can use \ref to refer to a section in the preamble that has been set up this way? I can not use \chapter because this will cause a chapter number to appear (along with the text "Chapter XX Notation) and this should not happen since this is part of the preamble.

Desired outcome

I would like to write a something like the following in the body:

The reader may wish to refer to the \ref{chnotation} in the preamble.

and after compiling, the \ref{chnotation} will be replaced by the name of the section in the preamble and the sentence will appear as

The reader may wish to refer to the Notation in the preamble.

where clicking on the word "Notation" will take the reader to the page where the \label{chnotation} was placed.

I tried looking at

Using hyperref with \addcontentsline

for help however I couldn't solve my problem.

7
  • As it says in tex.stackexchange.com/questions/247158/…, just add a \phantomsection before \label{chnotation}. – user30471 Jul 24 '20 at 5:03
  • @Andrew I tried that but unfortunately it does not work. I have edited my posting to reflect this. I still get the same warning message. – NM_ Jul 24 '20 at 5:09
  • @Andrew Unfortunately tex.stackexchange.com/questions/247158/… does not work. I have even mentioned that in my posting that I referred to it but couldn't use it to solve my problem. – NM_ Jul 24 '20 at 5:10
  • What text are you expecting to get from your \ref to an unnumbered chapter? Normally \ref is going to give you the value of the last counter incremented with \refstepcounter – Don Hosek Jul 24 '20 at 5:40
  • 1
    @NM_ You said only that you "tried looking at" the other post without saying what you actually did. Before posting my comments I checked and using \phantomsection and \autoref does solve your problem. – user30471 Jul 24 '20 at 7:19
1

\ref ususally just returns the number fo a chapter. Since you seem to want \ref to return the title of an unnumbered chapter, use \nameref instead:

\documentclass[12pt,letterpaper,openany,oneside]{book}
\usepackage{xcolor}
\usepackage[bookmarks,hypertexnames=false,debug,linktocpage=true]{hyperref}
\hypersetup{colorlinks,linkcolor={blue!90},citecolor={blue!90},urlcolor={blue!80}}


\begin{document}

\chapter*{Notation}  \label{ch:notation}
\addcontentsline{toc}{chapter}{Notation} 

\setcounter{tocdepth}{3}
\clearpage
\tableofcontents 

\chapter{chapter heading}
text \nameref{ch:notation}
\end{document}

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