Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The title says it all. Assume I use two \addtocontents in a document and I want to know whether or not their argument will be typeset in the same page of the ToC.

The simple idea of placing a \label and then using \pageref, as in

\documentclass{article}

\begin{document}

\pageref{a}\pageref{b}

\tableofcontents

\addtocontents{toc}{a\label{a}}
\addtocontents{toc}{\newpage b\label{b}}

\end{document}

fails and produces the expected warning:

LaTeX Warning: There were undefined references.
share|improve this question
3  
It works (on the third LaTeX run) if you \protect the \label commands. –  diabonas Apr 10 '12 at 18:33
add comment

1 Answer

up vote 6 down vote accepted

..... fragile command in a moving argument...

\addtocontents{toc}{a\protect\label{a}}
\addtocontents{toc}{\newpage b\protect\label{b}}
share|improve this answer
    
Now I feel really stupid! Thanks! –  Gonzalo Medina Apr 10 '12 at 18:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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