wenzelm@55224: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wenzelm@55224: % Comment.sty version 3.6, October 1999
wenzelm@55224: %
wenzelm@55224: % Purpose:
wenzelm@55224: % selectively in/exclude pieces of text: the user can define new
wenzelm@55224: % comment versions, and each is controlled separately.
wenzelm@55224: % Special comments can be defined where the user specifies the
wenzelm@55224: % action that is to be taken with each comment line.
wenzelm@55224: %
wenzelm@55224: % Author
wenzelm@55224: % Victor Eijkhout
wenzelm@55224: % Department of Computer Science
wenzelm@55224: % University of Tennessee
wenzelm@55224: % 107 Ayres Hall
wenzelm@55224: % Knoxville TN 37996
wenzelm@55224: % USA
wenzelm@55224: %
wenzelm@55224: % victor@eijkhout.net
wenzelm@55224: %
wenzelm@55224: % This program is free software; you can redistribute it and/or
wenzelm@55224: % modify it under the terms of the GNU General Public License
wenzelm@55224: % as published by the Free Software Foundation; either version 2
wenzelm@55224: % of the License, or (at your option) any later version.
wenzelm@55224: %
wenzelm@55224: % This program is distributed in the hope that it will be useful,
wenzelm@55224: % but WITHOUT ANY WARRANTY; without even the implied warranty of
wenzelm@55224: % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wenzelm@55224: % GNU General Public License for more details.
wenzelm@55224: %
wenzelm@55224: % For a copy of the GNU General Public License, write to the
wenzelm@55224: % Free Software Foundation, Inc.,
wenzelm@55224: % 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA,
wenzelm@55224: % or find it on the net, for instance at
wenzelm@55224: % http://www.gnu.org/copyleft/gpl.html
wenzelm@55224: %
wenzelm@55224: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wenzelm@55224: % This style can be used with plain TeX or LaTeX, and probably
wenzelm@55224: % most other packages too.
wenzelm@55224: %
wenzelm@55224: % Usage: all text included between
wenzelm@55224: % \comment ... \endcomment
wenzelm@55224: % or \begin{comment} ... \end{comment}
wenzelm@55224: % is discarded.
wenzelm@55224: %
wenzelm@55224: % The opening and closing commands should appear on a line
wenzelm@55224: % of their own. No starting spaces, nothing after it.
wenzelm@55224: % This environment should work with arbitrary amounts
wenzelm@55224: % of comment, and the comment can be arbitrary text.
wenzelm@55224: %
wenzelm@55224: % Other `comment' environments are defined by
wenzelm@55224: % and are selected/deselected with
wenzelm@55224: % \includecomment{versiona}
wenzelm@55224: % \excludecoment{versionb}
wenzelm@55224: %
wenzelm@55224: % These environments are used as
wenzelm@55224: % \versiona ... \endversiona
wenzelm@55224: % or \begin{versiona} ... \end{versiona}
wenzelm@55224: % with the opening and closing commands again on a line of
wenzelm@55224: % their own.
wenzelm@55224: %
wenzelm@55224: % LaTeX users note: for an included comment, the
wenzelm@55224: % \begin and \end lines act as if they don't exist.
wenzelm@55224: % In particular, they don't imply grouping, so assignments
wenzelm@55224: % &c are not local.
wenzelm@55224: %
wenzelm@55224: % Special comments are defined as
wenzelm@55224: % \specialcomment{name}{before commands}{after commands}
wenzelm@55224: % where the second and third arguments are executed before
wenzelm@55224: % and after each comment block. You can use this for global
wenzelm@55224: % formatting commands.
wenzelm@55224: % To keep definitions &c local, you can include \begingroup
wenzelm@55224: % in the `before commands' and \endgroup in the `after commands'.
wenzelm@55224: % ex:
wenzelm@55224: % \specialcomment{smalltt}
wenzelm@55224: % {\begingroup\ttfamily\footnotesize}{\endgroup}
wenzelm@55224: % You do *not* have to do an additional
wenzelm@55224: % \includecomment{smalltt}
wenzelm@55224: % To remove 'smalltt' blocks, give \excludecomment{smalltt}
wenzelm@55224: % after the definition.
wenzelm@55224: %
wenzelm@55224: % Processing comments can apply processing to each line.
wenzelm@55224: % \processcomment{name}{each-line commands}%
wenzelm@55224: % {before commands}{after commands}
wenzelm@55224: % By defining a control sequence
wenzelm@55224: % \def\Thiscomment##1{...} in the before commands the user can
wenzelm@55224: % specify what is to be done with each comment line.
wenzelm@55224: % BUG this does not work quite yet BUG
wenzelm@55224: %
wenzelm@55224: % Trick for short in/exclude macros (such as \maybe{this snippet}):
wenzelm@55224: %\includecomment{cond}
wenzelm@55224: %\newcommand{\maybe}[1]{}
wenzelm@55224: %\begin{cond}
wenzelm@55224: %\renewcommand{\maybe}[1]{#1}
wenzelm@55224: %\end{cond}
wenzelm@55224: %
wenzelm@55224: % Basic approach of the implementation:
wenzelm@55224: % to comment something out, scoop up every line in verbatim mode
wenzelm@55224: % as macro argument, then throw it away.
wenzelm@55224: % For inclusions, in LaTeX the block is written out to
wenzelm@55224: % a file \CommentCutFile (default "comment.cut"), which is
wenzelm@55224: % then included.
wenzelm@55224: % In plain TeX (and other formats) both the opening and
wenzelm@55224: % closing comands are defined as noop.
wenzelm@55224: %
wenzelm@55224: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wenzelm@55224: % Changes in version 3.1
wenzelm@55224: % - updated author's address
wenzelm@55224: % - cleaned up some code
wenzelm@55224: % - trailing contents on \begin{env} line is always discarded
wenzelm@55224: % even if you've done \includecomment{env}
wenzelm@55224: % - comments no longer define grouping!! you can even
wenzelm@55224: % \includecomment{env}
wenzelm@55224: % \begin{env}
wenzelm@55224: % \begin{itemize}
wenzelm@55224: % \end{env}
wenzelm@55224: % Isn't that something ...
wenzelm@55224: % - included comments are written to file and input again.
wenzelm@55224: % Changes in 3.2
wenzelm@55224: % - \specialcomment brought up to date (thanks to Ivo Welch).
wenzelm@55224: % Changes in 3.3
wenzelm@55224: % - updated author's address again
wenzelm@55224: % - parametrised \CommentCutFile
wenzelm@55224: % Changes in 3.4
wenzelm@55224: % - added GNU public license
wenzelm@55224: % - added \processcomment, because Ivo's fix (above) brought an
wenzelm@55224: % inconsistency to light.
wenzelm@55224: % Changes in 3.5
wenzelm@55224: % - corrected typo in header.
wenzelm@55224: % - changed author email
wenzelm@55224: % - corrected \specialcomment yet again.
wenzelm@55224: % - fixed excludecomment of an earlier defined environment.
wenzelm@55224: % Changes in 3.6
wenzelm@55224: % - The 'cut' file is now written more verbatim, using \meaning;
wenzelm@55224: % some people reported having trouble with ISO latin 1, or umlaute.sty.
wenzelm@55224: % - removed some \newif statements.
wenzelm@55224: % Has this suddenly become \outer again?
wenzelm@55224: %
wenzelm@55224: % Known bugs:
wenzelm@55224: % - excludecomment leads to one superfluous space
wenzelm@55224: % - processcomment leads to a superfluous line break
wenzelm@55224: %
wenzelm@55224: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wenzelm@55224:
wenzelm@55224: \def\makeinnocent#1{\catcode`#1=12 }
wenzelm@55224: \def\csarg#1#2{\expandafter#1\csname#2\endcsname}
wenzelm@55224: \def\latexname{lplain}\def\latexename{LaTeX2e}
wenzelm@55224: \newwrite\CommentStream
wenzelm@55224: \def\CommentCutFile{comment.cut}
wenzelm@55224:
wenzelm@55224: \def\ProcessComment#1% start it all of
wenzelm@55224: {\begingroup
wenzelm@55224: \def\CurrentComment{#1}%
wenzelm@55224: \let\do\makeinnocent \dospecials
wenzelm@55224: \makeinnocent\^^L% and whatever other special cases
wenzelm@55224: \endlinechar`\^^M \catcode`\^^M=12 \xComment}
wenzelm@55224: %\def\ProcessCommentWithArg#1#2% to be used in \leveledcomment
wenzelm@55224: % {\begingroup
wenzelm@55224: % \def\CurrentComment{#1}%
wenzelm@55224: % \let\do\makeinnocent \dospecials
wenzelm@55224: % \makeinnocent\^^L% and whatever other special cases
wenzelm@55224: % \endlinechar`\^^M \catcode`\^^M=12 \xComment}
wenzelm@55224: {\catcode`\^^M=12 \endlinechar=-1 %
wenzelm@55224: \gdef\xComment#1^^M{%
wenzelm@55224: \expandafter\ProcessCommentLine}
wenzelm@55224: \gdef\ProcessCommentLine#1^^M{\def\test{#1}
wenzelm@55224: \csarg\ifx{End\CurrentComment Test}\test
wenzelm@55224: \edef\next{\noexpand\EndOfComment{\CurrentComment}}%
wenzelm@55224: \else \ThisComment{#1}\let\next\ProcessCommentLine
wenzelm@55224: \fi \next}
wenzelm@55224: }
wenzelm@55224:
wenzelm@55224: \def\CSstringmeaning#1{\expandafter\CSgobblearrow\meaning#1}
wenzelm@55224: \def\CSstringcsnoescape#1{\expandafter\CSgobbleescape\string#1}
wenzelm@55224: {\escapechar-1
wenzelm@55224: \expandafter\expandafter\expandafter\gdef
wenzelm@55224: \expandafter\expandafter\expandafter\CSgobblearrow
wenzelm@55224: \expandafter\string\csname macro:->\endcsname{}
wenzelm@55224: }
wenzelm@55224: \def\CSgobbleescape#1{\ifnum`\\=`#1 \else #1\fi}
wenzelm@55224: \def\WriteCommentLine#1{\def\CStmp{#1}%
wenzelm@55224: \immediate\write\CommentStream{\CSstringmeaning\CStmp}}
wenzelm@55224:
wenzelm@55224: % 3.1 change: in LaTeX and LaTeX2e prevent grouping
wenzelm@55224: \if 0%
wenzelm@55224: \ifx\fmtname\latexename
wenzelm@55224: 0%
wenzelm@55224: \else \ifx\fmtname\latexname
wenzelm@55224: 0%
wenzelm@55224: \else
wenzelm@55224: 1%
wenzelm@55224: \fi \fi
wenzelm@55224: %%%%
wenzelm@55224: %%%% definitions for LaTeX
wenzelm@55224: %%%%
wenzelm@55224: \def\AfterIncludedComment
wenzelm@55224: {\immediate\closeout\CommentStream
wenzelm@55224: \input{\CommentCutFile}\relax
wenzelm@55224: }%
wenzelm@55224: \def\TossComment{\immediate\closeout\CommentStream}
wenzelm@55224: \def\BeforeIncludedComment
wenzelm@55224: {\immediate\openout\CommentStream=\CommentCutFile
wenzelm@55224: \let\ThisComment\WriteCommentLine}
wenzelm@55224: \def\includecomment
wenzelm@55224: #1{\message{Include comment '#1'}%
wenzelm@55224: \csarg\let{After#1Comment}\AfterIncludedComment
wenzelm@55224: \csarg\def{#1}{\BeforeIncludedComment
wenzelm@55224: \ProcessComment{#1}}%
wenzelm@55224: \CommentEndDef{#1}}
wenzelm@55224: \long\def\specialcomment
wenzelm@55224: #1#2#3{\message{Special comment '#1'}%
wenzelm@55224: % note: \AfterIncludedComment does \input, so #2 goes here!
wenzelm@55224: \csarg\def{After#1Comment}{#2\AfterIncludedComment#3}%
wenzelm@55224: \csarg\def{#1}{\BeforeIncludedComment\relax
wenzelm@55224: \ProcessComment{#1}}%
wenzelm@55224: \CommentEndDef{#1}}
wenzelm@55224: \long\def\processcomment
wenzelm@55224: #1#2#3#4{\message{Lines-Processing comment '#1'}%
wenzelm@55224: \csarg\def{After#1Comment}{#3\AfterIncludedComment#4}%
wenzelm@55224: \csarg\def{#1}{\BeforeIncludedComment#2\relax
wenzelm@55224: \ProcessComment{#1}}%
wenzelm@55224: \CommentEndDef{#1}}
wenzelm@55224: \def\leveledcomment
wenzelm@55224: #1#2{\message{Include comment '#1' up to level '#2'}%
wenzelm@55224: %\csname #1IsLeveledCommenttrue\endcsname
wenzelm@55224: \csarg\let{After#1Comment}\AfterIncludedComment
wenzelm@55224: \csarg\def{#1}{\BeforeIncludedComment
wenzelm@55224: \ProcessCommentWithArg{#1}}%
wenzelm@55224: \CommentEndDef{#1}}
wenzelm@55224: \else
wenzelm@55224: %%%%
wenzelm@55224: %%%%plain TeX and other formats
wenzelm@55224: %%%%
wenzelm@55224: \def\includecomment
wenzelm@55224: #1{\message{Including comment '#1'}%
wenzelm@55224: \csarg\def{#1}{}%
wenzelm@55224: \csarg\def{end#1}{}}
wenzelm@55224: \long\def\specialcomment
wenzelm@55224: #1#2#3{\message{Special comment '#1'}%
wenzelm@55224: \csarg\def{#1}{\def\ThisComment{}\def\AfterComment{#3}#2%
wenzelm@55224: \ProcessComment{#1}}%
wenzelm@55224: \CommentEndDef{#1}}
wenzelm@55224: \fi
wenzelm@55224:
wenzelm@55224: %%%%
wenzelm@55224: %%%% general definition of skipped comment
wenzelm@55224: %%%%
wenzelm@55224: \def\excludecomment
wenzelm@55224: #1{\message{Excluding comment '#1'}%
wenzelm@55224: \csarg\def{#1}{\let\AfterComment\relax
wenzelm@55224: \def\ThisComment####1{}\ProcessComment{#1}}%
wenzelm@55224: \csarg\let{After#1Comment}\TossComment
wenzelm@55224: \CommentEndDef{#1}}
wenzelm@55224:
wenzelm@55224: \if 0%
wenzelm@55224: \ifx\fmtname\latexename
wenzelm@55224: 0%
wenzelm@55224: \else \ifx\fmtname\latexname
wenzelm@55224: 0%
wenzelm@55224: \else
wenzelm@55224: 1%
wenzelm@55224: \fi \fi
wenzelm@55224: % latex & latex2e:
wenzelm@55224: \def\EndOfComment#1{\endgroup\end{#1}%
wenzelm@55224: \csname After#1Comment\endcsname}
wenzelm@55224: \def\CommentEndDef#1{{\escapechar=-1\relax
wenzelm@55224: \csarg\xdef{End#1Test}{\string\\end\string\{#1\string\}}%
wenzelm@55224: }}
wenzelm@55224: \else
wenzelm@55224: % plain & other
wenzelm@55224: \def\EndOfComment#1{\endgroup\AfterComment}
wenzelm@55224: \def\CommentEndDef#1{{\escapechar=-1\relax
wenzelm@55224: \csarg\xdef{End#1Test}{\string\\end#1}%
wenzelm@55224: }}
wenzelm@55224: \fi
wenzelm@55224:
wenzelm@55224: \excludecomment{comment}
wenzelm@55224:
wenzelm@55224: \endinput