# Restate a theorem before stating it

I plan to include as a preface of a dissertation (I am using cleanthesis) an extended abstract with the statements (theorems, propositions, etc.) of the main results.

I would like them to appear in the extended abstract with the same numbering (chapter.section.environment) and linked to the original statement within the dissertation. That is, I want an exact copy of the statements in the preamble except for the link to the original one.

After some research I found that the thm-restate package of thmtools offers this feature. The problem is that I need to keep the original statement within the main dissertation; that is, I need the call to appear "before" the original statement, and I get a compilation error: "! Undefined control sequence."

How can I fix this issue?

(I don't know whether this is relevant, but the document is split into different files: essentially, the first one corresponding to the preamble, and then one for each chapter.)

• Isn't the 'real' statement of the theorem actually the 2nd one then, i.e. the 'restating' and the first appearence in the abstract the 'Stating'? – user31729 Mar 2 '17 at 23:51
• Christian, sure you can (also) state in this way, but I think that the problem remains the same. The point is that I need the call before the real statement, and I prefer to keep the original code unchanged. – suitangi Mar 2 '17 at 23:55
• How about storing the theorem in a box first, then use the box twice, the 2nd time you have to decrease the theorem counter manually, otherwise the number would by too large by one. – user31729 Mar 2 '17 at 23:57
• Well, as long as you don't show any line of code and a compilable document the possibility of answering your request is quite limited – user31729 Mar 3 '17 at 9:21
• Then your question remains unclear... I won't post a possible solution for code that mustn't be changed, based on assumptions and getting complaints about later on, like ... "...but in my code I have X and not Y" ... – user31729 Mar 3 '17 at 9:29

## 2 Answers

This is the simplest way, in my opinion: the statement is typed in at the first appearance.

\documentclass{book}

\usepackage{environ}

\newtheorem{theorem}{Theorem}[chapter]

\NewEnviron{restatethis}[1]{%
% #1 (mandatory): a label
\expandafter\xdef\csname restatethis@#1\endcsname{%
\unexpanded\expandafter{\BODY}%
}%
\renewcommand{\thetheorem}{\ref{#1}}%
\begin{theorem}\BODY\end{theorem}%
}
\newcommand{\restate}[1]{%
\begin{theorem}\label{#1}\csname restatethis@#1\endcsname\end{theorem}%
}

\begin{document}

\frontmatter

\chapter{Introduction}

This is the introduction, where we have a theorem

\begin{restatethis}{main}
This is the main theorem in the thesis.
\end{restatethis}

\mainmatter

\chapter{Main result}

Here we prove our main theorem.

\restate{main}

\end{document}


Alternative solution where the statement of the theorem is in the body.

\documentclass{book}

\usepackage{environ}

\newtheorem{theorem}{Theorem}[chapter]

\makeatletter
\NewEnviron{restatethis}[1]{%
% #1 (mandatory): a label
\protected@write\@auxout{}{%
\string\@restatetheorem{#1}{\detokenize\expandafter{\BODY}}%
}%
\begin{theorem}\label{#1}\BODY\end{theorem}%
}
\newcommand{\@restatetheorem}[2]{%
\expandafter\gdef\csname restatethis@#1\endcsname{#2}%
}
\newcommand{\restate}[1]{%
\begingroup
\renewcommand{\thetheorem}{\ref{#1}}%
\begin{theorem}\csname restatethis@#1\endcsname\end{theorem}%
\endgroup
}
\makeatother

\begin{document}

\frontmatter

\chapter{Introduction}

This is the introduction, where we have a theorem

\restate{main}

\mainmatter

\chapter{Main result}

Here we prove our main theorem.

\begin{restatethis}{main}
This is the main theorem in the thesis.
\end{restatethis}

\end{document}

• Thank you @egreg (+1), but for me it is crucial to have the statement typed in the corresponding chapter (to use the code without the preface; and even, every chapter as a particular isolated paper). – suitangi Mar 3 '17 at 10:00
• @suitangi Added. – egreg Mar 3 '17 at 10:02
• It works fine, but can this be done (using thm-restate package of thmtools?) keeping the original theorem/proposition,etc environment? (This is convenient because: (a) the restate command should recognize the environment type, and (b) the chapter code could be easily reused by collaborators). – suitangi Mar 3 '17 at 10:28
• @suitangi The interface might be improved; but no, it cannot be done with thm-restate that assumes the restatement appears later. – egreg Mar 3 '17 at 10:36

I've been using a slightly modified version of @egreg's code so I thought I would put it here. It is set up to work very similarly to the mathtools environment restatable. This works correctly with (the current versions of) amsthm, ntheorem, and mathtools.

Annoyingly, if you number two theorem environments together using the standard theorem packages, \newtheorem defines \thecorollary but uses \thetheorem when numbering corollaries so redefining \thecorollary doesn't change the numbering at all. In this case, I have to look inside of the definition of \corollary to figure out which macro hods the corollary number. The package mathtools fix this defect, so if it is loaded, it suffices to redefine \thecorollary.

\documentclass{article}
\usepackage{environ}

\newtheorem{thm}{Theorem}[section]
\newtheorem{cor}[thm]{Corollary}
\makeatletter
\long\def\@secondofthree#1#2#3{#2}
\long\def\@thirdoffour#1#2#3#4{#3}

% #1 -- theorem type
% #2 -- name
\NewEnviron{restatethis}[2]{%
\begin{#1}%
\BODY
% Do the write inside the body of the theorem environment because if I do it afterwards it messes
% up the spacing for some strange reason...
\protected@write\@auxout{}{%
\string\@restatetheorem{#1}{#2}{\csname the#1\endcsname}{\detokenize\expandafter{\BODY}}%
}%
\end{#1}%
}

% Figure out which macro to redefine to change the numbering.
% Easy if thmtools is loaded, otherwise we have to extract the name from some macro.
% This will break if some jerk loads thmtools and then ntheorem.
\@ifpackageloaded{thmtools}{%
% just use the name of the environment
\def\restatethm@getthmcountercsname#1{\def\thethmcsname{#1}}%
}{%
\@ifpackageloaded{ntheorem}{%
% extract the right macro from \mkheader@thmtype -> ???? \@thm{environmentname}{numberwithname}{thmname}
\def\restatethm@getthmcountercsname#1{%
\def\thethmcsname{\expandafter\expandafter\expandafter\restatethm@ntheorem@getthmcountercsname@helper\csname mkheader@#1\endcsname}}%
\def\restatethm@ntheorem@getthmcountercsname@helper#1\@thm#2#3#4{#3}
}{%
\@ifpackageloaded{amsthm}{%
% extract the right macro from \thmtype -> \@thm{????}{numberwithname}{thmname} (it's the third thing)
\def\restatethm@getthmcountercsname#1{\edef\thethmcsname{\expandafter\expandafter\expandafter\@thirdoffour\csname#1\endcsname}}%
}{%
% extract the right macro from \thmtype -> \@thm{numberwithname}{thmname} (it's the second thing)
\def\restatethm@getthmcountercsname#1{\edef\thethmcsname{\expandafter\expandafter\expandafter\@secondofthree\csname#1\endcsname}}%
}%
}%
}

% #1 -- environment type
% #2 -- name for restating
% #3 -- number
% #4 -- content
\newcommand{\@restatetheorem}[4]{%
\expandafter\gdef\csname restatethis@#2\endcsname{%
\begingroup
% First we have to set the numerical label to the right value.
\restatethm@getthmcountercsname{#1}
\expandafter\def\csname the\thethmcsname\endcsname{#3}%
% Print the theorem
\begin{#1}#4\end{#1}%
\endgroup
}%
}
\newcommand{\restate}[1]{\csname restatethis@#1\endcsname} % Just use the stored macro
\makeatother

\begin{document}

\section{Introduction}

This is the introduction, where we restate some theorems:

\restate{main}

\restate{acorollary}

\section{Main result}

Here we prove our main theorem.
\begin{restatethis}{thm}{main}
This is the main theorem in the thesis.
\end{restatethis}
\begin{restatethis}{cor}{acorollary}
This is a corollary.
\end{restatethis}

\end{document}