How can I make sure that *all* counters start at 0?
\documentclass{article}
\makeatletter
\def\@arabic#1{\the\numexpr(#1)-1\relax}
\def\@roman#1{\romannumeral\numexpr(#1)-1\relax}
\def\@Roman#1{\expandafter\@slowromancap\romannumeral\numexpr(#1)-1\relax @}
\makeatother
\begin{document}
\section{Zero}
\subsection{Zero.Zero}
\subsubsection{Zero.Zero.Zero}
\section{One}
\subsection{One.Zero}
\subsubsection{One.Zero.Zero}
\section{Two}
\subsection{Two.Zero}
\subsubsection{Two.Zero.Zero}
\end{document}
You can use \LoopResetCounters
from xassoccnt
which sets all counters given in the comma-separated list to zero.
See the update for grabbing all counters defined with \newcounter
and put them on a list at the end of this answer!
\documentclass{article}
\usepackage{xassoccnt}
\begin{document}
\setcounter{figure}{17}
\thefigure
\LoopResetCounters{page,section,subsection,figure,equation,subsubsection,table}
\thefigure
\end{document}
Update
I've grabbed the comment by David Carlisle and exploited the \cl@@ckpt
list in order to reset the all counters to -1
, but omitted the page
counter there!
In order to make the resetting list work, the \@stpelt
list must be changed at all.
No additional package is needed at all!
This procedure does not influence the secnumdepth
and tocdepth
counters since those are not defined with \newcount
.
\documentclass{article}
\makeatletter
\newif\if@resetall
\@resetallfalse
\let\latex@newcounter\newcounter
\newcommand{\ResetAllCounters}[1][-1]{%
\EnableResetAll
\def\@elt##1{%
\def\@tmp@@a{##1}
\def\@tmp@@b{page}
\ifx\@tmp@@a\@tmp@@b % Check if it is the page counter
\setcounter{##1}{\z@}%
\else
\setcounter{##1}{#1}%
\fi
}%
\cl@@ckpt% Loop through the list of all counters defined with \newcounter
\gdef\@@resetvalue{#1}% Store the reset value
}
% Redefine the reset stepper \@elt - list marker
\let\latex@@stpelt\@stpelt
\def\@stpelt#1{%
\if@resetall%
\global\csname c@#1\endcsname \numexpr\@@resetvalue-1\stepcounter{#1}
\else
\latex@@stpelt{#1}%
\fi
}%
\newcommand{\DisableResetAll}{%
\global\@resetallfalse
}
\newcommand{\EnableResetAll}{%
\global\@resetalltrue%
}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\makeatother
\begin{document}
\tableofcontents
\part{Foo}
\section{Foo}
\ResetAllCounters
\part{Foostuff}
\section{Foostuff}
\subsection{Foostuff subsection}
\subsubsection{Foostuff subsubsection}
\paragraph{Foostuff paragraph}
\subparagraph{Foostuff subparagraph}
\part{Foobar}
\section{Foobar}
\subsection{Foobar subsection}
\subsubsection{Foobar subsubsection}
\paragraph{Foobar paragraph}
\subparagraph{Foobar subparagraph}
\ResetAllCounters
\DisableResetAll
\part{Barstuff}
\section{Barstuff}
\subsection{Barstuff subsection}
\subsubsection{Barstuff subsubsection}
\paragraph{Barstuff paragraph}
\subparagraph{Barstuff subparagraph}
\end{document}