1

I want to replicate the environment comment from the comment package:

\begin{comment}
Hidden stuff.
\end{comment}

which prints just nothing, instead of using % to comment things out.

I can do it with a command, such as \def\comment#1{}, and now I want to turn it into an environment.

The motivation is to make an environment that would conditionally hide the text completely or do something with it, such as change color:

\@ifundefined{flag}%
{\newenvironment{flagged}{\it\color{red}(}{)}}%
{\newenvironment{flagged}{\comment\bgroup}{\egroup}}

In the second case the intention is to make the text argument of the macro: \comment\bgroup Hidden stuff\egroup. This does not work because \bgroup\egroup cannot delimit an argument of a macro.

\includepackage{comment}
...
{\newenvironment{flagged}{\begin{comment}}{\end{comment}}}

does not work either, I guess because the comment package expects a literal string \end{comment}:

! File ended while scanning use of \next.

How to do this?

1 Answers1

1

The comment package provides a mechanism to do this via \specialcomment and \excludecomment.