3

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.

  • 5
    This depends on the way how the exercises are counted/numbered. If there is an exercises counter, I would guess \renewcommand{\theequation}{\thesection.\arabic{exercise}.\arabic{equation}} before using the first exercise environment and \renewcommand{\theequation}{\thesection.\arabic{equation}}. Best use chngcntr package. Please provide a minimal compiling document. – user31729 Sep 5 '17 at 10:12
  • Welcome to TeX.SX! – Bobyandbob Sep 5 '17 at 10:13
  • 1
    If you provide your tags as MWE, it will help to analyze the issue – MadyYuvi Sep 5 '17 at 12:30
1

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 \begin{equation}...\end{equation}.

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. 

\begin{equation}
  E = mc^{2}
\end{equation}
\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}
  \begin{equation}
    E = mc^{2}
    \end{equation}

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}
  \begin{equation}
    E = mc^{2}
    \end{equation}

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}

enter image description here

| improve this answer | |
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.