\RenewDocumentCommand{\item}{ s o }{ \IfNoValueTF{#2}{\it@m}{\it@m[#2]} \ifnum\enit@depth=\@ne \IfBooleanT{#1}{\addtocounter{totalitems}{-1}}% \stepcounter{totalitems} \fi }
\DeclareDocumentCommand{\item}{ s o }{ \IfNoValueTF{#2}{\it@m}{\it@m[#2]} \ifenum \IfBooleanT{#1}{\addtocounter{totalitems}{-1}}% \stepcounter{totalitems} \fi }
\def\outputexer{ (There \ifnum\exer@section{\c@section}=0% is ??{} exercise% \else% \ifnum\exer@section{\c@section}=1% is 1 exercise% \else% are \exer@section{\c@section} exercises% \fi% \fi.) } \def\exer@sectionzh#1{% \@ifundefined{totalenumi@\romannumeral#1}% {??}% {\csname totalenumi@\romannumeral#1\endcsname}% } \def\outputexerzh{% (本节共有 \exer@sectionzh{\c@section}题.) } \makeatother
\begin{document} \tableofcontents \section{Optional, nested, and resume\outputexer} \begin{enumerate} \item test \begin{enumerate} \item this is the second level of enumerate \begin{enumerate} \item this is the third level of enumerate \end{enumerate} \item* this is a star verion in the second level, will do nothing \end{enumerate} \item[option] this is an optional paramater without star. \end{enumerate}
\begin{enumerate}[resume] \item this is a resume version \end{enumerate} \exerend
\section{带星号以及可选参数\outputexerzh} \begin{enumerate} \item test \item*[option] this is a star version with an optional paramater. \end{enumerate}
\begin{enumerate} \item test \item* this is a star version \end{enumerate} \exerend
\section{A regular enumerate} \begin{enumerate} \item test \end{enumerate}
\section{A single item\outputexer} \begin{enumerate} \item just one item \end{enumerate} \exerend \end{document}
\def\outputexer{ (There \ifnum\exer@section{\c@section}=0% is ??{} exercise% \else% \ifnum\exer@section{\c@section}=1% is 1 exercise% \else% are \exer@section{\c@section} exercises% \fi% \fi.) }
\def\exer@sectionzh#1{% \@ifundefined{totalenumi@\romannumeral#1}% {??}% {\csname totalenumi@\romannumeral#1\endcsname}% } \def\outputexerzh{% (本节共有 \exer@sectionzh{\c@section}题.) } \makeatother \begin{document} \tableofcontents \section{One\outputexer} \begin{enumerate} \item test \begin{enumerate} \item this is the second level of enumerate \end{enumerate} \item test \end{enumerate}
\begin{enumerate}[resume] \item test \end{enumerate} \exerend
\section{Two\outputexerzh} \begin{enumerate}[start=5] \item test \item test \end{enumerate}
\begin{enumerate} \item test \end{enumerate} \exerend
\section{No output} \begin{enumerate} \item test \end{enumerate}
\section{Three\outputexer} \begin{enumerate} \item test \end{enumerate} \exerend \end{document}