[Tex/LaTex] How to make equation numbering dependent on theorem numbering

numbering

I ask a variation of some questions previously posed.

What I have now is this:

This is what I have

I want the equation numbers to follow the same numbering scheme as the theorems and definition. That is, I want the equation to be labelled (1.3) and the definition after it be labelled (1.4).

To further clarify, if we were in subsection 1.1, instead of section 1, I want to have theorem 1.1.1, theorem 1.1.2, equation 1.1.3 and definition 1.1.4.

Right now, the screenshot I posted uses the solution presented here.

I've also looked at this post. I tried to do that, but it completely ignored the "sectioning" I've done with the theorem numbers. Everything became 1, 2, 3… instead of 1.1, 1.2, 1.3, …

Moreover, it makes the theorem numbers depend on the equation numbers, which is the opposite of what I want. I want the equation numbering to follow the theorem numbering. This is because I've already "fixed" the theorem numbering to how I want it. However, I'm open to more out-of-the-box suggestions.

The following is the code for the screenshot.

\documentclass[a4paper]{article}
\usepackage{amsmath, amsthm}
\setcounter{section}{0}

\newtheorem{thm}{Theorem}[section]
\numberwithin{equation}{section}
\newtheorem{ex}[thm]{Example}
\newtheorem{defn}[thm]{Definition}

\begin{document}

\section{Section Title}

\begin{thm}
Spaghettoni.
\end{thm}

\begin{thm}
Vermicelloni.
\end{thm}

\begin{proof}
Manicotti.
\begin{equation}
x^2 + y^2 = z^2
\end{equation}
\end{proof}

\begin{defn}
Maltagliati.
\end{defn}

\end{document}

Best Answer

The \newtheorem command has an optional argument in which you can specify an already existing counter to be used for numbering the theorems. This counter can be any LaTeX counter, including equation. So, for instance,

\numberwithin{equation}{section} % or whatever you prefer

\swapnumbers % I prefer this

\theoremstyle{plain}
\newtheorem{thm}[equation]{Theorem}
\newtheorem{prop}[equation]{Proposition}
\newtheorem{lem}[equation]{Lemma}
\newtheorem{cor}[equation]{Corollary}
\newtheorem*{notice}{Notice}

\theoremstyle{definition}
\newtheorem{dfn}[equation]{Definition}
\newtheorem{bigrem}[equation]{Remark}
\newtheorem{num}[equation]{} % a bit strange, but I do use it!
\newtheorem{exmp}[equation]{Example}

defines a whole series of “theorem-like” environments all of which are numbered in the same sequence as equations.