[Tex/LaTex] Create an enumerate environment that can be turned off

#enumerate

This question led to a new package:
comment_io

I would like to create a document using enumerate environments that I then could switch on and off before compiling.

For example, let's say that I have a section that looks like this:

\begin{enumerate}
    \item This is a test.
    \item This is another test.
    \item This is yet another test.
\end{enumerate}

This would, under normal circumstances, compile as an enumerated list with three items, like so:

1. This is a test.
2. This is another test.
3. This is yet another test.

I would like a way for this specific enumerate environment to vanish so that the compiled output looked something like this:

This is a test. This is another test. This is yet another test.

In addition, I would like to be able to do this globally for different environments (that is, not having to edit each instance of the environment in question at the local level).

However, I would still want to be able to have other enumerate environments in my documents that stayed put (even if they were nested within the vanishing environment).

Context: I would like to write my texts using the Tractatus style of placing each section in a enumerated hierarchy. However, I would also like to be able to remove this enumeration and just show the text as a regular article. Finally, in this regular article, I would like to have the ability to show enumerated lists (that then wouldn't be a part of the Tractatus enumeration).

Best Answer

For allowing nested enumerate (or other lists) environments to still function, you need to capture \item if you're going to make it a no-op inside this new on-off enumerate. For this we store its definition in the preamble and resture it for use at the beginning of every enuemrate using etoolbox's \AtBeginEnvironment. If you plan on nesting other lists as well, you need to restore \item in a similar manner.

Below I've defined enumerate* which is turned off during compilation, while it still supports nested enumerates:

enter image description here

\documentclass{article}
\usepackage{etoolbox}
\AtBeginEnvironment{enumerate}{\let\item\olditem}
\let\olditem\item
\newenvironment{enumerate*}
  {\par\let\item\relax}
  {\par}
\begin{document}

\begin{enumerate*}
  \item Something
    \begin{enumerate}
      \item Something else
      \item Another thing
        \begin{enumerate*}
          \item This is it
          \item This is another it
        \end{enumerate*}
    \end{enumerate}
  \item Last thing
\end{enumerate*}

\end{document}

enumerate* redefined \item to do nothing (be \relax). As such, it'll completely ignore any optional argument, if you have any. That is, \item[<stuff>] will default to [<stuff>]. That can be adjusted to gobble the optional argument, if needed.

One can also adjust the vertical adjustment inserted by enumerate*.

Related Question