# Separate equation numbering in algorithm environment

Consider the following code:

\documentclass{article}
\usepackage[utf8]{inputenc}
%Algorithms:
\usepackage[boxruled]{algorithm2e} %Fancy algorithms
\usepackage{algcompatible}
\usepackage{amsmath}

\begin{document}

Blah blah blah

$$E = mc^2$$

\begin{algorithm}[ht!]
\SetAlgoNoLine
\SetAlgoNoEnd
\DontPrintSemicolon
\caption{My method}
\begin{minipage}[ht]{\dimexpr\textwidth-2\algomargin\relax}
\begin{enumerate}
\item Solve this equation:
$$\nabla f = u \tag{Alg1.1}$$
\item Then, solve this equation:
$$\nabla f + cf = u' \tag{Alg1.2}$$
\end{enumerate}
\end{minipage}
%
\end{algorithm}

blah blah blah

$$E \ne mc^3$$

\begin{algorithm}[ht!]
\SetAlgoNoLine
\SetAlgoNoEnd
\DontPrintSemicolon
\caption{My inverse method}
\begin{minipage}[ht]{\dimexpr\textwidth-2\algomargin\relax}
\begin{enumerate}
\item Update $u$:
$$u = \nabla f \tag{Alg2.1}$$
\item Update $u'$:
$$u' = \nabla f + cf \tag{Alg2.2}$$
\end{enumerate}
\end{minipage}
\end{algorithm}

blah blah blah

$$E \ne mc^4$$

\end{document}


Is there a way to automate the process of doing a different numbering system for equations inside the algorithm environment?

In particular, I would like all equations inside the Algorithms to be numbered as AlgX.Y where X is the algorithm number and Y is the equation number within Algorithm X.

You can use a method similar to subequations:

\documentclass{article}
\usepackage[utf8]{inputenc}
%Algorithms:
\usepackage[boxruled]{algorithm2e} %Fancy algorithms
\usepackage{algcompatible}
\usepackage{amsmath}
\usepackage{etoolbox}

\AtBeginEnvironment{algorithm}{\algoequations}
\AtEndEnvironment{algorithm}{\restoreequations}
\newcounter{algosavedequation}
\newcommand{\algoequations}{%
\setcounter{algosavedequation}{\value{equation}}%
\setcounter{equation}{0}%
\renewcommand{\theequation}{Alg\thealgocf.\arabic{equation}}%
}
\newcommand{\restoreequations}{%
\setcounter{equation}{\value{algosavedequation}}%
}

\begin{document}

Blah blah blah

$$E = mc^2$$

\begin{algorithm}[ht!]
\SetAlgoNoLine
\SetAlgoNoEnd
\DontPrintSemicolon
\caption{My method}
\begin{minipage}{\dimexpr\textwidth-2\algomargin\relax}
\begin{enumerate}
\item Solve this equation:
$$\nabla f = u$$
\item Then, solve this equation:
$$\nabla f + cf = u'$$
\end{enumerate}
\end{minipage}
%
\end{algorithm}

blah blah blah

$$E \ne mc^3$$

\begin{algorithm}[ht!]
\SetAlgoNoLine
\SetAlgoNoEnd
\DontPrintSemicolon
\caption{My inverse method}
\begin{minipage}{\dimexpr\textwidth-2\algomargin\relax}
\begin{enumerate}
\item Update $u$:
$$u = \nabla f$$
\item Update $u'$:
$$u' = \nabla f + cf$$
\end{enumerate}
\end{minipage}
\end{algorithm}

blah blah blah

$$E \ne mc^4$$

\end{document}


There is no ht option for minipage.