# How to dynamically number theorems?

I am writing an introduction. I want to reference theorems and so on which come later. I want to do something like the following.

\newtheorem*{thmcustom}[1]{Theorem #1}

Then \begin{thmcustom}[3.2.1] .. \end{thmcustom} would print out Thereom 3.2.1:... (In general I would have a \ref{thm:whatever} as opposed to the 3.2.1, but anyway.)

Of course, this doesn't work. Is there a way which I can do this?

(I have a hideous hack of doing \newtheorem*{thmA}{Theorem \ref{thm:thmA}} for each theorem I want to reference.

\documentclass[a4paper,10pt]{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\newtheorem*{thmA}{Theorem \ref{thm:thmA}}

\begin{document}
The same theorem which comes later:
\begin{thmA}
This is a theorem.
\end{thmA}

The original statement of the theorem.
\begin{theorem}
\label{thm:thmA}
This is a theorem.
\end{theorem}
\end{document}


This is awful! So anything will be better...)

-
What do you use to produce your theorems, since any working solution would have to be particular to the package. In fact, please provide a minimal working example (MWE)... that would be awesome. –  Werner Sep 26 '13 at 15:38
If you are using amsthm (or e.g. amsart, which loads amsthm automatically), with \newtheorem*{thmcustom}{Theorem}, then you can do \begin{thmcustom}[3.2.1] . . . \end{thmcustom} to get "Theorem (3.2.1)", which is an admittedly unsatisfactory solution that is at least easy. –  Charles Staats Sep 26 '13 at 15:49
I am using amsthm. –  user1729 Sep 26 '13 at 20:49
(And I have added in the requested example.) –  user1729 Sep 26 '13 at 20:59

## 1 Answer

Here's a (not so dirty) hack, based on the amsthm package. The theoremff environment is used for "fast-forward" theorems. The first (optional) argument is the theorem's name. The second argument is the theorem's label.

Notice that theorems are not dynamically numbered, I don't think you would want that! They are numbered as usual, but you are able to "fast-forward" some of them, using of course the same number that they will have later on. (Indeed, "fast-forward" is probably misleading, as you may equally well use this for theorems that have already appeared.) I hope I did not misinterpret your intentions.

\documentclass{article}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}
\newtheorem*{theoremaux}{Theorem \theoremauxnum}
\gdef\theoremauxnum{1}

\newenvironment{theoremff}[2][]{%
\def\theoremauxnum{\ref{#2}}
\begin{theoremaux}[#1]
}{%
\end{theoremaux}
}

\begin{document}

\section{Introduction}
Here are the two theorems that we will prove:

\begin{theoremff}[Progress]{thm:progress}
Progress theorem.
\end{theoremff}

\begin{theoremff}[Preservation]{thm:preservation}
Preservation theorem.
\end{theoremff}

\section{Metatheory}
And here are their proofs:

\begin{theorem}[Progress]
\label{thm:progress}
Progress theorem.
\begin{proof}
Easy.
\end{proof}
\end{theorem}

\begin{theorem}[Preservation]
\label{thm:preservation}
Preservation theorem.
\begin{proof}
Trivial.
\end{proof}
\end{theorem}

\end{document}


This is what you get for the document above.

-