# Re: LaTeX Q: Nullify A Custom Environment?

Randy Yates wrote:

....
I have defined a comment environment,
....
Now I'd like to redefine the environment definition so that the
comment environment text is "nullified" (i.e., removed).

Any suggestions on how to do this?
....

If you "nullify" stuff which is numbered, consecutive numbering
is affected. Nullifying a section or a theorem will result in
consecutive sections'/theorems' numbers being decreased by 1 in
comparison to the numbers that get assigned if nullifying does
not take place.
Page-numbering and thus pageref-numbers etc will also be
affected. Henceforth I assume your awareness of the like and
therefore will leave the related details (correct counter-
management etc) to you.

My suggestion requires at least a simplified explanation of
LaTeX2e-internal-concepts:

By calling the environment "foo" via \begin{foo}...\end{foo},
internally the macros \foo and \endfoo are called within a
group.

You can use this mechanism for defining two environments:
"VisibleComment" and "InvisibleComment" in terms of
\newenvironment. A third environment "VariatingComment" is
created in terms of \let by saying/toggling:
\let\VariatingComment=\VisibleComment
\let\endVariatingComment=\endVisibleComment
respective:
\let\VariatingComment=\InvisibleComment
\let\endVariatingComment=\endInvisibleComment

In order to create the "InvisibleComment"-environment, I
borrowed the comment-environment from the verbatim-package.

In the example I also took care that the environments
"VisibleComment" and "InvisibleComment" and thus also the
environment "VariatingComment" take an optional argument.
"VisibleComment" won't do anything to it. "InVisibleComment"
will call it. This gives the possibility to preserve numbering
of trailing stuff by performing "manual" counter-adjustments and
the like for the case that some numbered stuff like a section or
a theorem gets nullified.

I also implemented functionality which makes it possible to
exclude single "VariatingComment"-instances from toggling
between visibility and invisibility.
Therefore it is necessary to internally toggle to the user-
specified standard-behavior at the end of each environment by

\documentclass{article}
\usepackage{verbatim}
\usepackage{color}
\usepackage{amsmath}
\definecolor{commentcolor}{gray}{0.75}

% Let's create an environment for the visible comments
% (Environment is always executed in group - you don't
% need extra grouping. Also \bfseries and \scshape
% don't work together.):
\newenvironment{VisibleComment}[1][]
{\color{commentcolor}\sffamily\bfseries}

% verbatim-package - the comment-environment. So let's create an
% environment identical to that comment-environment except that
% it will always reset to the standard-behavior specified by
% the user in preamble or wherever:
\newenvironment{InvisibleComment}[1][]
{#1\comment}

% The following macro is a placeholder for resetting to the
% standard-behavior for VariatingComment-environments.
% The standard-behavior later gets specified by the
% user. The standard-setting-macros
% redefine this command accordingly:

% The following macro is used for specifying that comments
% created by VariatingComment-environments shall be
% invisible by standard:
\global\let\VariatingComment\InvisibleComment
\global\let\endVariatingComment\endInvisibleComment
}%
}%

% The following macro is used for specifying that comments
% created by VariatingComment-environments shall be
% visible by standard:
\global\let\VariatingComment\VisibleComment
\global\let\endVariatingComment\endVisibleComment
}%
}%

% Let's create the VariatingComment-environment and initially
% toggle to "VisibleComment" which is standard if
% none of the directives
% is supplied by the user:
\newenvironment{VariatingComment}{}{}

% The following macro will switch the next VariatingComment
% to be an InvisibleComment. (At the end of the environment-
% call, \SetToCommentStandardBehavior is called, so this
% change takes effect only once:
\global\let\VariatingComment\InvisibleComment
\global\let\endVariatingComment\endInvisibleComment
}%

% The following macro will switch the next VariatingComment
% to be an VisibleComment. (At the end of the environment-
% call, \SetToCommentStandardBehavior is called, so this
% change takes effect only once:
\global\let\VariatingComment\VisibleComment
\global\let\endVariatingComment\endVisibleComment
}%

% Play around here and see what happens:

\begin{document}

This is some text which precedes the comments.

\begin{VariatingComment}
Test 1
\end{VariatingComment}

\begin{VariatingComment}
Test 2
\end{VariatingComment}

\begin{VariatingComment}
Test 3
\end{VariatingComment}

\begin{VariatingComment}[Test 4 optional action if invisible]
Test 4
\end{VariatingComment}

\begin{VariatingComment}
Test 5
\end{VariatingComment}

\begin{VariatingComment}
Test 6
\end{VariatingComment}

This is some text which trails the comments.

\end{document}

I hope this concept fits your needs :-)

Ulrich

.