How can I terminate and resume an environment by another environment? This also seems to have broken the resume feature which was resolved in Define a List that is Always Resumed.
The code
\begin{MyEnvironment}
First entry
\end{MyEnvironment}
\hrule\smallskip\par
\begin{MyEnvironment}
Some alternate entry
\end{MyEnvironment}
yields the desired output (except for breaking the resume feature of the list):
I would like to eliminate the lines:
\end{MyEnvironment}
\hrule\smallskip\par
\begin{MyEnvironment}
so thought that a solution would be to define a new enviroment:
\newenvironment{MyEnvironmentAlternate}{%
\end{MyEnvironment}
\hrule\smallskip\par
\begin{MyEnvironment}
}{%
%\end{MyEnvironment}
}%
but this does not compile -- usage of this is commented out in the MWE.
Next I tried replacing the three lines with
\newcommand*{\EndAndResume}{%
\end{MyEnvironment}
\hrule\smallskip\par
\begin{MyEnvironment}
}%
which seems to compile, however it still breaks the resume feature of the counter as per Define a List that is Always Resumed.
Notes:
- The commented code in
MyEnvironmentAlternateis my attempt to adapt the solution from Suspending environments and resuming by another environment. David warned about not trying this at home, and since that is where I am, I attempted the alternate\EndAndResumesolution.
Code:
\documentclass{article}
\usepackage{enumitem}
\usepackage{environ}
\newlist{MyList}{enumerate}{1}
\setlist[MyList]{label={\arabic*)},leftmargin=2cm, resume}
\newenvironment{MyEnvironment}{% Don't want to have to change this enviromnent
\noindent\textbf{MyEnvironment}
\begin{MyList}
\item
}{%
\end{MyList}%
}%
%% The commented code here is my attempt to adapt the solution from
%% https://tex.stackexchange.com/questions/237478/suspending-environments-and-resuming-by-another-environment
\newenvironment{MyEnvironmentAlternate}{% Need to define this environment
%%\endgroup%
\end{MyEnvironment}%
\hrule\smallskip\par
\begin{MyEnvironment}%
%%\begingroup%
%%\def@currenvir{MyEnvironmentAlternate}%
}{%
\end{MyEnvironment}%
}%
\begin{document}
%Resumed list works here:
%
%\begin{MyList}
% \item A
%\end{MyList}
%\begin{MyList}
% \item B
%\end{MyList}
\begin{MyEnvironment}
First entry
\end{MyEnvironment}
\hrule\smallskip\par
\begin{MyEnvironment}
Some alternate entry
\end{MyEnvironment}
\noindent
The above is the desired result (except for the problem with counter), but want to do it within \verb|MyEnvironment| as below:
%\begin{MyEnvironment}
% First entry
% \begin{MyEnvironmentAlternate}
% Some alternate entry
% \end{MyEnvironmentAlternate}
%\end{MyEnvironment}
\end{document}

MyEnvironmentis set by a macro and saved for later processing. This content does not contain the title,\begin{MyList}including the\item. This macro expects only one item. So, I could define a separateMyEnvironmentAlternate, but thought I could just hack the content passed toMyEnvironment. – Peter Grill Mar 10 '16 at 23:02