Discussion:
How to locally change counter for theorem-environment with referencing
(too old to reply)
fjcmurphy
2006-05-08 16:39:59 UTC
Permalink
Hello!

I'm writing on my thesis and would like to have the following: In some
chapter I use a theorem with
\begin{theorem} \label{thm:A}
...
this is the Theorem 7.1
...
\end{theorem}
Lets say it is now called "Theorem 7.1".

Then in a later chapter (lets say Chapter 10) I use the same theorem
again. I repeat it with
\begin{theorem}
...
this is the Theorem 7.1
...
\end{theorem}
so the reader does not have to change back and forth all the time. How
do I tell LaTeX, to print again "Theorem 7.1" instead of "Theorem
10.1"?

I hope my question is clear ;)


Cheers and thanks alot in advance,
frank
Ulrich Diez
2006-05-08 21:15:59 UTC
Permalink
fjcmurphy wrote:

...
In some chapter I use a theorem
...
Then in a later chapter ...
I repeat it with
...
so the reader does not have to change back and forth all the time.
My suggestion:

The number of the <theorem> comes from printing the <theorem>-
count-register's value via the macro \the<theorem>.
- Don't reset the counter-register but locally redefine the
associated \the<theorem>-macro.
- Save the expansion of \the<theorem> right after writing the
theorem the first time.
- When writing the theorem the second time, locally redefine
\the<theorem> to expand to that saved expansion.

In case you don't have changed referencing for your <theorem>-
counter, you can use \label and \ref for saving and regaining
\the<theorem>'s expansion. Otherwise you can define another
macro to expand to the desired values:

\documentclass{article}

\newtheorem{theorem}{Theorem}[section]%

\begin{document}
\section{test 1}

\begin{theorem}
This is the first theorem that shall be repeated.
\end{theorem}
\xdef\savedtheoremnumber{\thetheorem}%
% You may wish to first check if \savedtheoremnumber is already
% defined:
% \makeatletter\@ifdefinable\savedtheoremnumber{%
% \xdef\savedtheoremnumber{\thetheorem}%
% }\makeatother
% or:
% \newcommand\savedtheoremnumber{}%
% \xdef\savedtheoremnumber{\thetheorem}%

\section{test 2}

\begin{theorem}\label{thm:B}
This is the second theorem that shall be repeated.
\end{theorem}

% repeat the first theorem:
{%
\renewcommand\thetheorem{\savedtheoremnumber}%
\begin{theorem}
This is the first theorem that shall be repeated.
\end{theorem}
\addtocounter{theorem}{-1}%
}%

\begin{theorem}\label{thm:C}
This is another theorem.
\end{theorem}

% repeat the second theorem:
{%
\renewcommand\thetheorem{\ref{thm:B}}% Use \ref* instead with hyperref
\renewcommand\label[1]{\relax}%
\begin{theorem}\label{thm:B}
This is the second theorem that shall be repeated.
\end{theorem}
\addtocounter{theorem}{-1}%
}%

\begin{theorem}\label{thm:D}
This is yet another theorem.
\end{theorem}


\end{document}


Ulrich
fjcmurphy
2006-05-09 06:33:16 UTC
Permalink
Hello Ulrich!

Thanks alot!

The first version with
\xdef\savedtheoremnumber{\thetheorem}%

works for me. However, when I use
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage[amsmath, thref,hyperref ]{ntheorem}

I can't use your second proposed way. I always get
--- TeX said ---
\***@ifnextchar ***@d = #1\def \***@a {
#2}\def \***@b
{#3}\f...

while compiling. Moreover, what does the opional "[1]" in
\label[1]{\relax} do?

Thanks alot.

All the best,
frank
Ulrich Diez
2006-05-09 08:15:05 UTC
Permalink
fjcmurphy wrote;
Post by fjcmurphy
Hello Ulrich!
Thanks alot!
The first version with
\xdef\savedtheoremnumber{\thetheorem}%
works for me. However, when I use
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage[amsmath, thref,hyperref ]{ntheorem}
I can't use your second proposed way. I always get
With this preamble referencing is changed.
Post by fjcmurphy
Post by Ulrich Diez
In case you don't have changed referencing for your <theorem>-
counter, you can use \label and \ref for saving and regaining
\the<theorem>'s expansion.
As referencing is changed, the inverse-case is not given
any more. So stuff of course might not work as expected
any more when going this route.
You can use another \ref-like macro instead which extracts
only the reference-number (no hyperlinks and stuff).
There was plenty of discussion about this recently/yesterday
at comp.text.tex.
I recommend using Heiko Oberdiek's refcount-package.

...
Post by fjcmurphy
Moreover, what does the opional "[1]" in
\label[1]{\relax} do?
It's not optional.
It's: \renewcommand\label[1]{\relax}
In case missing braces confuse you:
It's equal to: \renewcommand{\labe}l[1]{\relax}

This means: \label is redefined to "eat" it's argument and to
spit out \relax. For writing your theorem the second time, you
might use the "edit-copy-paste"-feature of your editor.
You might easily omit to remove \label-s placed into the theorem.
This might lead to erroneously getting multiple labels
with equal name. This can be prevented by locally redefining
label to do nothing or to \relax.

Ulrich
Ulrich Diez
2006-05-09 08:18:34 UTC
Permalink
Post by Ulrich Diez
It's not optional.
It's: \renewcommand\label[1]{\relax}
It's equal to: \renewcommand{\labe}l[1]{\relax}
Correction:

It's equal to: \renewcommand{\label}[1]{\relax}

Sorry for the typo.

Ulrich
fjcmurphy
2006-05-09 14:30:55 UTC
Permalink
Thanks alot for all the clarification.

Cheers,
frank

Loading...