# Always resumed list does not always resume if invoked from within an environment

MyList is an always resumed enumitem list:

\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{label={\arabic*.}, resume}% ALWAYS resumed


but seems to break if the first use of MyList is from within another environment (orange text). In the MWE, this environemnt adds a color to the list and then envokes \begin{MyList}:

\newenvironment{MyColoredList}[2][]{%
\color{#2}%
\begin{MyList}[#1]
}{%
\end{MyList}%
}%


But, the same environment used after the direct use of MyList seems fine (blue text):

## Notes:

• The second level is not resumed and there is no issue with it. Thus I removed the code that was testing that part.
• My question is not how to color a list, but how to have it resume numbering when it is invoked from within an environment.

# References:

## Code:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{label={\arabic*.}, resume}% ALWAYS resumed
\setlist[MyList,2]{label={\alph*)}}%           NOT resumed

\newenvironment{MyColoredList}[2][]{%
\color{#2}%
\begin{MyList}[#1]
}{%
\end{MyList}%
}%

\begin{document}
\begin{MyColoredList}{red}
\item First Item
\end{MyColoredList}
Some text
\begin{MyColoredList}{orange}% <--- This should be number 2
\item First Item
\end{MyColoredList}
Some text
\begin{MyList}% <--- This should be number 3
\item Second Item
\end{MyList}
Some text
\begin{MyList}
\item Third Item
\end{MyList}
Some text
\begin{MyColoredList}{blue}
\item Fourth Item (this works!!)
\end{MyColoredList}
\end{document}

• The resume option is local only, for global resume (i.e. settings that survive groups) you should the resume* option or even the series key – user31729 Apr 23 '17 at 8:27

You can do it the hard way:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{
label=\arabic*.,
before=\setcounter{MyListi}{\value{MyList}},
after=\setcounter{MyList}{\value{MyListi}},
}% ALWAYS resumed
\setlist[MyList,2]{label=\alph*)}%           NOT resumed

\newcounter{MyList}
\newenvironment{MyColoredList}[2][]{%
\color{#2}\begin{MyList}[#1]
}{%
\end{MyList}%
}%

\begin{document}
\begin{MyColoredList}{red}
\item First Item
\end{MyColoredList}
Some text
\begin{MyColoredList}{orange}% <--- This should be number 2
\item First Item
\end{MyColoredList}
Some text
\begin{MyList}% <--- This should be number 3
\item Second Item
\end{MyList}
Some text
\begin{MyList}
\item Third Item
\end{MyList}
Some text
\begin{MyColoredList}{blue}
\item Fourth Item (this works!!)
\end{MyColoredList}
\end{document}


The resume option is always local, i.e. only within the current group. Using a list within some environment and trying to resume the list in another environment later on will fail in the sense that the information is lost.

The remedy is resume*, which must be specified locally, however and can't be given as option to the \setlist macro.

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{label={\arabic*.},resume}% ALWAYS resumed
\setlist[MyList,2]{label={\alph*)}}%           NOT resumed

\newenvironment{MyColoredList}[2][]{%
\color{#2}%
\MyList[#1]
}{%
\endMyList%
}%

\begin{document}
\begin{MyColoredList}{red}
\item First Item
\end{MyColoredList}
Some text
\begin{MyColoredList}[resume*]{orange}% <--- This should be number 2
\item First Item
\end{MyColoredList}
Some text
\begin{MyList}% <--- This should be number 3
\item Second Item
\end{MyList}
Some text
\begin{MyList}
\item Third Item
\end{MyList}
Some text
\begin{MyColoredList}{blue}
\item Fourth Item (this works!!)
\begin{MyList}[resume*]
\item Inner Item
\end{MyList}
\end{MyColoredList}
\begin{MyColoredList}{violet}
\item Fifth Item (this works!!)
\begin{MyList}[resume*]
\item Inner Item
\end{MyList}
\end{MyColoredList}

\end{document}


A better way can be achieved with the series= key:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{label={\arabic*.},resume=foo}% ALWAYS resumed
\setlist[MyList,2]{label={\alph*)}}%           NOT resumed

\newenvironment{MyColoredList}[2][]{%
\color{#2}%
\begin{MyList}[#1]
}{%
\end{MyList}%
}%

\begin{document}
\begin{MyColoredList}[series=foo]{red}
\item First Item
\end{MyColoredList}
Some text
\begin{MyColoredList}{orange}% <--- This should be number 2
\item First Item
\end{MyColoredList}
Some text
\begin{MyList}%  <--- This should be number 3
\item Second Item
\end{MyList}
Some text
\begin{MyList}
\item Third Item
\end{MyList}
Some text
\begin{MyColoredList}{blue}
\item Fourth Item (this works!!)
\begin{MyList}[resume*]
\item Inner Item
\end{MyList}
\end{MyColoredList}
\begin{MyColoredList}{violet}
\item Fifth Item (this works!!)
\begin{MyList}[resume*]
\item Inner Item
\end{MyList}
\end{MyColoredList}

\end{document}


• Good solution. Unfortunately that won't work for me as I don't the order the list items will come in. I need it to auto resume. – Peter Grill Apr 23 '17 at 9:23
• @PeterGrill: Hm, I don't understand. There's only one resume in the \setlist part right now (apart from the forced resume on the last two inner lists). It does auto resume. You can change the series and the resume later on, if needed – user31729 Apr 23 '17 at 9:27
• But I don't know upfront which is the first list item to start the series with. The list \begin{MyList} \item .. \end{MyList} are stored and output later. These elements can also be other text, not just list elements, so at the output stage I don't know what is being output. Similar to \def\MacroA{\begin{MyList} \item .. \end{MyList}}, \def\MacroB{\begin{MyList} \item .. \end{MyList}}, \def\MacroC{Some text with perhaps lists in it, or not}. And then these three can be output in any order: \MacroA\MacroB\MacroC or \MacroC\MacroA\MacroB\MacroA, etc. – Peter Grill Apr 23 '17 at 9:31
• @PeterGrill: I have no clue for this (yet) ... – user31729 Apr 23 '17 at 9:32
• Based on your solution I was attempting to use environ to save the environment \BODY and do some \aftergroup (so that list would not be in a group) but can't seem to get that to work. – Peter Grill Apr 23 '17 at 9:33

You can try this

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\makeatletter
\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{label={\arabic*.},
after={\xdef\enit@resume@MyList{\noexpand\c@MyListi=\the\c@MyListi}},resume}% ALWAYS resumed
\setlist[MyList,2]{label={\alph*)}}%           NOT resumed

\makeatother
\newenvironment{MyColoredList}[2][]{%
\color{#2}%
\begin{MyList}[#1]
}{%
\end{MyList}%
}%

\begin{document}

\begin{MyColoredList}{red}
\item First Item
\end{MyColoredList}
Some text
\begin{MyColoredList}{orange}% <--- This should be number 2
\item First Item
\end{MyColoredList}
Some text
\begin{MyList}% <--- This should be number 3
\item Second Item
\end{MyList}
Some text
\begin{MyList}
\item Third Item
\end{MyList}
Some text
\begin{MyColoredList}{blue}
\item Fourth Item (this works!!)
\end{MyColoredList}
\end{document}