athm and aproof

Convenient theorem and proof environments

The following code defines two environments, athm and aproof. They automatically add the Proof of ... heading at the start of the proof and the sentence The proof of ... is thus complete at the end. They also enable use of the \llabel and \lref commands.

Code for the athm and aproof environments
\ExplSyntaxOn

\NewDocumentEnvironment {athm} {m m o} {
\str_if_eq:noTF {example} {#1} {
  \bool_gset_true:N \g_example_bool
} {
  \bool_gset_false:N \g_example_bool
}
\IfNoValueTF{#3}{
\begin{#1}\label{#2}\global\def\loc{#2}
}{
\begin{#1}[#3]\label{#2}\global\def\loc{#2}
}
}{
\end{#1}
}

\NewDocumentEnvironment {adef} {m} {
\begin{definition}\label{#1}\global\def\loc{#1}
}{
\end{definition}
}

\NewDocumentEnvironment{aproof} {} {
\bool_if:NTF \g_example_bool {
  \begin{proof}[Proof~for~\cref{\loc}]
} {
  \begin{proof}[Proof~of~\cref{\loc}]
}
\bool_gset_false:N \g_finishproof_bool
}{
\bool_if:NTF \g_finishproof_bool {}
{\finishproofthus}
\end{proof}
}

\NewDocumentCommand{\finishproofthus} {} {
  \bool_gset_true:N \g_finishproof_bool 
  \bool_if:NTF \g_example_bool {
    The~proof~for~\cref{\loc}~is~thus~complete.
  } {
    The~proof~of~\cref{\loc}~is~thus~complete.
  }
}
\NewDocumentCommand{\finishproofthis} {} {
  \bool_gset_true:N \g_finishproof_bool 
  \bool_if:NTF \g_example_bool {
    This~completes~the~proof~for~\cref{\loc}.
  } {
    This~completes~the~proof~of~\cref{\loc}.
  }
}

\ExplSyntaxOff

The athm environment takes two or three arguments,

  • the name of the theorem environment to use,
  • the label of the environment, and
  • (optionally) the title of the theorem.

The first argument must be the name of an environment that has been defined separately, e.g., with the standard \newtheorem command from the amsthm package.

The aproof environment takes no arguments.

The code above also supplies two commands, \finishproofthus and \finishproofthis, which expand to The proof of ... is thus complete and This completes the proof of ..., respectively (automatically inserting the name of the result currently being proved). If neither of these two commands is used throughout an aproof environment, the sentence The proof of ... is thus complete is inserted at the end of the proof.

Here is an example that illustrates how these commands work:

\begin{athm}{lemma}{lem:important}[An important lemma] 
  Let $a,b\in\Z$ be odd. 
  Then $a+b$ is even. 
\end{athm} 
\begin{aproof}
  Throughout this proof, let $u,v\in\Z$ satisfy 
  \begin{equation}
    \llabel{eq:1} 
    a=2u+1 \qquad\text{and}\qquad b=2v+1.
  \end{equation} 
  \Nobs that \lref{eq:1} \proves that $a+b=(2u+1)+(2v+1)=2(u+v+1)$. 
  \Hence that $a+b$ is even.
\end{aproof}
Lemma 1 (An important lemma). Let $a,b\in\mathbb Z$ be odd. Then $a+b$ is even.
Proof of Lemma 1. Throughout this proof, let $u,v\in\mathbb Z$ satisfy $$a=2u+1\qquad \text{and} \qquad b=2v+1. \tag{1}$$ Note that (1) ensures that $a+b=(2u+1)+(2v+1)=2(u+v+1)$. Hence, we obtain that $a+b$ is even. The proof of Lemma 1 is thus complete.

Unless otherwise noted, all LaTeX snippets on this site are released under the Zero-Clause BSD (0BSD) license. You may copy them into your documents without attribution or including any license. No warranty.