# How do I determine the page in which manually added ToC entries are typeset?

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.

-
It works (on the third LaTeX run) if you \protect the \label commands. – diabonas Apr 10 '12 at 18:33

## 1 Answer

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

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

-
Now I feel really stupid! Thanks! – Gonzalo Medina Apr 10 '12 at 18:46