General ⇒ Conditional output depending on a label being defined?
-
- Posts: 17
- Joined: Thu Aug 07, 2008 7:51 pm
Conditional output depending on a label being defined?
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.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Conditional output depending on a label being defined?
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}
-
- Posts: 17
- Joined: Thu Aug 07, 2008 7:51 pm
Re: Conditional output depending on a label being defined?
Thanks a lot; that really worked.
Yours,
Robert Lee