# Numbering equations with more than one counter

I am recently texing my lecture notes in maths and want to include a subsection with the exercises. The numbering of the lecture notes is (sec.eq), but for the exercises, I want the numbering to be (sec.ex.eq). I don't know how to achieve this.

(06.09.2017) Thank you for the comments so far. To give a minimal document:

\documentclass{article}

\usepackage{amsmath,amsthm,amsfonts,amssymb}
\usepackage{hyperref}

\newtheorem{Exercise}{Exercise}[section]

\begin{document}

\section{sec1}
Here is section 1.
\subsection{ssec1.1}
Here I have a subsection.
\subsection{ssec1.2}
Here I have another subsection.
\subsection{exercises1}
Here I have the exercises (using the above defined theroem enviroment).

\section{sec2}
Here the same.
\subsection{ssec2.1}
Here the same.
\subsection{ssec2.2}
Here the same.
\subsection{exercises2}
And again exercises.
\end{document}


The numbering is about the equation numbers, there I have my problems.

• Welcome to TeX.SX! – Bobyandbob Sep 5 '17 at 10:13
• If you provide your tags as MWE, it will help to analyze the issue – MadyYuvi Sep 5 '17 at 12:30

The output of \theequation can be changed locally in the Exercise environment which is defined by \newtheorem with

\AtBeginEnvironment{Exercise}{%
\renewcommand{\theequation}{\theExercise.\arabic{equation}}
}


Since this occurs within the environment group, the redefinition is not affecting \theequation used in $$...$$.

Since Exercise is defined to be counted within section, \theExercise is already using \thesection.\arabic{Exercise} by design.

Please note that the equation counter is not reset here with each Exercise however!

\documentclass{article}

\usepackage{amsmath,amsthm,amsfonts,amssymb}
\usepackage{etoolbox}

\usepackage{hyperref}

\newtheorem{Exercise}{Exercise}[section]

\AtBeginEnvironment{Exercise}{%
\renewcommand{\theequation}{\theExercise.\arabic{equation}}
}

\begin{document}

\section{sec1}
Here is section 1.

% Regular equation environment, using a different counter.

$$E = mc^{2}$$
\subsection{ssec1.1}
Here I have a subsection.
\subsection{ssec1.2}
Here I have another subsection.
\subsection{exercises1}
Here I have the exercises (using the above defined theroem enviroment).

\begin{Exercise}
$$E = mc^{2}$$

And other equations:

\begin{align}
E^{2} &= (p c)^{2} + (m_{0} c^{2})^{2} \\
c^{2} &= a^{2} + b^{2}
\end{align}

\end{Exercise}

\section{sec2}
Here the same.
\subsection{ssec2.1}
Here the same.
\subsection{ssec2.2}
Here the same.
\subsection{exercises2}
And again exercises.

\begin{Exercise}
$$E = mc^{2}$$

And other equations:

\begin{align}
E^{2} &= (p c)^{2} + (m_{0} c^{2})^{2} \\
c^{2} &= a^{2} + b^{2}
\end{align}

\end{Exercise}

\end{document}


• I suggest the usage of \counterwithin{equation}{Exercise} within \AtBeginEnvironment{Exercise}{} in order to reset the equation counter with each Exercise... – user31729 Sep 6 '17 at 19:39
• Thank you @Christian Hupfer. That was exactly what I was looking for. – DarkViole7 Sep 7 '17 at 8:57
• @DarkViole7: Please accept my solution then in order to mark it as solved – user31729 Sep 7 '17 at 9:18