Hi.
I'm working on a LaTeX package, which re-orders text in a document. It adds a line of text like "continued on page~\pageref{to#1}" when a block of text is moved.
Unfortunately, it doesn't guarantee that \label{to#1} will be defined in the document. Is there any way (without manually parsing the .aux file) to hide the line of text if the label is not defined?
Many thanks
Yours,
Robert Lee.
General ⇒ Conditional output depending on a label being defined?
-
- Posts: 17
- Joined: Thu Aug 07, 2008 7:51 pm
NEW: TikZ book now 40% off at Amazon.com for a short time.

Conditional output depending on a label being defined?
A label called foo gives rise to a command called \r@foo. You can check if this command is defined through the conditional \@ifundefined. Look at the following example:
Pay special attention to the second page of the resulting document. Compare its content after the first and the second run. If you don't see the difference, remove the .aux file and try again.
Code: Select all
\documentclass{article}
\makeatletter
\newcommand{\testlabel}[1]{%
\@ifundefined{r@#1}%
{Label #1 is not defined}%
{Label #1 is associated to the value \ref{#1} and the page \pageref{#1}}}%
\makeatother
\begin{document}
\section{A section}\label{sec:1}
Text, more text and an equation:
\begin{equation}\label{eq:1}
a+b=c.
\end{equation}
\section{Other section}\label{sec:2}
Text, more text and a new equation:
\begin{equation}\label{eq:2}
d+e=f.
\end{equation}
\newpage
\section{Last section}\label{sec:3}
Now we test several labels:\\
\testlabel{sec:1}\\
\testlabel{sec:2}\\
\testlabel{eq:1}\\
\testlabel{eq:2}\\
\testlabel{sec:3}\\
\testlabel{eq:3}.
\end{document}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
-
- Posts: 17
- Joined: Thu Aug 07, 2008 7:51 pm
Re: Conditional output depending on a label being defined?
Juanjo,
Thanks a lot; that really worked.
Yours,
Robert Lee
Thanks a lot; that really worked.
Yours,
Robert Lee