[Tex/LaTex] Resetting theorem counters: \section and (missing) \subsection

countersnumberingsectioningtheorems

Suppose I define a new theorem "Theorem" and declare that its counter should be reset whenever the subsection counter is incremented or reset:

\newtheorem{theorem}{Theorem}[subsection]

At some point in my (article) document I start a new \section (say, section 2) without starting a \subsection. I expect the first theorem in this section to be numbered with "2.0.1" (which may be considered bad style). However, the theorem is numbered "2.0.2".

Is this "by design" (technically, I didn't start a new \subsection) or a bug? Moreover, what would be a proper workaround? (Such a workaround should not involve manually resetting the theorem counter, and it should work for whatever theorem type I may define in addition to "Theorem".)

\documentclass{article}

\newtheorem{theorem}{Theorem}[subsection]

\begin{document}

\section{bla}

\subsection{blubb}

\begin{theorem}
Some text.
\end{theorem}

\subsection{foo}

\begin{theorem}
Some text.
\end{theorem}

\section{bar}

\begin{theorem}
Some text.
\end{theorem}

\end{document}

EDIT: In response to Seamus' comment: The unexpected counter value also occurs with amsthm and ntheorem.

Best Answer

In LaTeX, “subcounters” are only reset when the counter is incremented by a \stepcounter. They are not reset when the counter is changed in any other way (e.g. via \setcounter or TeX commands).

The \section increments the section counter and thus sets the subsection counter to 0. But this does not reset the theorem counter. Only the next \subsection (which increments the subsection counter) resets the theorem counter.

I guess the easiest (or at least safest; see the comments) workaround is to simply add the theorem counter to the reset list for the section counter:

\makeatletter
\@addtoreset{theorem}{section}
\makeatother
Related Question