[Tex/LaTex] Local equation numbering inside proofs

countersenvironmentsequationsnumbering

According to the question asked here and a possible suggestion to the problem which equations should be numbered given here I want to ask following question;

I find it a good solution to number all equations outside a proof-environment for a later reference option. I also share the opinion that equations inside a proof only have a local character, which do not need a global numbering. But I think one is limited to manually use \tag{$\ast$} on those equations inside a proof which one refers to. In case one restructures a proof, one has to manually change all tags and on the other hand I think it looks silly to have an equation tagged with (****).

Therefore I would like to know if it is possible to have a local equation numbering only for the proof-environment, i.e. to achieve a local numbering inside proofs for equations for which one refers to inside a proof. The numbering should start for every proof from the beginning in alphabetical style (a), (b), (c) and so on and to have a global counter outside proofs.

I guess there might exist some complications since I use cleverref. So it would be good to have a solution to this problem compatible to cleverref. Furthermore I would like to use all typical formula environments like equation, align, gather etc. just with a local counter inside proofs.

Best Answer

You can make temporary redefitions at the beginning and end of environment with the help of hooks provided by the etoolbox package. So a first attempt is:

Sample output

\documentclass{article}

\usepackage{mathtools,amsthm,etoolbox,cleveref}

\newtheorem{theorem}{Theorem}

\newcounter{equationstore}
\AtBeginEnvironment{proof}{\setcounter{equationstore}{\value{equation}}
\setcounter{equation}{0}\renewcommand{\theequation}{\alph{equation}}}
\AtEndEnvironment{proof}{\setcounter{equation}{\value{equationstore}}}

\begin{document}

\begin{equation}
  \label{eq:one}
  x = 1
\end{equation}

\begin{theorem}
  A theorem.
\end{theorem}

\begin{proof}
  Proof
  \begin{equation}
    \label{eq:p}
    a = b
  \end{equation}
  refers to \eqref{eq:one}, \eqref{eq:two} and \eqref{eq:p} and gives
  \begin{equation}
    \label{eq:q}
    c = d
  \end{equation}
  as required.  Note the cleveref references are \cref{eq:one},
  \cref{eq:two} and \cref{eq:p}.
\end{proof}

\begin{equation}
  \label{eq:two}
  z = 2
\end{equation}
Refer to \eqref{eq:one}, \eqref{eq:two} and \eqref{eq:p}.  Note the
cleveref references are \cref{eq:one}, \cref{eq:two} and \cref{eq:p}.


\end{document}

This needs to be adjusted depending on you equation labelling scheme.

If you are using hyperref you can avoid messages about duplicate labels either by disabling the hypertextnames option or as follows, where the \theHequation is also redefined in a way that includes a unique number for the current proof:

\documentclass{article}

\usepackage{mathtools,amsthm,etoolbox}
\usepackage{hyperref}
\usepackage{cleveref}

\newtheorem{theorem}{Theorem}

\newcounter{equationstore}
\newcounter{proofnum}

\AtBeginEnvironment{proof}{\setcounter{equationstore}{\value{equation}}
\refstepcounter{proofnum}
\setcounter{equation}{0}\renewcommand{\theequation}{\alph{equation}}
\renewcommand{\theHequation}{\arabic{proofnum}.\alph{equation}}}
\AtEndEnvironment{proof}{\setcounter{equation}{\value{equationstore}}}

\begin{document}

\begin{equation}
  \label{eq:one}
  x = 1
\end{equation}

\begin{theorem}
  A theorem.
\end{theorem}

\begin{proof}
  Proof
  \begin{equation}
    \label{eq:p}
    a = b
  \end{equation}
  refers to \eqref{eq:one}, \eqref{eq:two} and \eqref{eq:p} and gives
  \begin{equation}
    \label{eq:q}
    c = d
  \end{equation}
  as required.  Note the cleveref references are \cref{eq:one},
  \cref{eq:two} and \cref{eq:p}.
\end{proof}

\begin{equation}
  \label{eq:two}
  z = 2
\end{equation}
Refer to \eqref{eq:one}, \eqref{eq:two} and \eqref{eq:p}.  Note the
cleveref references are \cref{eq:one}, \cref{eq:two} and \cref{eq:p}.


\end{document}
Related Question