0

In the following, three issues:

  1. How can I allow the enumerated list in the "1.1 Examples (some examples), continued" to begin its item "2. ..." on the same line as the header/note, just like for the original 1.1 Examples (some examples)"?
  2. How can one eliminate the \hspace{-1.5pt} kludge in the value of the name key for the exscont theorem declaration? Without it, there is indeed about a 1.5 extra horizontal space between the head "1.1 Examples" and the note "(some examples)" in the continuouation.
  3. Why is the \savenum/\backnum ruse needed to resume numbering items? (Using instead the commented-out option [resume*] does not actually resume numbering!)

Note: I show all the cross-referencing stuff because I need that to work still after any fix for those issues. (So I apologize for not totally minimizing the example.)

\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{enumitem}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor=red}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\usepackage{crossreftools}

\newcommand{\crefexsname}[1]{\crtrefname{#1}}

\swapnumbers
\declaretheorem[name=theorem,numberwithin=chapter]{theorem}

\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\mdseries\sffamily,
  bodyfont=\mdseries,
]{exsstyle}
\declaretheorem[
  name=Examples,
  style=exsstyle,
  numberlike=theorem,
  preheadhook=\renewcommand{\qedsymbol}{$\diamond$}\pushQED{\qed},
  postfoothook=\popQED
  ]
{examples}
\counterwithin{examples}{chapter}

% To continue Examples environment:
\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={},
  postheadspace=0.5em,
  notefont=\mdseries\sffamily,
  bodyfont=\mdseries,
]{exscontstyle}
\declaretheorem[
  style=exscontstyle,
  name=\protect\continuation\space Examples\hspace{-1.5pt}, %\hspace kludge!
  unnumbered,
  preheadhook=\renewcommand{\qedsymbol}{$\diamond$}\pushQED{\qed},
  postfoothook=\popQED
]{exscont}
% From egreg's https://tex.stackexchange.com/a/430720/13492:
\newcommand{\continuation}{??}
\newenvironment{continueexamples}[1]
 {\renewcommand{\continuation}{\ref*{#1}}\exscont{\sffamily(\crefexsname{#1}), continued.}}
 {\endexscont}

% To resume enumerate after continuation:
\newcounter{savenum}
\newcommand{\savenum}[1]{\setcounter{savenum}{\value{#1}}}
\newcommand{\backnum}[1]{\setcounter{#1}{\value{savenum}}}

\crefname{continuedexamples}{Examples}{Examples}

\crefname{enumi}{}{} % do not use ``Item''

% Cross-referencing enumerated items within Examples:
\newcommand{\crefex}[2]{\hyperref[#2]{\namecref{#1}~\labelcref*{#1}~(\ref*{#2})}}
\newcommand\crefrangeex[3]{\cref{#1}~\crefrange{#2}{#3}}
\crefrangeformat{enumi}{\textup{(}#3#1#4\textup{)}--\textup{(}#5#2#6\textup{)}}

\begin{document}

\mainmatter
\chapter{A chapter}

\begin{examples}[some examples]\label{exmpls}
    \begin{enumerate}
        \item\label{exs:first} A first example.
        \savenum{enumi}
    \end{enumerate}
\end{examples}

\begin{continueexamples}{exmpls}
    \begin{enumerate}%[resume*]
        \backnum{enumi}
        \item\label{exs:second} Another example\qedhere
    \end{enumerate}
\end{continueexamples}

See \cref{exmpls}. 

In particular see \crefex{exmpls}{exs:first} and  \crefex{exmpls}{exs:second}.
In other words, see \crefrangeex{exmpls}{exs:first}{exs:second}.

\end{document}

continued examples enviroment

Related: https://tex.stackexchange.com/a/430720/13492, https://tex.stackexchange.com/a/125140/13492

1 Answer 1

1

To continue a theorem, you can use the continues key of thmtools. It takes as value the label of a previous theorem. The displayed text can be customized by redefining the \thmcontinues command, but to get the format in your MWE I defined a new key mycontinues that slightly abuses the headpunct key. This fixes issues 1 and 2. Note that 1 was due to your adding text after the beginning of the theorem. It's the same as if you wrote

\begin{theorem} some text
\begin{enumerate}

For issue 3, note that in the enumitem documentation it says, referring to the resume key,

This is done locally. If you want global resuming, see next section on series.

So to escape the group created by the theorem environment, you have to manually set the series=<name> then call resume*=<name>.

Here's your example with these changes.

\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{enumitem}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor=red}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\usepackage{crossreftools}

\makeatletter
\newif\ifthmtoolsiscontinuing
\thmt@define@thmuse@key{mycontinues}{%
  \thmt@suspendcounter{\thmt@envname}{\thmt@trivialref{#1}{??}}%
  \thmtoolsiscontinuingtrue
}
\makeatother

\newcommand{\crefexsname}[1]{\crtrefname{#1}}

\swapnumbers
\declaretheorem[name=theorem,numberwithin=chapter]{theorem}

\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={%
    \ifthmtoolsiscontinuing
      \mdseries,\ continued.
      \else
      .
      \fi
    },
  postheadspace=0.5em,
  notefont=\mdseries\sffamily,
  bodyfont=\mdseries,
]{exsstyle}
   
\declaretheorem[
  name=Examples,
  style=exsstyle,
  numberlike=theorem,
  qed=$\diamond$ % easier than adding to hooks
  ]
{examples}
\counterwithin{examples}{chapter}

\crefname{enumi}{}{} % do not use ``Item''

% Cross-referencing enumerated items within Examples:
\newcommand{\crefex}[2]{\hyperref[#2]{\namecref{#1}~\labelcref*{#1}~(\ref*{#2})}}
\newcommand\crefrangeex[3]{\cref{#1}~\crefrange{#2}{#3}}
\crefrangeformat{enumi}{\textup{(}#3#1#4\textup{)}--\textup{(}#5#2#6\textup{)}}

\begin{document}

\mainmatter
\chapter{A chapter}

\begin{examples}[some examples]\label{exmpls}
    \begin{enumerate}[series=myenum]
        \item\label{exs:first} A first example.
    \end{enumerate}
\end{examples}

\begin{examples}[mycontinues=exmpls,name=some examples]
    \begin{enumerate}[resume*=myenum]
        \item\label{exs:second} Another example\qedhere
    \end{enumerate}
\end{examples}

See \cref{exmpls}. 

In particular see \crefex{exmpls}{exs:first} and  \crefex{exmpls}{exs:second}.
In other words, see \crefrangeex{exmpls}{exs:first}{exs:second}.

\end{document}

thms


To get the format "1.1 Example, continued (some examples)", you can use the headformat key. As this interacts poorly with \swapnumbers, I've defined a command \unswapnumbers that you can call before declaring a theorem to cancel the swap effect.

\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{enumitem}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor=red}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\usepackage{crossreftools}

\makeatletter
\newcommand\unswapnumbers{\def\thm@swap{N}}
\newif\ifthmtoolsiscontinuing
\thmt@define@thmuse@key{mycontinues}{%
  \thmt@suspendcounter{\thmt@envname}{\thmt@trivialref{#1}{??}}%
  \thmtoolsiscontinuingtrue
}
\makeatother

\newcommand{\crefexsname}[1]{\crtrefname{#1}}

\swapnumbers
\declaretheorem[numberwithin=chapter]{theorem}

\unswapnumbers

\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\mdseries\sffamily,
  bodyfont=\mdseries,
  headformat={%
    \NUMBER\ \NAME%
    \ifthmtoolsiscontinuing
      \mdseries,\ continued%
    \fi
    \NOTE%
    }
]{exsstyle}
   
\declaretheorem[
  name=Examples,
  style=exsstyle,
  numberlike=theorem,
  qed=$\diamond$ % easier than adding to hooks
  ]
{examples}
\counterwithin{examples}{chapter}

\crefname{enumi}{}{} % do not use ``Item''

% Cross-referencing enumerated items within Examples:
\newcommand{\crefex}[2]{\hyperref[#2]{\namecref{#1}~\labelcref*{#1}~(\ref*{#2})}}
\newcommand\crefrangeex[3]{\cref{#1}~\crefrange{#2}{#3}}
\crefrangeformat{enumi}{\textup{(}#3#1#4\textup{)}--\textup{(}#5#2#6\textup{)}}

\begin{document}
\mainmatter
\chapter{A chapter}

\begin{examples}[some examples]\label{exmpls}
    \begin{enumerate}[series=myenum]
        \item\label{exs:first} A first example.
    \end{enumerate}
\end{examples}

\begin{examples}[mycontinues=exmpls,name=some examples]
    \begin{enumerate}[resume*=myenum]
        \item\label{exs:second} Another example\qedhere
    \end{enumerate}
\end{examples}

See \cref{exmpls}. 

In particular see \crefex{exmpls}{exs:first} and  \crefex{exmpls}{exs:second}.
In other words, see \crefrangeex{exmpls}{exs:first}{exs:second}.

\begin{theorem}
Some theorem text
\end{theorem}

\end{document}
7
  • Using the continues key like that does not give the heading/note format I want, at least with my attempt \renewcommand{\thmcontinues}[1]{continued}, which produces "1.1 Examples (some examples, continued )." [including the unexpected space between "d" and ")"] rather than my original desideratum "1.1 Examples, continued (some examples)." or even, almost as good, "1.1 Examples (some examples), continued." Somhow the thmtools command \thmt@define@thmuse@key{continues} has to be renewed, but I don't, at least yet, see how
    – murray
    Nov 29, 2023 at 2:14
  • @murray See update, I defined a new key but you can overwrite continues exactly the same way
    – mbert
    Nov 29, 2023 at 4:01
  • @murray The format "1.1 Examples, continued (some examples)." can be achieved with the headformat key in a similar way but it doesn't interact well with \swapnumbers so if you wanted the swapped numbered with other theorems you'd have to define a new theorem style with the key headformat=swapnumber
    – mbert
    Nov 29, 2023 at 4:08
  • May I still use \swapnumbers for the many other theorem-like environments my actual document uses? And even without that, I tried, e.g., to add to \declarethmstyle the key headformat={\NUMBER\hspace{0.25em}\NAME~\NOTE)} (along with \renewcommand{\thmcontinues}[1]{continued), but that still puts the "continued" within the note. So I don't understand how to use headformat` here, and the docs do not give even a single example! Moreover, supplying such code as value of headformat would seem to exclude supplying swapnumber. So how to implement the fix with headformat?
    – murray
    Nov 29, 2023 at 15:44
  • @murray see edit
    – mbert
    Nov 29, 2023 at 16:35

You must log in to answer this question.

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