I am working with a LaTeX template and am noticing a big difference between the compiled document after adding \usepackage{hyperref} at the top. Before adding it, the Table of Contents section is exactly how I want it, with nothing weird going on before each line:

Does anyone know why this is happening or how I can fix it?

Edit: here's a MWE.

\documentclass{MyUniversityThesisTemplate.cls}

\usepackage{hyperref}

\begin{document}

\chapter{Chapter 1}

\section{Section 1}

\chapter{Chapter 2}

\section{What do we want to measure?}

\section{Variables}

\section{Actors}

\section{Causal Relationships}

\section{Interdependencies}

\end{document}


And here's a MWE for the class document (might not be working though):

\NeedsTeXFormat{LaTeX2e}

\ProvidesClass{MyUniversityThesisTemplate}[2011/02/16 v1.4.2 My University Thesis class]

\RequirePackage{setspace}

%here I skip some code

\DeclareOption{myorder}{

\renewcommand*{\begincmd}{\doublespacing}}

\DeclareOption{lot}{\renewcommand*{\makelot}{

\DeclareOption{lof}{\renewcommand*{\makelof}{

\DeclareOption{los}{

\renewcommand*{\makelos}{

\RequirePackage{losymbol}

\section*{List of Symbols\@mkboth {LIST OF SYMBOLS}{LIST OF SYMBOLS}}

\@starttoc{los}

}

}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}

\ProcessOptions

%here I skip some code

\AtBeginDocument{\begincmd}

\endinput

• you should make sure that hyperref is the very last package you load, so put it at the bottom of your preamble, just before \begin{document}. Have you tested that? – T. Pluess Jun 3 '19 at 4:45
• @T.Pluess, yeah, it is currently the very last package that I load. Thanks for the idea though – Rasputin Jun 3 '19 at 6:17
• Untested but I doubt very much that the stripped down class actually triggers your problem - there is nowhere something looking like "red" and hyperref doesn't invent such a word. You will have to show a real minimal example that actually demonstrates the problem. – Ulrike Fischer Jun 3 '19 at 7:28
• The article class does not have \chapters, so this cannot work. But report and book have. And if I use one of those and add \tableofcontents to your MWE, then I even get a table of contents and everything is fine. – DLichti Jun 3 '19 at 8:14
• There isn't enough information to reproduce your problem, but random guess: Does \tableofcontents end up inside of \AtBeginDocument by any chance? – David Purton Jun 3 '19 at 9:37