Generalhyperref | Problem with ToC, LoF and LoT in custom Class

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
physicsgrad
Posts: 4
Joined: Thu Sep 06, 2012 9:17 pm

hyperref | Problem with ToC, LoF and LoT in custom Class

Post by physicsgrad »

Hello all,

I am new to this forum, I'm finishing up a PhD program and working on my thesis (a common story in these halls I imagine). Princeton distributes its own (unofficial) class file for theses, and for the most part it has worked just fine. However, when I try to use the hyperref package, I have an issue that seems to be confined only to the hyperlinks embedded in the ToC, LoT, and LoF (i.e., hyperlinks display and function properly in the body text, with no errors on compilation).

I am using TeXShop, and the 'TeX and DVI' typesetting option. When I run LaTeX, I get two 'Undefined control sequence' errors each time hyperref encounters a ToC, LoF, or LoT entry (see attached .log file), but no other errors occur during compilation. In the output PDF, the ToC, LoF, and LoT hyperlinks are displayed and function properly, but the word 'red' appears next to each link on the top left-hand side. Throughout the rest of the document, all other hyperlinks look good and work correctly (no phantom words lingering about).

Attached also is the puthesis.cls class file for the Princeton thesis format, as well as the main control TeX file, thesis_online.tex. My guess is that the problem is within the \addcontentsline bits at the bottom of the class file, and how it interacts with hyperref when that package is activated (everything works perfectly without hyperref). I found this post:

http://www.latex-community.org/forum/vi ... =4&t=13245

which seemed relevant, discussing a missing (empty) argument that hyperref expects to encounter, but this class file isn't using the \addtocontents command. I would greatly appreciate any input, and if more information is needed, please let me know (this is my first inquiry on a TeX forum!). Thanks so much!
Attachments
thesis_online.tex
(7.77 KiB) Downloaded 307 times
thesis_online.log
(72.7 KiB) Downloaded 422 times
puthesis.cls
(4.14 KiB) Downloaded 355 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

physicsgrad
Posts: 4
Joined: Thu Sep 06, 2012 9:17 pm

Re: hyperref | Problem with ToC, LoF and LoT in custom Class

Post by physicsgrad »

Also, here is a MWE to demonstrate the problem (exhibited here just within the TOC, though a more complete example shows the same issues with the LOT and LOF as well). I use just the three files (two .tex files and the .cls file). Also attached is my .pdf output, with the links in the TOC exhibiting the phantom 'red' word next to each link.
Attachments
thesis_online.pdf
(18.12 KiB) Downloaded 281 times
ch_intro.tex
(5 Bytes) Downloaded 358 times
puthesis.cls
(4.14 KiB) Downloaded 283 times
thesis_online.tex
(3.73 KiB) Downloaded 328 times
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

hyperref | Problem with ToC, LoF and LoT in custom Class

Post by cgnieder »

Hi physicsgrad,

Welcome to the LaTeX community!

It took me a while until I found a solution to your problem. As to the why -- I still have no idea. There is some conflict in the order when hyperref has to be loaded but I can't pinpoint the exact source of the problem (which bugs me a little ;) ).

Apparently with the puthesis class hyperref must be loaded before the last line of the class which reads

Code: Select all

\AtBeginDocument{\begincmd}
\endinput
In order to maintain the same options as before I decided the following as solution:

Pack the stuff from thesis-online.tex which is marked not to change

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Don't change this stuff
% Printed vs. online formatting
into the class file.

So I deleted all that from the tex file and changed the last lines of the class which now read:

Code: Select all

\ifdefined\printmode
  \RequirePackage{url}
\else
  \RequirePackage{hyperref}
  \ifdefined\proquestmode %ProQuest copy -- http://www.princeton.edu/~mudd/thesis/Submissionguide.pdf
    \hypersetup{bookmarksnumbered,pdftitle=\@title,pdfauthor=\@author}
  \else	% Online copy
    \hypersetup{bookmarksnumbered=true,colorlinks=true,pdftitle=\@title,pdfauthor=\@author}
  \fi % proquest or online formatting
\fi

\AtBeginDocument{\begincmd}
\endinput
The only real difference is now that you have to define \printmode or \proquestmode before \documentclass.

My Infominimal working example at least now compiles fine:

Code: Select all

\documentclass{puthesis}
\title{bla}
\author{blub}
\adviser{someone}
\submitted{09-2012}
\abstract{blubber}


\begin{document}

\chapter[Introduction]{Introduction}

\end{document}
I attached the modified thesis class (which one should probably mark as modified/private version somewhere in the source).

Regards
Attachments
puthesis.cls
(4.54 KiB) Downloaded 402 times
site moderator & package author
physicsgrad
Posts: 4
Joined: Thu Sep 06, 2012 9:17 pm

Re: hyperref | Problem with ToC, LoF and LoT in custom Class

Post by physicsgrad »

Hello cgnieder!

Your fix seems to work, but I agree with you, the reasons seem to be a bit nebulous. Thank you very much for helping look into this! Now that I'm looking at the properly-compiled PDF, I notice that for some reason going into hyperref mode causes the text entries in the LoF and LoT (and, presumably, the ToC if the entries were long enough) to fail to wrap properly, so they run off the page along with the corresponding page number entries. This does not occur in printmode, where the text in each listing wraps properly. I figure this must be an issue pertaining to how hyperref's default settings affect the page formatting, because there doesn't seem to be anything in the class file or the main TeX file that indicates a change in formatting settings when switching from printmode to the hyperlinked or proquest modes. Do you have any idea how to restore proper text wrapping using the hyperref package?

Thanks again!

Paul
physicsgrad
Posts: 4
Joined: Thu Sep 06, 2012 9:17 pm

hyperref | Problem with ToC, LoF and LoT in custom Class

Post by physicsgrad »

Nevermind, found some other posts that mentioned the breaklinks option, that did the trick! Thank you very much once again for your help in figuring out where this Princeton class file was going wrong!

Paul
Post Reply