GeneralTable of contents cannot compile with hypperref

LaTeX specific issues not fitting into one of the other forums of this category.
Tissie
Posts: 32
Joined: Wed Feb 18, 2009 9:40 pm

Re: Table of contents cannot compile with hypperref

Post by Tissie »

Alright, I prepared a minimal example, please see attached .rar file

If you pdftexify it should work now. But if you remove the % in front of \tableofcontents on line 128 in Thesis_Main_Error.tex I get the error again.

I appreciate the help.
Attachments
Minimalexample.rar
(30.99 KiB) Downloaded 219 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
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

Table of contents cannot compile with hypperref

Post by Stefan Kottwitz »

As I said in my second post - it produces the error, but after I removed the Thesis_Main_Error.toc it worked. You can try. ;-)

The .toc file originally contains:

Code: Select all

\contentsline {chapter}{Introduction}{{\pageref {chap:Introduction}}}
\contentsline {part}{I\hspace {1em}Testpart}{1}{part.1}
\contentsline {chapter}{\numberline {1}TestChapter}{3}{chapter.1}
\contentsline {section}{\numberline {1.1}Introduction}{3}{section.1.1}
\contentsline {subsection}{\numberline {1.1.1}blabla}{3}{subsection.1.1.1}
You can see, in the first line there's a parameter missing, which means the hyperref anchor. This line is generated in a wrong way, perhaps by calling or redefining \addcontentsline or \addtocontents incorrectly.

Perhaps check your document for that. Or, modify the minimal example in a way that it brings the error also when the .toc file has been deleted, i.e. would be generated again.

Stefan
LaTeX.org admin
Tissie
Posts: 32
Joined: Wed Feb 18, 2009 9:40 pm

Re: Table of contents cannot compile with hypperref

Post by Tissie »

Okay, it does not work with deleting the ToC file in my real document. I reproduced this error in the minimal example by including a chapter where I call \addtocontents (see line 150 in the new Thesis_main_error)
Attachments
Minimalexample.rar
(57.34 KiB) Downloaded 276 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

Table of contents cannot compile with hypperref

Post by Stefan Kottwitz »

Yes, that's the line where you use \contentsline without the argument which is added by hyperref:

Code: Select all

\addtocontents{toc}{\protect \contentsline
  {chapter}{List of Publications}{{\protect \pageref{mypubs}}}}
Add another argument, which can be taken by \contentsline, such as simply {}:

Code: Select all

\addtocontents{toc}{\protect \contentsline
  {chapter}{List of Publications}{{\protect \pageref{mypubs}}}{}}
As guessed, a simple correction fixes it. I just guessed such a problematic line would be in your style file, not in the main document. Such things should be macros, not used repeatedly in the author part of a document.

Stefan
LaTeX.org admin
Tissie
Posts: 32
Joined: Wed Feb 18, 2009 9:40 pm

Table of contents cannot compile with hypperref

Post by Tissie »

Awesome, we are getting close, now I can compile. But my bibliography entrance in the ToC displays the page on which the bibliography ends.

My code for this is:

Code: Select all

\bibliographystyle{bibgen}
\footnotesize{\bibliography{library}}
\addcontentsline{toc}{chapter}{Bibliography}
In the ToC it says that Biblio is on page 56 (the last page of the Biblio), but it actually starts on page 49.

Can I get it to read it correctly?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

Table of contents cannot compile with hypperref

Post by Stefan Kottwitz »

That's because you made the entry after the bibliography. Make it before, and insert \cleardoublepage or \clearpage also before to ensure that you don't make the entry too early.

Code: Select all

\cleardoublepage
\addcontentsline{toc}{chapter}{Bibliography}
{
  \footnotesize
  \bibliography{library}
}
Note, \footnotesize and similar font size commands are declarations and don't have arguments. They work like switches. The effect can be limited by an environment, or a group or braces, respectively, as I did here.

Stefan
LaTeX.org admin
Tissie
Posts: 32
Joined: Wed Feb 18, 2009 9:40 pm

Re: Table of contents cannot compile with hypperref

Post by Tissie »

Super, it works now.

Thank you very much for your help, Stefan - I really appreciate it :)
Now with this solved I can focus on the actual writing.. hehe

Kind regards,
Tissie
Post Reply