One can produce a solution by adapting some of the code from amsmath.sty
. Don't worry about the details if they seem complicated, but here is some code that you can use, with some commentary.
Code to enable the ignoring of the remaining items in a list
We need some way of collecting everything that remains in the itemized list after a certain point, where the bullet points might also have environments in them. This strongly motivates that we use code very much similar to that used by the amsmath
environments to collect the bodies of the align
, gather
, and other multi-line math environments.
Edit: as noted by egreg
in the comments, most of this functionality is provided by the environ
package, which we may include to simplify the code. However, we do still need a modified version of the main macro \collect@body
, used in the amsmath
environments, to control what is actually done with the list items that have been collected. We give it a different name so that it doesn't conflict with the existing macro, and modify it slightly. Specifically, the new macro doesn't accept (or do anything with) an argument, and rather than actually using the contents of the source which it has collected, it executes a macro to stand in for all of the remaining items in the list. (This macro can be modified, separately, to do whatever you like, including nothing at all.)
\usepackage{environ}% <--- for \collect@@body, etc.
\makeatletter
\def\truncatedlist@omit{%
\edef\process@envbody{%
\noexpand\let\noexpand\item\noexpand\orig@item
\noexpand\omitlistitems \noexpand\end{\@currenvir}}%
\@envbody\@emptytoks \def\begin@stack{b}%
\begingroup
\expandafter\let\csname\@currenvir\endcsname\collect@@body
\edef\process@envbody{\expandafter\noexpand\csname\@currenvir\endcsname}%
\process@envbody
}
Note in particular the first line, which redefines \item
to be the value of some macro \orig@item
. This is because, for your truncated list environment, we will be modifying the definition of \item
, but might like to use the original meaning of \item
when describing what to do instead of the omitted items.
Defining the new truncated list environment
Now we get to the point of the exercise. Define two counters:
\newcounter{trunclistnum}
\newcounter{trunclistlimit}
\setcounter{trunclistlimit}{3}% <--- or whatever limit you prefer
We also define what to do with the omitted items.
\def\omitlistitems{\item $\cdots$}
% or if you prefer, \def\omitlistitems{}
Finally, we define the list itself. The following code is basically a modification of the itemize
environment as found in latex.ltx
. It sets the count of the number of items to zero, and redefines \item
to check whether the number of items exceeds the limit. If it does, it calls the macro which is used to omit the rest of the items; otherwise it calls a macro which contains the original behaviour of \item
.
\let\endtruncitemize\enditemize
\def\truncitemize{%
\ifnum \@itemdepth >\thr@@\@toodeep\else
\c@trunclistnum=0\relax
\let\orig@item\item
\def\item{%
\ifnum\c@trunclistnum<\c@trunclistlimit
\let\@tempa\orig@item%
\else
\let\@tempa\truncatedlist@omit%
\fi
\advance\c@trunclistnum by 1%
\@tempa}%
\advance\@itemdepth\@ne
\edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
\expandafter
\list
\csname\@itemitem\endcsname
{\def\makelabel##1{\hss\llap{##1}}}%
\fi}
\makeatother
Demonstration
Put all of that into the pre-amble of a document, and give the following a try:
\begin{document}
\subsection*{Result}
A truncated itemized list:
\begin{truncitemize}
\item First item
\item Second item
\item Third item
\item Fourth item
\item Yet further items
\end{truncitemize}
A normal itemized list:
\begin{itemize}
\item First item
\item Second item
\item Third item
\item Fourth item
\item Yet further items
\end{itemize}
\end{document}

myitemize
? Are the items saved in a macro?myitemize
to represent a modifieditemized
environment. No, the items are not saved in a macro.\makeatletter\newenvironment{wrapper{\begin{truncitemize}\bgroup\def\@currenvir{wrapper}}\egroup\end{truncitemize}}\makeatother
which, while slightly cludgy, should do the trick. Alternatively, you could adapt the\truncitemize
macro to take an optional argument for the name of a wrapper environment, which would provide a slightly cleaner interface. If you're confident it won't get clobbered, even a very slight redefinition of the\begin
macro to save the name of the current (i.e. wrapper) environment, for use by\truncitemize
, would do.