2

When using amsthm, I want to be able to continue a particular theorem-like environment (in my case, an example) later. The continued environment should have the same number as the one it continues from earlier; and after the continued environment is finished, normal theorem numbering should resume.

The following accomplishes what I want. Is there a simpler or otherwise better way -- without having to stray below LaTeX into pure TeX?

% continue-thm.try
\documentclass[12pt]{article}

\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\theoremstyle{definition}
\newtheorem{example}[theorem]{Example}

\newcounter{savedthmcounter}
\newcounter{tobecontinuedthmcounter}

% Invoke \tobecontinued immediately AFTER theorem to be continued
\newcommand{\tobecontinued}{%
    \setcounter{tobecontinuedthmcounter}{\value{theorem}}%
    \addtocounter{tobecontinuedthmcounter}{-1}}
% Invoke \continue immediately BEFORE continuing theorem that was to be continued
\newcommand{\continue}{%
    \setcounter{savedthmcounter}{\value{theorem}}%
    \setcounter{theorem}{\value{tobecontinuedthmcounter}}}
% Invoke immediately AFTER done with the continued theorem
\newcommand{\resume}{\setcounter{theorem}{\value{savedthmcounter}}}

\begin{document}

\begin{theorem}% 1
Theorem 1.
\end{theorem}

\begin{example}% 2
\label{ex:ex2}
An example.
\end{example}
%
\tobecontinued

\begin{theorem}% 3
Theorem 3.
\end{theorem}

\begin{theorem}%4
Theorem 4.
\end{theorem}

\begin{proposition}
A proposition.
\end{proposition}

\continue
%
\begin{example}[continued]% 2 again
Example \ref{ex:ex2}, continued.
\end{example}

\resume

\begin{theorem}% 5
Theorem 5.
\end{theorem}

\end{document}

Continue an earlier theorem, then resume normal numbering.

Added

The preceding method works not just for amsthm with article, etc., but also when I use thmtools and then \declaretheoremstyle and \declaretheorem(and, as it happens, with the memoir class that I'm using).

How do I invoke the thmtools package's \declaretheoremstyle and \declaretheorem (with memoir) so as to adapt the proposed answers -- and most especially egreg's answer?

Update: If the theorem-like environment to be continued already has a note (i.e., from something like \begin{example}[some text]), then a method different from the above and from the accepted answer, below, seems to be required. One such method is shown in https://tex.stackexchange.com/a/702575/13492.

2 Answers 2

4

I don't think you need such a complex framework: I can only think to continuation of examples.

\documentclass[12pt]{article}

\usepackage{amsthm}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}

\theoremstyle{definition}
\newtheorem{example}[theorem]{Example}
\newtheorem*{excont}{Example \continuation}
\newcommand{\continuation}{??}
\newenvironment{continueexample}[1]
 {\renewcommand{\continuation}{\ref{#1}}\excont[continued]}
 {\endexcont}

\begin{document}

\begin{theorem}% 1
Theorem 1.
\end{theorem}

\begin{example}% 2
\label{ex:ex2}
An example.
\end{example}

\begin{theorem}% 3
Theorem 3.
\end{theorem}

\begin{theorem}%4
Theorem 4.
\end{theorem}

\begin{proposition}
A proposition.
\end{proposition}

\begin{continueexample}{ex:ex2}
Example \ref{ex:ex2}, continued.
\end{continueexample}

\begin{theorem}% 5
Theorem 5.
\end{theorem}

\end{document}

Just give a \label to the example you want to continue and use it as the argument to continueexample.

enter image description here

With thmtools it's no different, just remember to use \protect\continuation.

\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{thmtools}

\declaretheoremstyle[
  bodyfont=\upshape,
]{upshape}

\declaretheorem[
  name=Theorem,
  within=section,
]{theorem}
\declaretheorem[
  name=Proposition,
  sibling=theorem,
]{proposition}
\declaretheorem[
  style=upshape,
  name=Example,
  sibling=theorem,
]{example}
\declaretheorem[
  style=upshape,
  name=Example \protect\continuation,
  unnumbered,
]{excont}
\newcommand{\continuation}{??}
\newenvironment{continueexample}[1]
 {\renewcommand{\continuation}{\ref{#1}}\excont[continued]}
 {\endexcont}


\begin{document}

\begin{theorem}% 1
Theorem 1.
\end{theorem}

\begin{example}% 2
\label{ex:ex2}
An example.
\end{example}

\begin{theorem}% 3
Theorem 3.
\end{theorem}

\begin{theorem}%4
Theorem 4.
\end{theorem}

\begin{proposition}
A proposition.
\end{proposition}

\begin{continueexample}{ex:ex2}
Example \ref{ex:ex2}, continued.
\end{continueexample}

\begin{theorem}% 5
Theorem 5.
\end{theorem}

\end{document}
4
  • How do I invoke the thmtools package's \declaretheoremstyle and \declaretheorem (with memoir) so as to adapt your very nice answer that works with amsthm alone?
    – murray
    May 9, 2018 at 17:52
  • @murray Added the thmtools version.
    – egreg
    May 9, 2018 at 21:44
  • I'm using a \newenvironment for my examples (where I place the examples between two horizontal lines, and adjust margins etc). I was not able to adjust your first solution to use the same environment for all examples. Is it possible to do that?
    – user144410
    Jul 18, 2019 at 9:06
  • @user144410 Please, open a new question with all the needed details.
    – egreg
    Jul 18, 2019 at 9:08
0

Based on https://tex.stackexchange.com/a/311985/36296 you could create a new environment which automatically get the previous example number from the label and resets it after your continued example. This will

  • save you from having to manually add \tobecontinued, \continue and \resume

  • works for every example, not just the last one marked with \tobecontinued


% continue-thm.try
\documentclass[12pt]{article}

\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\theoremstyle{definition}
\newtheorem{example}[theorem]{Example}

\newcounter{savedthmcounter}
\newcounter{tobecontinuedthmcounter}

\makeatletter
\def\@extractthmnum#1.#2{#2}
\newcommand{\extractthmnum}[2]{% \extractthmnum{<cnt>}{<ref>}
  \setcounter{#1}{0}% Default
  \ifcsname r@#2\endcsname
    \edef\@tempa{\csname r@#2\endcsname}% Extract complete reference
    \edef\@tempa{\expandafter\@firstoftwo\@tempa}% Extract number
    \setcounter{#1}{\expandafter\@extractthmnum\@tempa}% Strip number
  \fi
}
\makeatother

\newenvironment{excont}[1][]{
    \extractthmnum{tobecontinuedthmcounter}{#1}
    \addtocounter{tobecontinuedthmcounter}{-1}
     \setcounter{savedthmcounter}{\value{theorem}}
    \setcounter{theorem}{\value{tobecontinuedthmcounter}}
    \begin{example}[continued]
}{
\end{example}
\setcounter{theorem}{\value{savedthmcounter}}
}

\begin{document}

\begin{theorem}% 1
Theorem 1.
\end{theorem}

\begin{example}% 2
\label{ex:ex2}
An example.
\end{example}


\begin{theorem}% 3
Theorem 3.
\end{theorem}

\begin{theorem}%4
Theorem 4.
\end{theorem}

\begin{proposition}
A proposition.
\end{proposition}

\begin{excont}[ex:ex2]% 2 again
Example \ref{ex:ex2}, continued.
\end{excont}


\begin{theorem}% 5
Theorem 5.
\end{theorem}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .