# Bad interaction between comment package and enumerate environment?

I'm trying to use the comment package inside an enumerate environment, and it produces a compilation error. Minimal example:

\documentclass{article}
\usepackage{comment}

\specialcomment{com}{}{}
\excludecomment{com}

\begin{document}
\begin{enumerate}
\item Outside.
\begin{com}
Inside.
\end{com}
\end{enumerate}
\end{document}

This produces the following error:

Runaway argument?
! File ended while scanning use of \next.
<inserted text>
\par

For reference, everything works fine without enumerate, as in the following example:

\documentclass{article}
\usepackage{comment}

\specialcomment{com}{}{}
\excludecomment{com}

\begin{document}
Outside.
\begin{com}
Inside.
\end{com}
\end{document}

Is this a known problem? I'm having trouble finding anything about it ("comment" isn't exactly a Google-friendly term to search for…).

-
Strange. If I unindent your com block, I don't get the error. I think you found a bug. –  hpesoj626 Jan 12 '13 at 11:04
Page 1 of the documentation of comment: “The opening and closing commands should appear on a line of their own. No starting spaces, nothing after it.” –  egreg Jan 12 '13 at 11:29
@hpesoj626 Oh, good catch! Similarly, it stops working when I indent the the com block in the working example, so it seems to be about indentation, not enumerate. –  jathd Jan 12 '13 at 11:29
@egreg Ah, I read the first sentence of what you quote in the doc, but not the second… That'll teach me. Can you make that into an answer so I can accept it? –  jathd Jan 12 '13 at 11:32
@egreg I think that is an answer. Was it you who said looking at documentation is cheating? ;) Or did somebody else say that? –  hpesoj626 Jan 12 '13 at 11:32

The comment package has an important limitation; quoting from the documentation

The opening and closing commands should appear on a line of their own. No starting spaces, nothing after it.

So there's not much more to say about it: don't indent the environment that you want to "comment out".

Here's a different implementation; I've left the same syntax for \specialcomment with three arguments, although nothing is done with the second and third (it can be improved for using them).

\documentclass{article}
\usepackage{environ,etoolbox}

\newcommand\specialcomment[3]{%
\newtoggle{#1}\toggletrue{#1}
\NewEnviron{#1}{\iftoggle{#1}{\BODY}{}}
}
\newcommand{\excludecomment}[1]{\togglefalse{#1}}
\newcommand{\includecomment}[1]{\toggletrue{#1}}

\specialcomment{com}{}{}
\excludecomment{com}

\begin{document}
\begin{enumerate}
\item Outside.
\begin{com}
Inside.
\end{com}
\item Outside. Inside.
\end{enumerate}
\end{document}
-
thanks for "The opening and closing commands should appear on a line of their own. No starting spaces, nothing after it." –  tim Jan 15 '14 at 18:28