[Tex/LaTex] Disable environment contents


I want to prevent the content of a custom environment from being shown. I've tried:

  %some stuff happens here

but this doesn't work.

Best Answer

Instead of \begin{comment} and \end{comment}, use \comment and \endcomment. The reason for this is that the \comment command proceeds by searching the text for the beginning of \end{<envname>}, where <envname> is the name of the environment it was called from.

This allows you to call comments from your own environments: \comment will see the end of your environment and know that the extent of the commenting has come to an end. With the code you gave, it would be looking for \end{comment}, never find it since it will never expand \end{asdf}, and continue forever.

(Oddly, this means that you must comment within a LaTeX environment: the pair of commands \comment/\endcomment, written directly into your document, will not work, unlike every other environment! But verbatim text, of which commenting is an example, is very odd all around.)

Related Question