blob: fb7047c4259b10925adc0856538d68ce712b6b19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% comment.sty version 3.0, 3 September 1992
% selectively in/exclude pieces of text: the user can define new
% comment versions, and each is controlled separately.
% Special comments can be defined where the user specifies the
% action that is to be taken with each comment line.
%
% This style can be used with plain TeX or LaTeX, and probably
% most other packages too.
%
% Author
% Victor Eijkhout and Vafa Khalighi
% persian-tex@tug.org
%
% 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.
%
% Special comments are defined as
% \specialcomment{name}{before commands}{after commands}
% where the second and third arguments are executed before
% and after each comment. By defining a control sequence
% \Thiscomment#1{...} in the before commands the user can
% specify what is to be done which each comment line.
%
% 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
%
% This file copyright Victor Eijkhout and Vafa Khalighi.
%
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%
%
\def\makeinnocent#1{\catcode`#1=12 }
\def\csarg#1#2{\expandafter#1\csname#2\endcsname}
\def\TreatAsComment#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
\def\next{\endgroup\AfterComment}%
\else \csarg\ifx{LolliEnd\CurrentComment Test}\test
\def\next{\endgroup\AfterComment}%
\else \csarg\ifx{LaLaEnd\CurrentComment Test}\test
\edef\next{\endgroup\noexpand\AfterComment
\noexpand\end{\CurrentComment}}
\else \ThisComment{#1}\let\next\xComment
\fi \fi \fi \next}
}
\def\includecomment
#1{\message{Including comment '#1'}%
\expandafter\def\csname#1\endcsname{}%
\expandafter\def\csname end#1\endcsname{}}
\def\excludecomment
#1{\message{Excluding comment '#1'}%
\csarg\def{#1}{\let\AfterComment\relax
\def\ThisComment####1{}\TreatAsComment{#1}}%
{\escapechar=-1\relax
\csarg\xdef{PlainEnd#1Test}{\string\\end#1}%
\csarg\xdef{LolliEnd#1Test}{\string\\#1Stop}%
\csarg\xdef{LaLaEnd#1Test}{\string\\end\string\{#1\string\}}%
}}
\long\def\specialcomment
#1#2#3{\message{Special comment '#1'}%
\csarg\def{#1}{\def\ThisComment{}\def\AfterComment{#3}#2%
\TreatAsComment{#1}}%
{\escapechar=-1\relax
\csarg\xdef{PlainEnd#1Test}{\string\\end#1}%
\csarg\xdef{LolliEnd#1Test}{\string\\#1Stop}%
\csarg\xdef{LaLaEnd#1Test}{\string\\end\string\{#1\string\}}%
}}
\excludecomment{comment}
\endinput
% a test of the special comments
\newcount\comlines
\specialcomment{countedcomment}
{\comlines=-1\relax %note that the rest of the first line is also comment
\def\ThisComment{\global\advance\comlines1\relax}}
{\endgraf **Comment: \number\comlines\ line(s) removed**\endgraf}
This is a line of text
\countedcomment
Oneline
\endcountedcomment
another line of text
\countedcomment
One line
Two line
Three line
\endcountedcomment
last line of text
\end
|