In the following MWE
\documentclass[draft]{article}
\newenvironment{myitem}{\item}{}%
\begin{document}
\begin{enumerate}
\item \begin{enumerate}
\item Item 1
\item Item 2
\end{enumerate}
\end{enumerate}
\begin{enumerate}
\item \begin{enumerate}
\begin{myitem} Item 1 \end{myitem} % This is the only difference
\item Item 2
\end{enumerate}
\end{enumerate}
% even this works!!!!
\begin{enumerate}
\item \begin{enumerate}
\myitem Item 1 \endmyitem % This is the only difference
\item Item 2
\end{enumerate}
\end{enumerate}
\end{document}
The output of the first part is correct, but the output of my verbose myitem
environment (which should just replicate \item
) is missing the number on the second line. EDIT: Any idea why this is happening? Note that if I add any text in the outer \item
, everything works as expected (the inner enumerate starting on a new line).
In my real use-case, I have to execute some code at the beginning and end of each item, which is why I adopted the use of an environment.
EDIT: thanks for the suggestions regarding other ways to resolve this. But I am also quite interested to learn why the environment approach is failing.
EDIT2: I found out that I can replicate the wrong behaviour with.
\begin{enumerate}
\item \begin{enumerate}
\begingroup \item test 1 \endgroup
\item item 2
\end{enumerate}
\end{enumerate}
So clearly the fact that the environments are starting groups around the \item
is the issue. I thought I could change the definition of my environment as follows:
\newenvironment{myitem}{\endgroup\item\begingroup}{}%
To cause the group to be created outside \item
, but then I get the error
\begin{enumerate} on input line 15 ended by \end{myitem}.
getitems
package might be helpful for your real use case.