Debian Codegraph @

texmf-dist/doc/latex/comment/comment_plain.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % Comment.sty version 3.5, August 1998
3 %
4 % Purpose:
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.
9 %
10 % Author
11 % Victor Eijkhout
12 % Department of Computer Science
13 % University of Tennessee
14 % 107 Ayres Hall
15 % Knoxville TN 37996
16 % USA
17 %
18 % [email protected]
19 %
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.
24 %
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.
29 %
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
35 %
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 % This style can be used with plain TeX or LaTeX, and probably
38 % most other packages too.
39 %
40 % Usage: all text included between
41 % \comment ... \endcomment
42 % or \begin{comment} ... \end{comment}
43 % is discarded.
44 %
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.
49 %
50 % Other `comment' environments are defined by
51 % and are selected/deselected with
52 % \includecomment{versiona}
53 % \excludecoment{versionb}
54 %
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
59 % their own.
60 %
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
64 % &c are not local.
65 %
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'.
73 % ex:
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.
80 %
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
88 %
89 % Trick for short in/exclude macros (such as \maybe{this snippet}):
90 %\includecomment{cond}
91 %\newcommand{\maybe}[1]{}
92 %\begin{cond}
93 %\renewcommand{\maybe}[1]{#1}
94 %\end{cond}
95 %
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
101 % then included.
102 % In plain TeX (and other formats) both the opening and
103 % closing comands are defined as noop.
104 %
105 % Changes in version 3.1
106 % - updated author's address
107 % - cleaned up some code
108 % - trailing contents on \begin{env} line is always discarded
109 % even if you've done \includecomment{env}
110 % - comments no longer define grouping!! you can even
111 % \includecomment{env}
112 % \begin{env}
113 % \begin{itemize}
114 % \end{env}
115 % Isn't that something ...
116 % - included comments are written to file and input again.
117 % Changes in 3.2
118 % - \specialcomment brought up to date (thanks to Ivo Welch).
119 % Changes in 3.3
120 % - updated author's address again
121 % - parametrised \CommentCutFile
122 % Changes in 3.4
123 % - added GNU public license
124 % - added \processcomment, because Ivo's fix (above) brought an
125 % inconsistency to light.
126 % Changes in 3.5
127 % - corrected typo in header.
128 % - changed author email
129 % - corrected \specialcomment yet again.
130 % - fixed excludecomment of an earlier defined environment.
131 %
132 % Known bugs:
133 % - excludecomment leads to one superfluous space
134 % - processcomment leads to a superfluous line break
135 %
136 \def\makeinnocent#1{\catcode`#1=12 }
137 \def\csarg#1#2{\expandafter#1\csname#2\endcsname}
138 \def\latexname{lplain}\def\latexename{LaTeX2e}
139 \newwrite\CommentStream
140 \def\CommentCutFile{comment.cut}
141
142 \def\ProcessComment#1% start it all of
143 {\begingroup
144 \def\CurrentComment{#1}%
145 \let\do\makeinnocent \dospecials
146 \makeinnocent\^^L% and whatever other special cases
147 \endlinechar`\^^M \catcode`\^^M=12 \xComment}
148 %\def\ProcessCommentWithArg#1#2% to be used in \leveledcomment
149 % {\begingroup
150 % \def\CurrentComment{#1}%
151 % \let\do\makeinnocent \dospecials
152 % \makeinnocent\^^L% and whatever other special cases
153 % \endlinechar`\^^M \catcode`\^^M=12 \xComment}
154 {\catcode`\^^M=12 \endlinechar=-1 %
155 \gdef\xComment#1^^M{%
156 \expandafter\ProcessCommentLine}
157 \gdef\ProcessCommentLine#1^^M{\def\test{#1}
158 \csarg\ifx{End\CurrentComment Test}\test
159 \edef\next{\noexpand\EndOfComment{\CurrentComment}}%
160 \else \ThisComment{#1}\let\next\ProcessCommentLine
161 \fi \next}
162 }
163
164 % 3.1 change: in LaTeX and LaTeX2e prevent grouping
165 \if 0%
166 \ifx\fmtname\latexename
167 0%
168 \else \ifx\fmtname\latexname
169 0%
170 \else
171 1%
172 \fi \fi
173 %%%%
174 %%%% definitions for LaTeX
175 %%%%
176 \def\AfterIncludedComment
177 {\immediate\closeout\CommentStream
178 \input{\CommentCutFile}\relax
179 }%
180 \def\TossComment{\immediate\closeout\CommentStream}
181 \def\WriteCommentLine#1{\immediate\write\CommentStream{#1}}
182 \def\BeforeIncludedComment
183 {\immediate\openout\CommentStream=\CommentCutFile
184 \let\ThisComment\WriteCommentLine}
185 \def\includecomment
186 #1{\message{Include comment '#1'}%
187 \csarg\let{After#1Comment}\AfterIncludedComment
188 \csarg\def{#1}{\BeforeIncludedComment
189 \ProcessComment{#1}}%
190 \CommentEndDef{#1}}
191 \long\def\specialcomment
192 #1#2#3{\message{Special comment '#1'}%
193 % note: \AfterIncludedComment does \input, so #2 goes here!
194 \csarg\def{After#1Comment}{#2\AfterIncludedComment#3}%
195 \csarg\def{#1}{\BeforeIncludedComment\relax
196 \ProcessComment{#1}}%
197 \CommentEndDef{#1}}
198 \long\def\processcomment
199 #1#2#3#4{\message{Lines-Processing comment '#1'}%
200 \csarg\def{After#1Comment}{#3\AfterIncludedComment#4}%
201 \csarg\def{#1}{\BeforeIncludedComment#2\relax
202 \ProcessComment{#1}}%
203 \CommentEndDef{#1}}
204 \def\leveledcomment
205 #1#2{\message{Include comment '#1' up to level '#2'}%
206 %\csarg\newif{if#1IsStreamingComment}
207 %\csarg\newif{if#1IsLeveledComment}
208 %\csname #1IsLeveledCommenttrue\endcsname
209 \csarg\let{After#1Comment}\AfterIncludedComment
210 \csarg\def{#1}{\BeforeIncludedComment
211 \ProcessCommentWithArg{#1}}%
212 \CommentEndDef{#1}}
213 \else
214 %%%%
215 %%%%plain TeX and other formats
216 %%%%
217 \def\includecomment
218 #1{\message{Including comment '#1'}%
219 \csarg\def{#1}{}%
220 \csarg\def{end#1}{}}
221 \long\def\specialcomment
222 #1#2#3{\message{Special comment '#1'}%
223 \csarg\newif{if#1IsStreamingComment}
224 \csarg\def{#1}{\def\ThisComment{}\def\AfterComment{#3}#2%
225 \ProcessComment{#1}}%
226 \CommentEndDef{#1}}
227 \fi
228
229 %%%%
230 %%%% general definition of skipped comment
231 %%%%
232 \def\excludecomment
233 #1{\message{Excluding comment '#1'}%
234 \csarg\def{#1}{\let\AfterComment\relax
235 \def\ThisComment####1{}\ProcessComment{#1}}%
236 \csarg\let{After#1Comment}\TossComment
237 \CommentEndDef{#1}}
238
239 \if 0%
240 \ifx\fmtname\latexename
241 0%
242 \else \ifx\fmtname\latexname
243 0%
244 \else
245 1%
246 \fi \fi
247 % latex & latex2e:
248 \def\EndOfComment#1{\endgroup\end{#1}%
249 \csname After#1Comment\endcsname}
250 \def\CommentEndDef#1{{\escapechar=-1\relax
251 \csarg\xdef{End#1Test}{\string\\end\string\{#1\string\}}%
252 }}
253 \else
254 % plain & other
255 \def\EndOfComment#1{\endgroup\AfterComment}
256 \def\CommentEndDef#1{{\escapechar=-1\relax
257 \csarg\xdef{End#1Test}{\string\\end#1}%
258 }}
259 \fi
260
261 \excludecomment{comment}
262
263 \endinput