4

I have created an environment named hwp with custom headers and footers that works otherwise very much like the native section environment, in which I can set equations, add figures, etc. What I would like to do is to use the \numberwithin{equation}{section} for hwp. In other words, the numbering of equations should be reset whenever a new hwp is created.

As it appears that I have to work around the \numberwithin command, I have been working on setting up my own counter that would serve the purpose, yet to no avail. The following is the code related to my goal. Any advice would be much appreciated.

\newcounter{hwpcounter}
\newcounter{eqcounter}
\renewcommand{\theeqcounter}{\addtocounter{eqcounter}{1}}

\newenvironment{hwp}[1][Prob \arabic{hwpcounter}]
{
    \stepcounter{hwpcounter}
    \renewcommand{\theequation}{\arabic{hwpcounter}.\theeqcounter}
}
1

1 Answer 1

3

I provided a dummy definition for the hwp environment, since the one given in the question is not complete:

\documentclass{article} 
\usepackage{amsmath}

\newcounter{hwpcounter}

\newenvironment{hwp}[1][Prob~\arabic{hwpcounter}]
  {\refstepcounter{hwpcounter}\par#1\par\nobreak}
  {\par}

\numberwithin{equation}{hwpcounter}

\begin{document}

\begin{hwp}
test
\begin{equation}
a=b.
\end{equation}
\begin{equation}
a=b.
\end{equation}
\end{hwp}

\begin{hwp}
test
\begin{equation}
a=b.
\end{equation}
\begin{equation}
a=b.
\end{equation}
\end{hwp}

\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .