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

Repeating theorems, again

26 views
Skip to first unread message

emanuel...@gmail.com

unread,
Jun 3, 2007, 5:07:04 PM6/3/07
to
Hi,

I have been using Ulrich's very useful package theomac.sty
(http://groups.google.com/group/comp.text.tex/browse_thread/thread/
c76e50961fbfc194/09e7f2229128f774?lnk=gst&q=putting
+proofs&rnum=1#09e7f2229128f774)
but there's a couple of things I would find *really* helpful and that
I can't quite do:

1) It would be nice to have an option for the repeated theorem not to
increase the counter,
but rather to display the original number followed by ", restated".
Would this be possible?

2) The "numbered_like" option does not seem to work: E.g.

\newtheorem{theorem}{Theorem}[section]
\newtheoremWithMacro{theoremR}[theorem]{Theorem}

gives an error when trying to repeat a theorem. I can make it work if
I add

\newcounter{theoremR}.

Thank you very much,
Emanuele

Enrico Gregorio

unread,
Jun 3, 2007, 6:55:38 PM6/3/07
to
<emanuel...@gmail.com> wrote:

\newtheorem{theorem}{Theorem}[section]
\newtheorem*{theoremRinner}{Theorem~\ref{\repthmref}, restated}
\newenvironment{theoremR}[1]
{\def\repthmref{#1}\theoremRinner}{\endtheoremRinner}

\begin{theorem}\label{important}
$1+1=2$.
\end{theorem}

Let's repeat the important Theorem~\ref{important}.

\begin{theoremR}{important}
$1+1=2$.
\end{theoremR}

Ciao
Enrico

emanuel...@gmail.com

unread,
Jun 3, 2007, 7:32:46 PM6/3/07
to
Thank you very much for the reply!, but unfortunately I think your
code would not be enough.
The code I pointed to in my previous message allows one to repeat
theorems
without repeating the body, while I think your code only lets you
repeat the reference number.
Would you know how to accomplish both/tweak the code
(http://groups.google.com/group/comp.text.tex/browse_thread/thread/
c76e50961fbfc194/09e7f2229128f774?lnk=gst&q=putting
+proofs&rnum=1#09e7f2229128f774) ?

Grazie,
Emanuele

Ulrich Diez

unread,
Jun 4, 2007, 3:58:46 AM6/4/07
to
Emanuele wrote:

> Hi,
>
> I have been using Ulrich's very useful package theomac.sty

[...]


> but there's a couple of things I would find *really* helpful and that
> I can't quite do:
>
> 1) It would be nice to have an option for the repeated theorem not to
> increase the counter,

Oops! That's indeed a bug related to the "numbered_like"-option.

The name of the theorem usually also forms the name of the associated
counter but not when using the [numbered_like]-option.
I overlooked that one. Sorry.
I think I resolved this in the new release below.

> but rather to display the original number followed by ", restated".
> Would this be possible?

Yes. I implemented an \if-switch "\ifrestated".
When the theorem gets restated, that switch is "true", otherwise it
is "false". Don't set the switch yourself but use an
\ifrestated...\else...\fi-construct for forking depending on whether
the theorem is restated or not.
I think you can use this switch
- within the theorem-environment's arguments
- within the theorem-environmnent's body
- when (re)defining or patching the \the<counter> macro which is
associated to the theorem's counter.

> 2) The "numbered_like" option does not seem to work: E.g.
>
> \newtheorem{theorem}{Theorem}[section]
> \newtheoremWithMacro{theoremR}[theorem]{Theorem}
>
> gives an error when trying to repeat a theorem. I can make it work if
> I add
>
> \newcounter{theoremR}.

Yes. With that option there was an attempt of using a counter which
doesn't exist. The reason is the same as above:
The name of the theorem usually also forms the name of the associated
counter but not when using the [numbered_like]-option.
I overlooked that one. Sorry.
I think I resolved this in the new release below.

Ulrich


% This is file `theomac.sty',
%
% The usage is explained after coding-stuff, right after
% "\endinput". This way you don't need all these percent-chars
% all the time...
%
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{amsmath}
\ProvidesPackage{theomac}
[2007/06/04 v1.00beta2 Define macros from theorems.]
%
% Find out how to catch the arguments - there are the following
% possibilities:
% - \newtheorem{env_name}[numbered_like]{caption}
% - \newtheorem{env_name}{caption}[within]
% - \newtheorem{env_name}{caption}
%
\newcommand*\newtheoremWithMacro[1]{%
\@ifnextchar[%
{\newtheoremwithmacrooptbrace{#1}}%
{\newtheoremwithmacrobraceopt{#1}}%
}%
\newcommand*\newtheoremwithmacrobraceopt[2]{%
\@ifnextchar[%
{\newtheoremwithmacrolastopt{#1}{#2}}%
{\newtheoremwithmacronolastopt{#1}{#2}}%
}%
%
% Depending on the order of the arguments, one of the following
% three macros is called for defining the theorem <foo> and
% afterwards calling "\@newtheoremWithMacro{<foo>}" for trans-
% forming that environment into one that catches up an additional
% optional argument for defining a macro which can henceforth be
% used for restating that theorem:
%
\@ifdefinable\newtheoremwithmacrooptbrace{%
\gdef\newtheoremwithmacrooptbrace#1[#2]#3{%
\newtheorem{#1}[#2]{#3}\@newtheoremWithMacro{#1}{#2}%
}%
}%
\@ifdefinable\newtheoremwithmacrolastopt{%
\gdef\newtheoremwithmacrolastopt#1#2[#3]{%
\newtheorem{#1}{#2}[#3]\@newtheoremWithMacro{#1}{#1}%
}%
}%
\@ifdefinable\newtheoremwithmacronolastopt{%
\gdef\newtheoremwithmacronolastopt#1#2{%
\newtheorem{#1}{#2}\@newtheoremWithMacro{#1}{#1}%
}%
}%
%
%"\@newtheoremWithMacro{<foo>}" "transforms" the theorem-environ-
% ment "<foo>" into one that catches up an additional optional
% argument for defining a macro which can henceforth be used for
% restating that theorem:
%
\newcommand\@newtheoremWithMacro[2]{%
% First "copy" the theorem-environment "<foo>" to the environ-
% ment "<foo>theorem":
\expandafter\@ifdefinable\csname #1theorem\endcsname{%
\expandafter\global
\expandafter\let
\csname #1theorem\expandafter\endcsname
\csname #1\endcsname
}%
\@ifundefined{end#1theorem}{%
\expandafter\global
\expandafter\let
\csname end#1theorem\expandafter\endcsname
\csname end#1\endcsname
}%
{%
\edef\reserved@a{%
\expandafter\expandafter
\expandafter\@gobble
\expandafter\string
\csname end#1theorem\endcsname
}%
\@notdefinable
}%
%
% Then define the macro "\@<foo>" to catch the first optional
% argument into the macro \@tempa and to start collecting the
% "body" of the environment into the token-register "\toks@"
% whereby a call to the former "<foo>"-theorem-environment
% which was saved in/copied to "<foo>theorem" must precede
% everything in order to make sure that a theorem is formed
% when later the token-register is "flushed":
%
\expandafter\@ifdefinable\csname @#1\endcsname{%
\expandafter\gdef\csname @#1\endcsname[##1]{%
\def\@tempa{##1}%
\collect@body\toks@{#1theorem}%
}%
}%
%
% Afterwards redefine the internal starter-macro of the
% "<foo>"-theorem-environment (and thus that environment it-
% self) to call the "\@<foo>"-macro and hereby supply an empty
% optional argument if no optional argument is provided:
%
\expandafter\gdef\csname #1\endcsname{%
\@ifnextchar[%
{\@tempswatrue\csname @#1\endcsname}%
{\@tempswafalse\csname @#1\endcsname[]}%
}%
% Redefine the internal-ending-macro of the "<foo>"-theorem-
% environment so that to the content of the token-register
% both the leading token "\begin" [Within the \collect@body-
% part there was inserted "{#1theorem}" -- Together this yields
% "\begin{#1theorem}" ] and a trailing phrase "\end{#1theorem}"
% get added. Afterwards flush the register once in order to
% print the theorem...
%
\expandafter\gdef\csname end#1\endcsname{%
\toks@\expandafter{%
\expandafter\begin
\the\toks@\end{#1theorem}}%
\the\toks@
% In case there was no optional argument, we have
% "\@tempswafalse".
% In case "\@tempa" is empty, the optional argument for
% defining the macro is empty. In both cases we don't need to
% define a "theorem-printing"-macro. Otherwise we have to.
% Then within "\@tempa" the name of that macro is stored so
% that "\@tempa" needs to be expanded once before defining
% can take place. The environment itself is within the
% token-register.
% All we have to do is making sure that
% - we always get the same value for the counter
% - the counter does not get stepped
% - label has no effect (otherwise: multiply defined
% references-errors!!!!!)
% whenever the theorem is restated:
\ifx\@tempa\@empty\@tempswafalse\fi
\if@tempswa
{%
\restatedtrue
\expandafter\edef
\csname the#2\endcsname{%
\csname the#2\endcsname
}%
\expandafter\@ifdefinable\@tempa{%
\expandafter\expandafter
\expandafter \gdef
\expandafter\@tempa
\expandafter{%
\expandafter\bgroup
\expandafter\restatedtrue
\expandafter\def
\csname the#2%
\expandafter\expandafter
\expandafter \endcsname
\expandafter\expandafter
\expandafter {%
\csname the#2%
\expandafter\endcsname
\expandafter}%
\expandafter\let
\expandafter\label
\expandafter\@gobble
\expandafter\let
\expandafter\refstepcounter
\expandafter\@gobble
\the\toks@
\egroup
}%
}%
}%
\fi
}%
}%
%
% The following switch is set true when a theorem is restated
% by calling the associated macro:
%
\@ifdefinable\ifrestated{%
\@ifdefinable\restatedfalse{%
\@ifdefinable\restatedtrue{%
\newif\ifrestated
\global\restatedfalse
}%
}%
}%

\endinput
%
Usage etc:
==========

change history
--------------

2006/07/29 v1.00beta1 - initial release
2007/06/04 v1.00beta2 - bugfix related to counter-management
with [numbered_like]-option.
if-switch "\ifrestated" which is "true"
when theorem is restated and otherwise
"false".
I think you can use this switch
- within the theorem-environment's
arguments
- within the theorem-environmnent's body
- when (re)defining or patching the
\the<counter> macro which is associated
to the theorem's counter.

legal stuff
-----------

theomac.sty - Copyright (C) 2006, 2007 by Ulrich Diez
(ulric...@alumni.uni-tuebingen.de)

theomac may be distributed and/or modified under the conditions
of the LaTeX Project Public Licence (LPPL), either version 1.3
of this license or (at your option) any later version. (The
latest version of this license is in:
http://www.latex-project.org/lppl.txt
and version 1.3 or later is part of all distributions of LaTeX
version 1999/12/01 or later.)
The author and Current Maintainer of this work is Ulrich Diez.
This work has the LPPL maintenance status 'maintained'.
Usage of theomac.sty is at your own risk.
There is no warranty - neither for the documentation nor for any
other part of theomac.sty. If something breaks, you usually may
keep the pieces.


What is it? / Acknowledgment / Intro:
-------------------------------------

The file theomac.sty is a package for LaTeX2e. It came into being
as a result of internet-discussion that took place at
comp.text.tex (usenet).
Subject: Restating Theorems
Initial posting in July 8 2006 by Louis Theran
(ID: 1152428341.7...@p79g2000cwp.googlegroups.com)

Special thanks to Ulrich M. Schwarz, Louis Theran, Michael
and Emanuele <emanuel...@gmail.com> for
their comments and for reporting problems and thus providing
important contributions to the making of this package.

The introducing-phrase in Louis Theran's initial posting:

...
> In longer papers, I like to state results in an early section
> and then restate them before the proof later on.
...

Usually you define theorem-like-environments by means of the
"\newtheorem"-macro.

theomac.sty provides a macro "\newtheoremWithMacro" which is
similar to "\newtheorem" but which creates environments which
also allow specifying an additional optional-argument which is
to hold the name of a newly to be defined control-sequence.
Internally these environments fork:

If optional argument is not supplied or supplied empty:
Simply create the theorem-text and hereby internally use an
environment defined in terms of "\newtheorem".

If optional argument is supplied a macro-name:
Additionally define a macro to spit out the theorem-text. (For
getting the environment-text into a defining-control-sequence's
argument, amsmath.sty's "\collect@body"-macro is used. I tried
to take care so that referencing-labels won't get defined more
than once and counters will be balanced correctly.)

If you wish to repeat/restate the theorem, you can do so by
simply calling that macro given in the optional argument when
stating it the first time.

"\newtheoremWithMacro" has the same syntax as "\newtheorem".

Difference is:

\newtheorem{foo}...

creates theorem-environment with syntax

\begin{foo} ... \end{foo}

________________________

\newtheoremWithMacro{foo}...

creates theorem(-like)-environment with syntax

\begin{foo}[\macro] ... \end{foo}

If you supply the optional-argument "\macro", you can later
repeat/restate your theorem-statement by calling "\macro".
"\macro" will be defined in terms of "\global".
If "\macro" is already defined, an error is raised.

Usage
-----

Possible syntax-patterns for "\newtheorem" are:

\newtheorem{env_name}[numbered_like]{caption}
\newtheorem{env_name}{caption}[within]
\newtheorem{env_name}{caption}

Possible syntax-patterns for "\newtheoremWithMacro"are the same:

\newtheoremWithMacro{env_name}[numbered_like]{caption}
\newtheoremWithMacro{env_name}{caption}[within]
\newtheoremWithMacro{env_name}{caption}

Syntax-patterns for a theorem "foo" defined in terms of
"\newtheorem" are:

\begin{foo}
This is my theorem
\end{foo}

\begin{foo}[Galois]
This is my theorem
\end{foo}

Syntax-patterns for a theorem "bar" defined in terms of
"\newtheoremWithMacro" are:

\begin{bar}
This is my theorem
\end{bar]

\begin{bar}[]
This is my theorem
\end{bar}
(But this is obsolete and yields the same as above!)

\begin{bar}[][Galois]
This is my theorem
\end{bar}

\begin{bar}[\macro][Galois]
This is my theorem
\end{bar}

\begin{bar}[\macro]
This is my theorem
\end{bar}

The last two variants also define "\macro" to restate the
theorem.

Restrictions
------------

A noteworthy restriction is:
"Verbatim" is broken within the body of environments that are
defined in terms of "\newtheoremWithMacro".

This is because amslatex' "\collect@body" will read ahead and
tokenize the whole stuff before catcode-changes of verbatim-
environment get into effect.

E.g., the following code does work as expected...

\newtheorem{foo}...
...
\begin{foo}
\begin{verbatim}
\TeX is funny.
\end{verbatim}
\end{foo}

...while this one does not:

\newtheoremWithMacro{bar}...
...
\begin{bar}
\begin{verbatim}
\TeX is funny.
\end{verbatim}
\end{bar}


Usage-Example:
--------------

\documentclass{article}
\usepackage{theomac}
\usepackage{hyperref}

\newtheorem{theorem}{Theorems Caption}[section]
\newtheoremWithMacro{Mytheorem}[theorem]{My Theorem}
%\newtheoremWithMacro{Mytheorem}{My Theorem}[section]
\makeatletter
\g@addto@macro\thetheorem{\ifrestated, restated\fi}%
%\g@addto@macro\theMytheorem{\ifrestated, restated\fi}%
\makeatother

\begin{document}

\section{test}

\begin{Mytheorem}[\firsttheorem][Not Galois]%
This is my first theorem.
\label{firsttheoremsfirstocurrence}%
\end{Mytheorem}

Let's restate the first theorem: \firsttheorem

\begin{Mytheorem}[\secondtheorem][Not Galois]
This is my second theorem.
\end{Mytheorem}

\begin{Mytheorem}
This is my third theorem.
\end{Mytheorem}

Let's restate the first theorem: \firsttheorem

\newpage

\section{test}

\begin{Mytheorem}
This is my fourth theorem.
\end{Mytheorem}

Let's restate the first theorem: \firsttheorem

\begin{Mytheorem}
This is my fifth theorem.
\end{Mytheorem}

This is page-reference to the page where my first theorem
occurred the first time: \pageref{firsttheoremsfirstocurrence}%

This is reference to the number of my first theorem---the
hyperlink goes to the place where the theorem was stated
the first time: \ref{firsttheoremsfirstocurrence}%

\end{document}

%
%% End of file `theomac.sty'.

theomac.sty

emanuel...@gmail.com

unread,
Jun 4, 2007, 9:59:22 AM6/4/07
to
Thank you so much! This is really helpful!

Emanuele

0 new messages