1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % Comment.sty version 3.6, October 1999
5 % selectively in/exclude pieces of text: the user can define new
6 % comment versions, and each is controlled separately.
7 % Special comments can be defined where the user specifies the
8 % action that is to be taken with each comment line.
12 % Department of Computer Science
13 % University of Tennessee
20 % This program is free software; you can redistribute it and/or
21 % modify it under the terms of the GNU General Public License
22 % as published by the Free Software Foundation; either version 2
23 % of the License, or (at your option) any later version.
25 % This program is distributed in the hope that it will be useful,
26 % but WITHOUT ANY WARRANTY; without even the implied warranty of
27 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 % GNU General Public License for more details.
30 % For a copy of the GNU General Public License, write to the
31 % Free Software Foundation, Inc.,
32 % 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA,
33 % or find it on the net, for instance at
34 % http://www.gnu.org/copyleft/gpl.html
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 % This style can be used with plain TeX or LaTeX, and probably
38 % most other packages too.
40 % Usage: all text included between
41 % \comment ... \endcomment
42 % or \begin{comment} ... \end{comment}
45 % The opening and closing commands should appear on a line
46 % of their own. No starting spaces, nothing after it.
47 % This environment should work with arbitrary amounts
48 % of comment, and the comment can be arbitrary text.
50 % Other `comment' environments are defined by
51 % and are selected/deselected with
52 % \includecomment{versiona}
53 % \excludecoment{versionb}
55 % These environments are used as
56 % \versiona ... \endversiona
57 % or \begin{versiona} ... \end{versiona}
58 % with the opening and closing commands again on a line of
61 % LaTeX users note: for an included comment, the
62 % \begin and \end lines act as if they don't exist.
63 % In particular, they don't imply grouping, so assignments
66 % Special comments are defined as
67 % \specialcomment{name}{before commands}{after commands}
68 % where the second and third arguments are executed before
69 % and after each comment block. You can use this for global
70 % formatting commands.
71 % To keep definitions &c local, you can include \begingroup
72 % in the `before commands' and \endgroup in the `after commands'.
74 % \specialcomment{smalltt}
75 % {\begingroup\ttfamily\footnotesize}{\endgroup}
76 % You do *not* have to do an additional
77 % \includecomment{smalltt}
78 % To remove 'smalltt' blocks, give \excludecomment{smalltt}
79 % after the definition.
81 % Processing comments can apply processing to each line.
82 % \processcomment{name}{each-line commands}%
83 % {before commands}{after commands}
84 % By defining a control sequence
85 % \def\Thiscomment##1{...} in the before commands the user can
86 % specify what is to be done with each comment line.
87 % BUG this does not work quite yet BUG
89 % Trick for short in/exclude macros (such as \maybe{this snippet}):
90 %\includecomment{cond}
91 %\newcommand{\maybe}[1]{}
93 %\renewcommand{\maybe}[1]{#1}
96 % Basic approach of the implementation:
97 % to comment something out, scoop up every line in verbatim mode
98 % as macro argument, then throw it away.
99 % For inclusions, in LaTeX the block is written out to
100 % a file \CommentCutFile (default "comment.cut"), which is
102 % In plain TeX (and other formats) both the opening and
103 % closing comands are defined as noop.
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 % Changes in version 3.1
107 % - updated author's address
108 % - cleaned up some code
109 % - trailing contents on \begin{env} line is always discarded
110 % even if you've done \includecomment{env}
111 % - comments no longer define grouping!! you can even
112 % \includecomment{env}
116 % Isn't that something ...
117 % - included comments are written to file and input again.
119 % - \specialcomment brought up to date (thanks to Ivo Welch).
121 % - updated author's address again
122 % - parametrised \CommentCutFile
124 % - added GNU public license
125 % - added \processcomment, because Ivo's fix (above) brought an
126 % inconsistency to light.
128 % - corrected typo in header.
129 % - changed author email
130 % - corrected \specialcomment yet again.
131 % - fixed excludecomment of an earlier defined environment.
133 % - The 'cut' file is now written more verbatim, using \meaning;
134 % some people reported having trouble with ISO latin 1, or umlaute.sty.
135 % - removed some \newif statements.
136 % Has this suddenly become \outer again?
139 % - excludecomment leads to one superfluous space
140 % - processcomment leads to a superfluous line break
142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 \def\makeinnocent#1{\catcode`#1=12 }
145 \def\csarg#1#2{\expandafter#1\csname#2\endcsname}
146 \def\latexname{lplain}\def\latexename{LaTeX2e}
147 \newwrite\CommentStream
148 \def\CommentCutFile{comment.cut}
150 \def\ProcessComment#1% start it all of
152 \def\CurrentComment{#1}%
153 \let\do\makeinnocent \dospecials
154 \makeinnocent\^^L% and whatever other special cases
155 \endlinechar`\^^M \catcode`\^^M=12 \xComment}
156 %\def\ProcessCommentWithArg#1#2% to be used in \leveledcomment
158 % \def\CurrentComment{#1}%
159 % \let\do\makeinnocent \dospecials
160 % \makeinnocent\^^L% and whatever other special cases
161 % \endlinechar`\^^M \catcode`\^^M=12 \xComment}
162 {\catcode`\^^M=12 \endlinechar=-1 %
163 \gdef\xComment#1^^M{%
164 \expandafter\ProcessCommentLine}
165 \gdef\ProcessCommentLine#1^^M{\def\test{#1}
166 \csarg\ifx{End\CurrentComment Test}\test
167 \edef\next{\noexpand\EndOfComment{\CurrentComment}}%
168 \else \ThisComment{#1}\let\next\ProcessCommentLine
172 \def\CSstringmeaning#1{\expandafter\CSgobblearrow\meaning#1}
173 \def\CSstringcsnoescape#1{\expandafter\CSgobbleescape\string#1}
175 \expandafter\expandafter\expandafter\gdef
176 \expandafter\expandafter\expandafter\CSgobblearrow
177 \expandafter\string\csname macro:->\endcsname{}
179 \def\CSgobbleescape#1{\ifnum`\\=`#1 \else #1\fi}
180 \def\WriteCommentLine#1{\def\CStmp{#1}%
181 \immediate\write\CommentStream{\CSstringmeaning\CStmp}}
183 % 3.1 change: in LaTeX and LaTeX2e prevent grouping
185 \ifx\fmtname\latexename
187 \else \ifx\fmtname\latexname
193 %%%% definitions for LaTeX
195 \def\AfterIncludedComment
196 {\immediate\closeout\CommentStream
197 \input{\CommentCutFile}\relax
199 \def\TossComment{\immediate\closeout\CommentStream}
200 \def\BeforeIncludedComment
201 {\immediate\openout\CommentStream=\CommentCutFile
202 \let\ThisComment\WriteCommentLine}
204 #1{\message{Include comment '#1'}%
205 \csarg\let{After#1Comment}\AfterIncludedComment
206 \csarg\def{#1}{\BeforeIncludedComment
207 \ProcessComment{#1}}%
209 \long\def\specialcomment
210 #1#2#3{\message{Special comment '#1'}%
211 % note: \AfterIncludedComment does \input, so #2 goes here!
212 \csarg\def{After#1Comment}{#2\AfterIncludedComment#3}%
213 \csarg\def{#1}{\BeforeIncludedComment\relax
214 \ProcessComment{#1}}%
216 \long\def\processcomment
217 #1#2#3#4{\message{Lines-Processing comment '#1'}%
218 \csarg\def{After#1Comment}{#3\AfterIncludedComment#4}%
219 \csarg\def{#1}{\BeforeIncludedComment#2\relax
220 \ProcessComment{#1}}%
223 #1#2{\message{Include comment '#1' up to level '#2'}%
224 %\csname #1IsLeveledCommenttrue\endcsname
225 \csarg\let{After#1Comment}\AfterIncludedComment
226 \csarg\def{#1}{\BeforeIncludedComment
227 \ProcessCommentWithArg{#1}}%
231 %%%%plain TeX and other formats
234 #1{\message{Including comment '#1'}%
237 \long\def\specialcomment
238 #1#2#3{\message{Special comment '#1'}%
239 \csarg\def{#1}{\def\ThisComment{}\def\AfterComment{#3}#2%
240 \ProcessComment{#1}}%
245 %%%% general definition of skipped comment
248 #1{\message{Excluding comment '#1'}%
249 \csarg\def{#1}{\let\AfterComment\relax
250 \def\ThisComment####1{}\ProcessComment{#1}}%
251 \csarg\let{After#1Comment}\TossComment
255 \ifx\fmtname\latexename
257 \else \ifx\fmtname\latexname
263 \def\EndOfComment#1{\endgroup\end{#1}%
264 \csname After#1Comment\endcsname}
265 \def\CommentEndDef#1{{\escapechar=-1\relax
266 \csarg\xdef{End#1Test}{\string\\end\string\{#1\string\}}%
270 \def\EndOfComment#1{\endgroup\AfterComment}
271 \def\CommentEndDef#1{{\escapechar=-1\relax
272 \csarg\xdef{End#1Test}{\string\\end#1}%
276 \excludecomment{comment}