2

I'd like to define an environment like this:

\newenvironment{antiitemize}{\end{itemize}}{\begin{itemize}}

I call it antiitemize because I intend to use it inside an itemize environment to break out of the list for a short while, e.g. to write a comment that's not really part of the list. For instance, I would like to write

\documentclass{article}

\newenvironment{antiitemize}{\end{itemize}}{\begin{itemize}}

\parindent=0pt

\begin{document}

Donec aliquam quam sed enim bibendum, quis ultrices felis porttitor.

\begin{itemize}

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit. 

\item Quisque ac porttitor lectus.

\begin{antiitemize}
Mauris a libero laoreet, iaculis arcu et, tincidunt quam.
\end{antiitemize}

\item Suspendisse auctor leo ut felis lobortis commodo vel quis diam.

\end{itemize}

Morbi nec rhoncus ante.

\end{document}

However, this doesn't work. LaTeX seems not to like that the environments are ill-nested. I've found a work-around that involves defining a pair of commands to start and end the antiitemize environment manually, like so.

\documentclass{article}

\def\antiitemize{\end{itemize}}
\def\endantiitemize{\begin{itemize}}

\parindent=0pt

\begin{document}

Donec aliquam quam sed enim bibendum, quis ultrices felis porttitor.

\begin{itemize}

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit. 

\item Quisque ac porttitor lectus.

\antiitemize
Mauris a libero laoreet, iaculis arcu et, tincidunt quam.
\endantiitemize

\item Suspendisse auctor leo ut felis lobortis commodo vel quis diam.

\end{itemize}

Morbi nec rhoncus ante.

\end{document}

This is tolerable, but I'd really like to know why I can't define my antiitemize environment using \newenvironment.


Edit. In response to some of the comments my question has received, here are a couple of notes about my motivation for asking this question.

  • cgnieder points out that \end{itemize}...\begin{itemize} would have the same effect as \begin{antiitemize}...\end{antiitemize}. This is true, but in my use case it's not a very 'semantic' way to do the document mark up. The stuff in my antiitemize environment should be thought of as 'an interruption in the list' rather than as 'ending one list and starting another'.

  • I didn't make this clear in my original question, but I guess what I'd really like an answer to is: why is my antiitemize environment broken?

  • You can use the package enumitem and the option resume. However I can't see any benefit for your declaration especially for a simple itemize environment. – Marco Daniel Aug 20 '14 at 11:58
  • 2
    Where is the advantage of typing \begin{antiitemize} instead of \end{itemize} (and vice versa)? – clemens Aug 20 '14 at 12:10
  • I'll just leave this here (accessible only to TUG members until about 9 mo have passed): tug.org/members/TUGboat/tb35-1/tb109hunt.pdf – Paul Gessler Aug 20 '14 at 13:14
  • mark wooding write a thing called mdwlist.sty, which includes \suspend and \resume commands, for doing “non-list” insertions into itemize (and the like) lists. look for the mdwtools directory on ctan. – wasteofspace Aug 20 '14 at 13:28
  • @cgnieder Good point. Your suggestion would have the same effect, but it wouldn't be so semantic, if you know what I mean. I've updated my answer to address your comment. – John Wickerson Aug 20 '14 at 14:01
2

You already can do that quite easily with the enumitem package: it has a resume* option that uses the parameters of the preceding list of the same type and level, and, for enumerate, starts the counter where the preceding list had left it. Demo:

 \documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage{amssymb} 
\usepackage[svgnames]{xcolor} 
\usepackage{enumitem}

\parindent=0pt

\begin{document}

Donec aliquam quam sed enim bibendum, quis ultrices felis porttitor.

\begin{itemize}[label =\color{VioletRed}$ \lozenge $]

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit.

\item Quisque ac porttitor lectus.

\end{itemize}
Mauris a libero laoreet, iaculis arcu et, tincidunt quam.

\begin{itemize}[resume*]

\item Suspendisse auctor leo ut felis lobortis commodo vel quis diam.

\end{itemize}

Morbi nec rhoncus ante.

\begin{itemize}

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit.

\item Quisque ac porttitor lectus.

\end{itemize}

\end{document} 

enter image description here

  • Where's the point in resuming an itemize list? The output without the option is the same as with it (except if you do the local label redefinition like in your example which IMHO is conceptually wrong and should go into the preamble even if one wants two different itemize lists) – clemens Aug 20 '14 at 12:55
  • Yes but it can be used with special values of parameters. It saves writing the same optional arguments again and again. I agree it's more useful for enumerate. Take a look at my updated answer. – Bernard Aug 20 '14 at 13:06
  • But if you have a special kind of list the way to go IMHO is to define a new list in the preamble and use that one in the document instead. And then resuming of the list is pointless. (And the question of the OP (how to leave the surrounding environment) then still isn't solved...) – clemens Aug 20 '14 at 13:09
  • Certainly, albeit it may depend on the number of such lists one has to write. – Bernard Aug 20 '14 at 13:11
  • Maybe... I for my part (nearly) always define new environments/commands for this. I like my document to be completely semantic. The “nearly” part has bitten me more than once already... I'm working on it to eliminate it :) – clemens Aug 20 '14 at 13:15
0

You could use \antiitemize and \endantiitemize in place of \begin{antiitemize} and \end{antiitemize}, and keep the environment definition.

\documentclass{article}

\newenvironment{antiitemize}{\end{itemize}}{\begin{itemize}}

\parindent=0pt

\begin{document}

Donec aliquam quam sed enim bibendum, quis ultrices felis porttitor.

\begin{itemize}

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit. 

\item Quisque ac porttitor lectus.

\antiitemize

Mauris a libero laoreet, iaculis arcu et, tincidunt quam.

\endantiitemize

\item Suspendisse auctor leo ut felis lobortis commodo vel quis diam.

\end{itemize}

Morbi nec rhoncus ante.

\end{document}

enter image description here

See the results here.

  • 1
    This is shown in the second example of the original post. – Marco Daniel Aug 20 '14 at 12:06
  • @MarcoDaniel the second example shows an explicit definition for \antiitemize and \endantiitemize. I propose to use their implicit definition, by maintaining the \newenvironment{antiitemize} command. – Alexis Pigeon Aug 20 '14 at 12:08
  • Why not the other way around \newenvironment{antiitemize}{\enditemize}{\itemize} and then use \begin{antiitemize} and \end{antiitemize}. – Manuel Aug 20 '14 at 12:14
  • @Manuel you could try it yourself to see why :) – clemens Aug 20 '14 at 12:16
  • 2
    @AlexisPigeon try it: it doesn't. While it gives no error the “escaped” paragraph is indented like it was still in an itemize environment – clemens Aug 20 '14 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.