Document Classeshyperref | Issue with custom Document Class

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
jibberalan
Posts: 9
Joined: Mon Oct 18, 2010 11:52 pm

hyperref | Issue with custom Document Class

Post by jibberalan »

Hi,

I am currently trying to use my school's thesis document class, however it will not work with the hyperref package. I have contacted the graduate school, but no clue if I'll get any help from them... Anyways, I have attached a minimum code example below that uses their document class and macros file. It will compile great until you add the hyperref package. The error has to do with the \contentsline command... Any help figuring out why this is breaking it would be greatly appreciated!! Thanks!
Attachments
mythesis.tex
(1.85 KiB) Downloaded 433 times
macros.tex
(865 Bytes) Downloaded 424 times
thesis.cls
(40.64 KiB) Downloaded 595 times

Recommended reading 2024:

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

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

User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

hyperref | Issue with custom Document Class

Post by Juanjo »

The problem comes from the \addtocontents commands included in thesis.sty. They write \contentsline commands in the toc, lof and lot files. But this command has an extra argument when hyperref is loaded. Hence, when LaTeX reads the auxiliary files, it detects that such an argument is missing, hence the error.

The solution is simple: search for \addtocontents in thesis.cls and replace each {\protect\relax}} by {\protect\relax}{}}. You should have the lines:

Code: Select all

\addtocontents{lof}{\protect\contentsline {part}
	{\protect\figurenameToC}{\protect\relax}{}}
\addtocontents{lot}{\protect\contentsline {part}
	{\protect\tablenameToC}{\protect\relax}{}}
\addtocontents{toc}{\protect\contentsline {part}
	{\protect\chapternameToC}{\protect\relax}{}}
and also

Code: Select all

\addtocontents{toc}{\protect\contentsline {part}
		{\protect\appendixnameToC}{\protect\relax}{}}
Note the extra pair of braces at the end of every \addtocontents. It has no effect if hyperref is not loaded, but it provides the extra argument for \contentsline, otherwise.

If the above code works, contact your school in order to improve thesis.cls.

I also suggest you to treat your macros file as a package. To this end, rename macros.tex to macros.sty, add the line

Code: Select all

\RequirePackage{macros}
at the top of macros.sty, delete \input macros.tex in the source file and write \usepackage{macros} instead (in the preamble, before \begin{document}).
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
schremmer
Posts: 7
Joined: Mon Oct 25, 2010 8:16 pm

hyperref | Issue with custom Document Class

Post by schremmer »

I have the same error with the book class and I don't think I want to change that. So, might there be some other way?


Hopeful regards
--schremmer
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

hyperref | Issue with custom Document Class

Post by localghost »

schremmer wrote:I have the same error with the book class and I don't think I want to change that. So, might there be some other way? […]
For an adequate problem description and in order to prevent other from guesswork kindly prepare a self-contained and minimal example that clearly reproduces the undesired behaviour.


Thorsten
Post Reply