I want equation number in an algorithm with chapter number included. Here is my code.
\documentclass{book}
\usepackage{amsmath,amssymb,amsthm, latexsym,float,epsfig,subfig}
\usepackage[mathscr]{euscript}
\usepackage{mathrsfs, breqn}
\usepackage[ruled,vlined,linesnumbered,algochapter]{algorithm2e}
\usepackage{multirow}
\newtheorem{exmp}{Example}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{proposition}{Proposition}
\newtheorem{corollary}{Corollary}
\numberwithin{figure}{chapter}
\numberwithin{theorem}{chapter}
\numberwithin{exmp}{chapter}
\numberwithin{lemma}{chapter}
\numberwithin{proposition}{chapter}
\numberwithin{corollary}{chapter}
\numberwithin{equation}{chapter}
\begin{document}
\chapter{First}
\label{chap_ch1}
\begin{algorithm}[!h]
\DontPrintSemicolon
\SetAlgoLined
\If{p} {
\begin{equation} \label{eq:sclrec1}
a = b
\end{equation}
}
\Else {
\If{t} {
\begin{equation} \label{eq:sclrec2}
x = y
\end{equation}
}
}
\caption{\label{alg:algo} algorithm}
\end{algorithm}
Equation~\ref{eq:sclrec1} and Equation~\ref{eq:sclrec2}
\end{document}
The result is as follows :
I don't understand why my references are incorrect. Can anyone please explain ?
\begin{equation}\addtocounter{equation}{-1}\refstepcounter{equation}\label{eq:sclrec1}