[Tex/LaTex] Share counter between amsthm and algorithm

algorithmsamsthm

I am using amsthm

\usepackage{amsthm}
\newtheorem{thm}{Theorem}[chapter]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}

and algorithm

\usepackage{algorithm, algpseudocode}
\makeatletter
\renewcommand\thealgorithm{\thechapter.\arabic{algorithm}}
%\@addtoreset{algorithm}{chapter}
\makeatother

In my text I have everything numbered consecutively in each chapter (Definition 3.1, Lemma 3.2, Theorem 3.3) except for the algorithms which have separate counter (Definition 3.1, Lemma 3.2, Algorithm 3.1, Theorem 3.3). How can I make it so that algorithms are numbered together with everything else? (Definition 3.1, Lemma 3.2, Algorithm 3.3, Theorem 3.4)

Best Answer

Use [algorithm] in all your \newthorem so they use the algorithm counter instead of thm.

Beware though, if you use a floating environment and a non-floating environment with the same counter the algorithm may float past the theorem so come in the wrong order.

Related Question