Open wwywong opened 7 months ago
Here is a patch which makes use of resume*
without antecedent behaves the same as such use of resume
: input is accepted silently and nothing is resumed.
\documentclass{article}
\usepackage{enumitem}
\makeatletter
\@namedef{enitkv@enumitem-resume@resume*@default}{%
\let\enit@resuming\thr@@
\enit@ifunset{enit@resumekeys@\@currenvir}
% Nothing to resume if this is the first occurrance of \@currenvir.
% An empty \enit@resumekeys results in \enitkv@setkeys{enumitem}{,resume}
% called in \enit@setresume.
{\def\enit@resumekeys{}}
{\let\enit@resuming\thr@@
\expandafter\let\expandafter\enit@resumekeys
\csname enit@resumekeys@\@currenvir\endcsname
\@nameuse{enit@resume@\@currenvir}\relax}%
}
\makeatother
\newlist{myenum}{enumerate}{3}
\setlist[myenum]{label=\roman*}
\begin{document}
\begin{enumerate}[resume*]
\item Test \texttt{resume*} without antecedent
\end{enumerate}
\begin{enumerate}[resume*]
\item b
\item c
\end{enumerate}
\begin{myenum}[resume]
\item Test \texttt{resume} without antecedent
\end{myenum}
\begin{myenum}[resume]
\item b
\item c
\end{myenum}
\end{document}
Consider the (somewhat unrealistic) MWE
This will print the text
resume,,
before the list starts.My TeX.SE answer describes why, and this can be solved by using a different token to check of list termination in the definition of
\enitkv@do#1,
(currently it uses\relax
to mark end of list, which is the cause of the problem as\csname ... \endcsname
returns\relax
when the macro is undefined.A more realistic use case which leads to this showing up is if a user used
\begin{enumerate}...\end{enumerate}
within an environment (so in a group), and then tried to call\begin{enumerate}[resume*] ... \end{enumerate}
afterwards from outside the group. This can be abstracted asIn this case, we see a very strange behavior. The first time the
resume*
environment hits, everything is okay. The second time theresume*
environment hits, we get the weirdresume,,
text showing up, but the counter is resumed correctly!This is because for
resume*
it doesn't save the optional arguments, but it saves the counter via\global
. While the first call toenumerate
saves both but only locally. From the package:Part of me is also wondering whether for the
resume*
(but notseries
) case, it would make more sense to have\@gobblefour\@empty
instead of\@gobblefour\global
to line up with the other non-series
cases.