%% Save file as: COMMENT.STY                    Source: FILESERV@SHSU.BITNET
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Comment.sty   version 2.0, 19 June 1992
% selectively in/exclude pieces of text: the user can define new
% comment versions, and each is controlled separately.
% This style can be used with plain TeX or LaTeX, and probably
% most other packages too.
%
% Examples of use in LaTeX and TeX follow \endinput
%
% Author
%    Victor Eijkhout
%    Department of Computer Science
%    University Tennessee at Knoxville
%    104 Ayres Hall
%    Knoxville, TN 37996
%    USA
%
%    eijkhout@cs.utk.edu
%
% Usage: all text included in between
%    \comment ... \endcomment
% or \begin{comment} ... \end{comment}
% is discarded. The closing command should appear on a line
% of its own. No starting spaces, nothing after it.
% This environment should work with arbitrary amounts
% of comment.
%
% Other 'comment' environments are defined by
% and are selected/deselected with
% \includecomment{versiona}
% \excludecoment{versionb}
%
% These environments are used as
% \versiona ... \endversiona
% or \begin{versiona} ... \end{versiona}
% with the closing command again on a line of its own.
%
% Basic approach:
% to comment something out, scoop up  every line in verbatim mode
% as macro argument, then throw it away.
% For inclusions, both the opening and closing comands
% are defined as noop

\def\makeinnocent#1{\catcode`#1=12 }
\def\csarg#1#2{\expandafter#1\csname#2\endcsname}

\def\ThrowAwayComment#1{\begingroup
    \def\CurrentComment{#1}%
    \let\do\makeinnocent \dospecials
    \makeinnocent\^^L% and whatever other special cases
    \endlinechar`\^^M \catcode`\^^M=12 \xComment}
{\catcode`\^^M=12 \endlinechar=-1 %
 \gdef\xComment#1^^M{\def\test{#1}
      \csarg\ifx{PlainEnd\CurrentComment Test}\test
          \let\next\endgroup
      \else \csarg\ifx{LaLaEnd\CurrentComment Test}\test
            \edef\next{\endgroup\noexpand\end{\CurrentComment}}
      \else \let\next\xComment
      \fi \fi \next}
}

\def\includecomment
 #1{\expandafter\def\csname#1\endcsname{}%
    \expandafter\def\csname end#1\endcsname{}}
\def\excludecomment
 #1{\expandafter\def\csname#1\endcsname{\ThrowAwayComment{#1}}%
    {\escapechar=-1\relax
     \csarg\xdef{PlainEnd#1Test}{\string\\end#1}%
     \csarg\xdef{LaLaEnd#1Test}{\string\\end\string\{#1\string\}}%
    }}

\excludecomment{comment}

\endinput
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Example of LaTeX usage:

\documentstyle[comment]{article}
\begin{document}

This \comment Is not
\endcomment
printed.

\includecomment{versiona}
\excludecomment{versionb}

Text for a:
\begin{versiona}
is included.
\end{versiona}

Text for b:
%\tracingall
\begin{versionb}
is not included.
\end{versionb}

As we all can see.

\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Example of TeX usage:

\input comment

This \comment Is not
\endcomment
printed.

\includecomment{versiona}
\excludecomment{versionb}

Text for a:
\versiona
is included.
\endversiona

Text for b:
\versionb
is not included.
\endversionb

As we all can see.

\bye
