I'm attempting to use enumitem to make a list that runs consecutively in a section and then resets.
This question and accepted answer looks promising: How to use chngcntr with an enumitem newlist with resume?, but it does not quite seem to work when I try it.
The requirement from the author needing it was just that the Problems env should be usable several times within the same section, consecutive numbering within the section, and reset at et new section.
Any ideas?
\documentclass[a4paper]{article}
\usepackage{enumitem}
\newlist{xxx}{enumerate}{1}
\setlist[xxx]{
label=\thesection.\arabic*.,
% no end dot in ref
ref=\thesection.\arabic*,
resume=myProblems,
}
\usepackage{etoolbox}
\preto\section{%
\restartlist{xxx}%
}
\newenvironment{Problems}{%
\paragraph{\textbf{Exercises}}%
\begin{xxx}}{\end{xxx}}
\begin{document}
\section{test}
\begin{Problems}
\item A
\end{Problems}
\subsection{subtest}
\begin{Problems}
\item B
\end{Problems}
\section{test 2}
\begin{Problems}
\item C
\end{Problems}
\end{document}

\restartlistonly sets\enit@resume@myProblemsto empty. That is not enough in this case. – daleif Feb 02 '15 at 10:46\pretocmd? In this case it's the same as\pretobut I think it's better\pretocmd. – Manuel Feb 02 '15 at 19:44\pretocmdmight be more defensive,\pretois faster and more efficient. – Heiko Oberdiek Feb 02 '15 at 19:54