2
\documentclass{article}
\usepackage{amsmath, amsfonts, chngcntr}
\newcounter{problem}
\newcounter{solution}

\newcommand\Problem{%
  \stepcounter{problem}%
  \textbf{\theproblem.}~%
  \setcounter{solution}{0}%
}

\newcommand\TheSolution{%
  \textbf{Solution:}\\%
}

\newcommand\ASolution{%
  \stepcounter{solution}%
  \textbf{Solution \thesolution:}\\%
}
\parindent 0in
\parskip 1em
\begin{document}

\section{Kinematics}

\Problem A motorboat going going downstream overcame a raft at point $\emph{A}$; $\tau$ = 60 min later it turned back and after some time passed the raft at a distance $l$ = 6.0 km from the point $\emph{A}$. Find flow velocity assuming the duty of the engine to be constant.

\TheSolution Let u be the flow velocity and v be velocity of boat in still water, 
    \begin{equation} \frac{l}{u}=\tau + \frac{(u+v)\tau-l}{v-u}  \end{equation}
    \begin{equation} u=\frac{l}{2\tau}=\frac{6}{2\cdot1}=3 \ km/hr \end{equation} 

\Problem  A point traversed half the distance with a velocity $v_0$. The remaining part of the distance was covered with velocity $v_1$ for half the time, and with velocity $v_2$ for the other half of the time. Find the mean velocity of the point averaged over the whole time of motion. 

\TheSolution \begin{equation} v_{av} = \frac{2\cdot v_0\cdot\frac{v_1+v_2}{2}}{v_0 + \frac{v_1+v_2}{2}} \end{equation}
\end{document}

This is my basic template for writing my problems and their solutions now if I compile this it will give this:

Output of the abv code

Now I want it so that the equation counter resets after each question like in que 2 it doesn't become (3) but becomes (1).

1
  • What sense will have numbering of equation which will repeating and not be unique? With this you will lost possibilities to referencing them (uniquely). Than is better to not number them at all.
    – Zarko
    Jun 13 at 9:48

2 Answers 2

3

Depending on your formatting requirements, you have two main choices for how to reset the equation counter automatically each time a new problem environment starts.,

  • If you just want to reset the equation counter each time a new problem starts, but do not wish to change the way the equation counter is displayed as well, you could run the following instruction in the preamble:

    \counterwithin*{equation}{problem}
    

    Note the "star" (*) symbol at the end of \counterwithin*.

  • If, in addition to resetting the equation counter, you wish to change the appearance of the counter so that it displays (1.1), (1.2) etc for equations associated with problem 1; {2.1) etc for equations associated with problem 2, etc, you could run the following code in the preamble:

    \counterwithin{equation}{problem}
    

The following code assumes you want to pursue the second option.

enter image description here

\documentclass{article}
\usepackage{amsmath, amsfonts}
\newcounter{problem}
\newcounter{solution}

%% option 1
%\counterwithin*{equation}{problem
%% option 2
\counterwithin{equation}{problem}

\newcommand\Problem{%
  \refstepcounter{problem}%
  \textbf{\theproblem.}~%
  \setcounter{solution}{0}%
}

\newcommand\TheSolution{%
  \textbf{Solution:}\\%
}

\newcommand\ASolution{%
  \stepcounter{solution}%
  \textbf{Solution \thesolution:}\\%
}
\parindent 0in
\parskip 1em

\usepackage{siunitx} % for \qty and \unit macros

\begin{document}

\section{Kinematics}

\Problem 
A motorboat going downstream passed a raft at point $\emph{A}$; $\tau = \qty{60}{min}$ later it turned back and after some time passed the raft at a distance $l = \qty{6.0}{km}$ from the point $\emph{A}$. Find flow velocity assuming the duty of the engine to be constant.

\TheSolution Let $u$ be the flow velocity and $v$ be velocity of boat in still water,
    \begin{equation} \frac{l}{u}=\tau + \frac{(u+v)\tau-l}{v-u}  
    \end{equation}
    \begin{equation} u=\frac{l}{2\tau}=\frac{6}{2\cdot1}=\qty{3}{km/hr} \end{equation}

\Problem  
A point traversed half the distance with a velocity $v_0$. The remaining part of the distance was covered with velocity $v_1$ for half the time, and with velocity $v_2$ for the other half of the time. Find the mean velocity of the point averaged over the whole time of motion.

\TheSolution 
\begin{equation} v_{av} = \frac{2\cdot v_0\cdot\frac{v_1+v_2}{2}}{v_0 + \frac{v_1+v_2}{2}} \end{equation}
\end{document} 
2
  • 1
    Uh! Why not \counterwithin*{equation}{problem} instead of going with \@addtoreset?
    – egreg
    Jun 13 at 10:17
  • @egreg - Mostly because I'd forgotten the "starred" variant of \counterwithin... Let me fix this issue right away.
    – Mico
    Jun 13 at 10:21
0

The command \setcounter{equation}{0} will reset the equation counter to 0. The next time you have a numbered equation, the counter will be incremented and displayed, so that this equation will have number 1.

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.