Given content of several paragraphs (which definitely has at least one occurrence of {MyList} environment), I would like to define a macro that can break this content into the content before the end of the nth item of {MyList} and the content after the nth item.
That is, given input of the form
Some text before
\begin{MyList}
\item First.
\item Second.
\item Third.
\end{MyList}
Some text after
transform this into (assuming n=1)
Some text before
\begin{MyList}
\item First.
\end{MyList}% end list after n items
%% -----------
\begin{MyList}% restart list after n items
\item Second.
\item Third.
\end{MyList}
Some text after
and process the two pieces separately.
If n=2, then the desired transformation would be
Some text before
\begin{MyList}
\item First.
\item Second.
\end{MyList}% end list after n items
%% -----------
\begin{MyList}% restart list after n items
\item Third.
\end{MyList}
Some text after
Ideally, I would like to provide an integer to indicate the number of line items to break at. But, in case there does not exist sufficient TeX magic to do this, one option would to require a \MarkBoundaryPoint to be placed in the list to denote the point where the break is to occur.
That is included in the MWE, but is a NOOP for now.
If that is still not possible, what is the least markup that would allow this to be done?
Notes:
- I am using a list that is always resumed so numbering is not an issue.
The desired output of the MWE, after appropriate changes to \IncludeUpToFirstNItemsOfMyList and \IncludeAfterFirstNItemsOfMyList would be:
Code:
\documentclass{article}
\usepackage{enumitem}
%% This list is ALWAYS resumed.
%% https://tex.stackexchange.com/questions/366179/always-resumed-list-does-not-always-resume-if-invoked-from-within-an-environment
\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)}
\newcounter{MyList}
\newcommand{\IncludeUpToFirstNItemsOfMyList}[2][1]{%
%% #1 = number of list item to put in fbox
%% #2 = content which includes a {MyList}
%%
%% ??? How do I ignore ALL text AFTER first n items?
#2% TBD: This macro should cutoff any text AFTER item number specified in #1
}%
\newcommand{\IncludeAfterFirstNItemsOfMyList}[2][1]{%
%% #1 = number of list item to discard
%% #2 = content which includes a {MyList}
%%
%% ??? How do I ignore ALL text up to the first n items?
#2% TBD: This macro should cutoff any text BEFORE item number specified in #1
}%
\newcommand*{\MarkBoundaryPoint}{}% 2nd option (in case it is not possible to do without)
\newcommand{\PutPartOfListInFbox}[2][1]{%
%% #1 = number of list item to put in fbox
%% #2 = content which includes a {MyList}
%%
\noindent
\fboxsep=0pt
\fbox{%
%% This is to test this capability and display it to be able to see that it
%% worked as desired.
\begin{minipage}{0.5\linewidth}
\IncludeUpToFirstNItemsOfMyList[#1]{#2}%
\end{minipage}%
}%
\IncludeAfterFirstNItemsOfMyList[#1]{#2}%
}
\newcommand*{\MyContent}{%
Some optional content before the list.
\begin{MyList}
\item First Item of list. This will be nonempty, but may or may not have more than
one paragraph.
Second optional para of first Item.\MarkBoundaryPoint
\item Second Item is optional.
Could be zero (in which case this item would not exist)
or more paragraphs.
Second optional para of second Item.
\item Third Item is optional.
Second optional para of third Item.
\end{MyList}%
Some optional content after the list.
}%
\begin{document}
\PutPartOfListInFbox{\MyContent}
\end{document}


\item blubis executed. – Peter Grill Jul 30 '19 at 00:23MyListBoxed(in the example, 5 or lower). I was not sure about those edge cases; I decided not to draw any box in that case and to box the whole list if no threshold is given. That line was residue from testing, I removed it. – schtandard Jul 30 '19 at 01:00tempboxb. I thought I made the appropriate changes without issuing a\usebox{tempboxb}and the content is still displayed for some reason. For the MWE purposes you can just include a\usebox{tempboxb}after the last\end{MyList}. – Peter Grill Jul 30 '19 at 19:57Boxed, which should make it a bit easier to modify the environment, and appended an example boxing both parts of the list to the answer. – schtandard Jul 31 '19 at 17:50\saveboxes, not that I want an\fboxaround them necessarily. Basically, the second part needs to be saved for later use. – Peter Grill Aug 01 '19 at 06:41MyListBoxed? – schtandard Aug 01 '19 at 07:36MyListBoxed. The first part gets used inside, but the second part is used much later. That is what I suggested you can just include a\usebox{tempboxb}after the last\end{MyList}so that code is complete. – Peter Grill Aug 01 '19 at 07:44\@tempawith\def\@tempa{\end{Boxed}\global\setbox\@tempboxa=\vtop\bgroup}%, adding an\egroupafter the\end{MyList}%and a\bgroupbefore the\begin{MyList}%in the true-part of the\ifnum(in the original definition ofMyListBoxed) makes the second part of the list (including the between-text) globally available as\@tempboxa. You should probably define new box names, though. – schtandard Aug 01 '19 at 08:07