4

I have a list that I need to behave as if it is always resumed. With the enumitem package, I know I can use series=<name> on the first list, and use resume*=<name> on subsequent lists.

However, my issue is that I have these lists defined in macros and the macros don't know which one will be first (so that it can specify the series=<name> option) and which will be the subsequent ones (which need a resume*=<name>). Furthermore, any item (including the first one) may be repeated, so if any one item is assumed to be the first one, then the count gets reset.

How can I define al its that always continues numbering independent of the order?

enter image description here

Notes:

  • A hack solution would be to pass in the series= and resume* option when the macros are invoked, but I'd prefer not to have to do that.

Code:

\documentclass{article}

\usepackage{enumitem}

\newlist{MyList}{enumerate}{2} \setlist[MyList]{label={\arabic*)}}

\newcommand*{\ListA}{% \begin{MyList}[series=ResumedList] \item Item A \end{MyList} }

\newcommand{\ListB}{% \begin{MyList}[resume=ResumedList] \item Item B \end{MyList} }

\begin{document} \ListA \ListB

\ListB
\ListA

Number of list items = \arabic{MyListi}

\ifnum\arabic{MyListi}=4\relax
    \textbf{PASS}: Correct count
\else
    \textbf{FAIL}: Incorrect count. Count should be 4.
\fi

\end{document}

Peter Grill
  • 223,288

1 Answers1

5

Are there several series? Because if not, this works

\documentclass{article}

\usepackage{enumitem}

\newlist{MyList}{enumerate}{2}
\setlist[MyList]{
  label=(\arabic*),
  resume
}

\newcommand*{\ListA}{%
    \begin{MyList}
        \item Item A
    \end{MyList}
}

\newcommand*{\ListB}{%
    \begin{MyList}
        \item Item B
    \end{MyList}
}


\begin{document}
    \ListA
    \ListB

    \ListB
    \ListA

    Number of list items = \arabic{MyListi}

    \ifnum\arabic{MyListi}=4\relax
        \textbf{PASS}: Correct count
    \else
        \textbf{FAIL}: Incorrect count. Count should be 4.
    \fi
\end{document}
daleif
  • 54,450
  • 2
    You beat me to this very answer (in particular, the use of the resume option in \setlist) by a few seconds. :-) However, I would write \ifnum\value{MyListi}=4 instead of \ifnum\arabic{MyListi}=4\relax. – Mico Mar 10 '16 at 11:13
  • @Mico any idea on the case where there might be several series? I'm guessing testing for the existence of the series and then adjusting options accordingly – daleif Mar 10 '16 at 11:14
  • I have a different list for different series, so this works great for me. Thanks. – Peter Grill Mar 10 '16 at 11:15