Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reusing theorem numbers

1,264 views
Skip to first unread message

Edward M. Reingold

unread,
May 20, 2009, 12:01:32 PM5/20/09
to
I want to reset the theorem number to a previously defined value; that is, I
want to state a series of theorems (without proof) in one part of a paper,
then repeat them (with proofs) WITH THE SAME NUMBERS in a later part of the
paper. How do I do that?
--

Professor Edward M. Reingold Email: rein...@iit.edu
Department of Computer Science Voice: (312) 567-3309
Illinois Institute of Technology Fax: (312) 567-5067
Stuart Building, 228F
10 West 31st Street
Chicago, IL 60616-3729 U.S.A.

Ulrich M. Schwarz

unread,
May 20, 2009, 12:26:20 PM5/20/09
to
On Wed, 20 May 2009 18:01:32 +0200, Edward M. Reingold
<rein...@emr.cs.iit.edu> wrote:

> I want to reset the theorem number to a previously defined value; that
> is, I
> want to state a series of theorems (without proof) in one part of a
> paper,
> then repeat them (with proofs) WITH THE SAME NUMBERS in a later part of
> the
> paper. How do I do that?

That depends a lot on what else you need handled: what is supposed to
happen
to equation numbers in your theorem? New or reused? Labels? Floating
environments
within?
That being said, and hoping it's only a paper and not 300+ pages of
lecture notes
where you really really need it to work entirely reliably, you can try
thm-restate
from the thmtools bundle:

\documentclass{article}
\usepackage{amsmath, amsthm,
thm-restate}% http://absatzen.de/thmtools.html, CTAN version is a bit
out-of-date
\newtheorem{lemma}{Lemma}
\begin{document}
\begin{restatable}[Zorn]{lemma}{zornlemma}\label{thm:zorn}
If every chain in $X$ is upper-bounded,
$X$ has a maximal element.
It's true, you know!
\end{restatable}
\begin{lemma}
This is some other lemma of no import.
\end{lemma}
And now, here's Mr. Zorn again: \zornlemma*
\end{document}

HTH
Ulrich

Alan Munn

unread,
May 20, 2009, 12:34:52 PM5/20/09
to
In article <85k54b4...@emr.cs.iit.edu>,

rein...@emr.cs.iit.edu (Edward M. Reingold) wrote:

> I want to reset the theorem number to a previously defined value; that is, I
> want to state a series of theorems (without proof) in one part of a paper,
> then repeat them (with proofs) WITH THE SAME NUMBERS in a later part of the
> paper. How do I do that?

Assume you label each equation with \label{eq1} etc, with amsmath you
can set the equation number of the repeated equation using
\tag{\ref{eq1}}.

Alan

Edward M. Reingold

unread,
May 20, 2009, 12:50:14 PM5/20/09
to
>>>>> "EMR" == Edward M Reingold <rein...@emr.cs.iit.edu> writes:

EMR> I want to reset the theorem number to a previously defined value;
EMR> that is, I want to state a series of theorems (without proof) in one
EMR> part of a paper, then repeat them (with proofs) WITH THE SAME NUMBERS
EMR> in a later part of the paper. How do I do that? --

I should have been more precise. Here is what I want to do:

\begin{lemma}\label{neighbors}
Blah, blah..
\end{lemma}

...

RESET THE LEMMA COUNTER TO \ref{neighbors}
\begin{lemma}
Blah, blah..
\end{lemma}
\begin{proof}
...
\end{proof}

Oleksandr Baranovskyi

unread,
May 22, 2009, 1:00:52 AM5/22/09
to
Edward M. Reingold написав(ла):

>>>>>> "EMR" == Edward M Reingold <rein...@emr.cs.iit.edu> writes:
>
> EMR> I want to reset the theorem number to a previously defined value;
> EMR> that is, I want to state a series of theorems (without proof) in one
> EMR> part of a paper, then repeat them (with proofs) WITH THE SAME NUMBERS
> EMR> in a later part of the paper. How do I do that? --
>
> I should have been more precise. Here is what I want to do:
>
> \begin{lemma}\label{neighbors}
> Blah, blah..
> \end{lemma}
>
> ...
>
> RESET THE LEMMA COUNTER TO \ref{neighbors}

Put

\setcounter{lemma}{n-1}

before lemma, where n is a number of lemma with label neighbors.

> \begin{lemma}
> Blah, blah..
> \end{lemma}
> \begin{proof}
> ...
> \end{proof}

However this simple solution has some disadvantages:

1) If lemmata are not numbered consecutively, one should do the same
before each lemma.

2) If lemma contains some equations (figures etc.), one should do the
same with counter equation (figure etc.).

3) If the number of lemma neighbors has changed, one should set manually
another value for the counter.

You may try the yafp package:

http://www.imath.kiev.ua/~baranovskyi/tex/yafp/yafp.sty

Sorry, only Ukrainian documentation is available now. But usage is
extremely simple.

Suppose that we have some lemmata (or other numbered objects: theorems,
equations, figures etc.) in the main part of the document:

% Suppose that the number of this lemma is 1.1
\begin{lemma}
\label{lem:test1}
Test 1.
\end{lemma}

% Suppose that the number of this lemma is 1.2
\begin{lemma}
\label{lem:test2}
Test 2.
\end{lemma}

% Suppose that the number of this lemma is 1.3
\begin{lemma}
\label{lem:test3}
Test 3.
\end{lemma}

We want to put some lemmata to another part of the document and preserve
their numbers. Then we should only "copy and paste" and surround that
part by environment yafea:

\begin{yafea}

% The number of this lemma will be 1.1 here
\begin{lemma}
\label{lem:test1}
Test 1.
\end{lemma}

Test. Some text.

% The number of this lemma will be 1.3 here
\begin{lemma}
\label{lem:test3}
Test 3.
\end{lemma}

Test. Some text.

\end{yafea}

Note that one should use the \label for each lemma. And lemma has the
same \label inside yafea.

--
Yours sincerely,
Oleksandr Baranovskyi

Ulrich D i e z

unread,
May 23, 2009, 5:44:37 AM5/23/09
to
Edward M. Reingold wrote:

> >>>>> "EMR" == Edward M Reingold <rein...@emr.cs.iit.edu> writes:
>
> EMR> I want to reset the theorem number to a previously defined value;
> EMR> that is, I want to state a series of theorems (without proof) in one
> EMR> part of a paper, then repeat them (with proofs) WITH THE SAME NUMBERS
> EMR> in a later part of the paper. How do I do that? --
>
> I should have been more precise. Here is what I want to do:
>
> \begin{lemma}\label{neighbors}
> Blah, blah..
> \end{lemma}
>
> ...
>
> RESET THE LEMMA COUNTER TO \ref{neighbors}
> \begin{lemma}
> Blah, blah..
> \end{lemma}
> \begin{proof}
> ...
> \end{proof}

Hello Professor Reingold,

you might be interested in testing my theolab-package.
It is an attempt at enhancing theorem-like environments
in order to make it possible to provide names/labels for single
instances of such environments. When doing so, it is
possible to repeat/restate such environments via
\restatetheorem{<label/name>}.

I tried to take counter-management and duplicate-label-errors
and multiply-defined hyperref-anchors into account. Nonetheless
I give no warranties.

The package is not on CTAN yet as there still is a lot of
work to do. The version numner indicates the package currently
is at some beta-testing state.

Sincerely

Ulrich

Example.tex
theolab.sty

Edward M. Reingold

unread,
May 24, 2009, 11:07:49 AM5/24/09
to
Thanks to all of those who helped. I have now solved the basic problem that I
had using the "restatable" environment (nice package). But what I still want
to know is, how do I reset a LaTeX theorem counter to a value that needs
expansion!
Message has been deleted
Message has been deleted
Message has been deleted

Ulrich D i e z

unread,
May 24, 2009, 4:04:35 PM5/24/09
to
Edward M. Reingold wrote:

[...]


> But what I still want
> to know is, how do I reset a LaTeX theorem counter to a value that needs
> expansion!

I'm confused by your question/request because usually expansion
takes place with counter-assignments in any case:


\documentclass{article}

\newcommand*\firstdigitsequence{12}
\newcommand*\seconddigitsequence{34\firstdigitsequence}

% Allocate a TeX-count-register:
\newcount\mycountA

% Allocate a LaTeX-counter:
\newcounter{mycountB}

\begin{document}

\mycountA=\firstdigitsequence\seconddigitsequence\relax
\message{%
TeX-count-register \string\mycountA\space has
value \the\mycountA
}
\showthe\mycountA

\setcounter{mycountB}{\seconddigitsequence\firstdigitsequence}
\message{%
LaTeX-counter `mycountB' has value \number\value{mycountB}%
}
\expandafter\showthe\csname c@mycountB\endcsname

\end{document}


Probably your question isn't about expansion but about
extraction of a former counter-value from a referencing-label?

If so, you can probably use Heiko Oberdiek's refcount-
package:


\documentclass{article}
\usepackage{refcount}
\newtheorem{lemma}{Lemma:}
\newtheorem{proof}{Proof:}

\begin{document}

\begin{lemma}\label{neighbors}
First blah, blah...
\end{lemma}

\begin{lemma}
Second blah, blah...
\end{lemma}

\begin{lemma}
Third blah, blah...
\end{lemma}

\begin{lemma}
Fourth blah, blah...
\end{lemma}

\newpage

% This will set the lemma-counter to 1---the value it had when
% the label occurred.
% Be aware that the environment will increment the counter by 1,
% thus the next lemma will have number 2.

\setcounterref{lemma}{neighbors}

% This will set the proof-counter to 1---the value the lemma-
% counter had when the label occurred.
% Be aware that the environment will increment the counter by 1,
% thus the next proof will have number 2.

\setcounterref{proof}{neighbors}

\begin{lemma}
Another first blah, blah...


\end{lemma}
\begin{proof}
...
\end{proof}

\end{document}


I recommend the refcount-package because it takes into
account several issues. E.g.,

1. In the first LaTeX-run, no aux-file is available yet, thus in
the first LaTeX-run no label is defined. In this case, \ref,
\pageref etc will not deliver numerical values but
(unexpandable) stuff like warning-messages and
question-marks which is not suitable for counter-
assignments.

2. When using the hyperref-package, \ref, \pageref etc won't
deliver only numerical values. In this case, these macros
also deliver non-numerical tokens/information for creating
a hyperlink from the reference.

Be aware that with this package you still might encounter
problems when the reference-text contains something else
than plain numbers.
You might encounter problems e.g.,
- in case a \the<counter>-macro delivers roman numerals.
- in case a \the<counter>-macro delivers a number separated
from another number by a dot.
- in case the \p@<counter>-macro associated to a <counter>
delivers non-mumerical tokens.


From time to time I stumbled over another issue which has to
do with resetting counters to former values:

Using the hyperref-package leads to usually getting a hyperref-
anchor placed automatically whenever a counter is incremented by
the \refstepcounter-macro. Hereby the name of that hyperref-
anchor is created automatically and in case a \label is placed,
the name of that anchor will be saved to the aux-file together
with all the other referencing-information.

(A common misunderstanding is that people think that hyperlink-
anchor-placement takes place when a \label is placed. But that's
wrong. Hyperlink-anchor-placement is independent from \label-
placement and takes place whenever a counter is \refstep'ped, e.g.,
via sectioning-commands like \chapter, \section, or within theorem-
like environments, or via the \caption-macro. The user can place
hyperlink-anchors "manually" via the \phantomsection-macro.)

The crucial point is:
For automatic hyperlink-anchor-name-creation both the name and
the value of the counter in question are used.

The effect is:
Resetting a counter to a former value might lead to automatic
creation of the same anchor-name more than once and at the end
of the pdf(e)TeX-run you will be informed about this by some
compiler-warning-messages about "destination with same
identifier...duplicate ignored...".
When running pdfLaTeX in pdf-mode on the following example, the
resulting .log-file will exhibit the problem:


\documentclass{article}
\usepackage{hyperref}


\newtheorem{lemma}{Lemma:}
\begin{document}

\begin{lemma}\label{firstlemma}
First...
\end{lemma}
\setcounter{lemma}{0}%
\begin{lemma}\label{otherfirstlemma}
Another first...
\end{lemma}
\noindent
This is reference to the first Lemma: \ref{firstlemma}

\noindent
This is reference to the other first Lemma: \ref{otherfirstlemma}
\end{document}


A solution to that problem is:

Above I wrote that both the name and the value of the counter
in question are used for automatic hyperlink-anchor-name-creation.
The value for hyperlink-anchor-name-creation is not delivered via
\the<counter> but via \theH<counter>. When resetting a counter
to a former value, you can ensure unique hyperlink-anchor-names
by temporarily redefinig \theH<counter>.

The following example exhibits the solution:


\documentclass{article}
\usepackage{hyperref}


\newtheorem{lemma}{Lemma:}
\begin{document}

\begin{lemma}\label{firstlemma}
First...
\end{lemma}
\begingroup
\setcounter{lemma}{0}%
\newcommand\savedtheHlemma{}%
\let\savedtheHlemma=\theHlemma
\renewcommand*\theHlemma{the-other-\savedtheHlemma}%
\begin{lemma}\label{otherfirstlemma}
Another first...
\end{lemma}
\endgroup
\noindent
This is reference to the first Lemma: \ref{firstlemma}

\noindent
This is reference to the other first Lemma: \ref{otherfirstlemma}
\end{document}


Ulrich

Edward M. Reingold

unread,
May 25, 2009, 10:53:07 AM5/25/09
to
>>>>> "UDiez" == Ulrich D i e z <eu_an...@web.de.invalid> writes:

UDiez> Probably your question isn't about expansion but about extraction
UDiez> of a former counter-value from a referencing-label?

Yes, exactly; so how could I reset, say the theorem number, so that the next
theorem environment would have the same theorem number as one that was
previously saved in a \label command with the numbers then continuing in
sequence from that point? At this point, I am just trying to learn something
new, not solve a real problem!

Ulrich D i e z

unread,
May 25, 2009, 2:53:50 PM5/25/09
to
Edward M. Reingold wrote:

> UDiez> Probably your question isn't about expansion but about extraction
> UDiez> of a former counter-value from a referencing-label?
>
> Yes, exactly; so how could I reset, say the theorem number, so that the next
> theorem environment would have the same theorem number as one that was
> previously saved in a \label command with the numbers then continuing in
> sequence from that point?

As I described in my last posting:

Extract the number from referencing the label in question
and use that extracted numerical value as an argument for
\setcounter. When resetting counters to former values
while using the hyperref-package, make sure that hyperref's
automatic hyperlink-anchor-name-generating-and-hyperlink-
anchor-placing-mechanism (which via \theH<counter> makes
use of counter-values) won't attempt to place two hyperlink-
anchors with the same name.

How extracting can be done differs - e.g., depending on the
hyperref-packege being loaded or not. [Therefore in my last
posting I recommended using Heiko Oberdiek's \refcount-
package for extracting numerical values from referencing-labels.]

The first source of information on how this extraction can be
done is the commented source to Heiko Oberdiek's refcount-
package because that package is designed for easing up the
task of doing exactly this.

But in order to understand what's going on there, you need
some knowledge about how referencing (\label, \ref etc) is
implemented in the LaTeX2e-kernel and in the hyperref-
package.

I think there should be a file source2e.pdf/source2e.dvi somewhere
on your system. That file contains the commented sources of the
LaTeX2e-kernel. (The kernel consists of a bundle of files,
source2e.pdf/dvi contains commented sources to all of them.)

If you want to learn about LaTeX2e-kernel-counter-management
(especially \refstepcounter and \p@<counter>, but implementation
of \newcounter etc is interesting also) , have a look at the section
about File m: ltcounts.dtx - 21 Counters and Lengths .

If you want to learn about the LaTeX2e-referencing-mechanism,
have a look at the section about File x: ltxref.dtx - 53 Cross Referencing .

Documentation/commented sources of the hyperref-package
might be of interest also.

>At this point, I am just trying to learn something
> new, not solve a real problem!

I got that moot point ;-)

The question is: Are you interested in implementation-details
or do you just want some sort of overview over the concepts
related to the issue?

Ulrich

Edward M. Reingold

unread,
May 26, 2009, 5:13:47 PM5/26/09
to
>>>>> "UDiez" == Ulrich D i e z <eu_an...@web.de.invalid> writes:

UDiez> The question is: Are you interested in implementation-details or do
UDiez> you just want some sort of overview over the concepts related to
UDiez> the issue?

Thanks for all the pointers! I suppose I would say that at this point I would
just like to see a bit of TeX code that I could put in a file to get what I
wanted--I finding studying expert's code is the way to learn the inside of a
language,

0 new messages