Debian Codegraph @

texmf-dist/doc/otherformats/lollipop/manual/comment.tex

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