summaryrefslogtreecommitdiff
path: root/texmf-dist/tex/latex/acrotex/aeb-comment.sty
blob: 35624bd1e718e323502be1811e80132e8a84e5c4 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is an unmodified version of comment.sty (version 3.2) that is distributed
% with acrotex under the name of aeb-comment.sty. D. P. Story (dpstory at acrotex dot net)
%
% Comment.sty   version 3.2, August 1997
% 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
%    Department of Mathematics
%    University of California
%    405 Hilgard Ave, MS 6363
%    Los Angeles, CA 90034
%    USA
%
%    eijkhout@math.ucla.edu
%
% Usage: all text included in between
%    \comment ... \endcomment
% or \begin{comment} ... \end{comment}
% is discarded.
% The opening and closing commands should appear on a line
% of their 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 opening and closing commands again on a line of
% their own.
%
% LaTeX users note: for an included comment, the
% \begin and \end lines act as if they don't exist.
% In particular, assignments &c are not local.
%
% Special comments are defined as
% \specialcomment{name}{before commands}{after commands}
% where the second and third arguments are executed before
% and after each comment block.
% By defining a control sequence
% \Thiscomment##1{...} in the before commands the user can
% specify what is to be done with each comment line.
% To keep definitions &c local, you can include \begingroup
% in the `before commands' and \endgroup in the `after commands'.
%
% Basic approach:
% to comment something out, scoop up  every line in verbatim mode
% as macro argument, then throw it away.
% For inclusions, in LaTeX the block is written out to
% a file "comment.cut", which is then included.
% In plain TeX (and other formats) both the opening and
% closing commands are defined as noop.
%
% Trick for short in/exclude macros (\maybe{this snippet}):
%\includeversion{cond}
%\newcommand{\maybe}[1]{}
%\begin{cond}
%\renewcommand{\maybe}[1]{#1}
%\end{cond}
%
% Changes in version 3.1
% - updated author's address
% - cleaned up some code
% - trailing contents on \begin{env} line is always discarded
%  even if you've done \includecomment{env}
% - comments no longer define grouping!! you can even
%   \includecomment{env}
%   \begin{env}
%   \begin{itemize}
%   \end{env}
%  Isn't that something ...
% - included comments are written to file and input again.
% Changes in 3.2
% - \specialcomment brought up to date (thanks to Ivo Welch).
%
\def\makeinnocent#1{\catcode`#1=12 }
\def\csarg#1#2{\expandafter#1\csname#2\endcsname}
\def\latexname{lplain}\def\latexename{LaTeX2e}
\newwrite\CommentStream

\def\ProcessComment#1{\begingroup
    \def\CurrentComment{#1}%
    \let\do\makeinnocent \dospecials
    \makeinnocent\^^L% and whatever other special cases
    \endlinechar`\^^M \catcode`\^^M=12 \fxComment}
{\catcode`\^^M=12 \endlinechar=-1 %
 \gdef\fxComment#1^^M{\xComment}
 \gdef\xComment#1^^M{\def\test{#1}
      \csarg\ifx{End\CurrentComment Test}\test
          \edef\next{\noexpand\EndOfComment{\CurrentComment}}%
      \else \ThisComment{#1}\let\next\xComment
      \fi \next}
}

% 3.1 change: in LaTeX and LaTeX2e prevent grouping
\if 0%
\ifx\fmtname\latexename
    0%
\else \ifx\fmtname\latexname
          0%
      \else
          1%
\fi   \fi
%%%%
%%%% definitions for LaTeX
%%%%
\edef\restoreat{\catcode\noexpand`\noexpand\@=\the\catcode`\@\relax}
\makeatletter
\def\AfterIncludedComment
   {\immediate\closeout\CommentStream
    \input comment.cut
    }%
\def\WriteCommentLine#1{\immediate\write\CommentStream{#1}}
\def\BeforeIncludedComment{\immediate\openout\CommentStream=comment.cut
    \let\ThisComment\WriteCommentLine}
\def\includecomment
 #1{\message{Include comment '#1'}%
    \csarg\let{After#1Comment}\AfterIncludedComment
    \csarg\def{#1}{\BeforeIncludedComment
        \ProcessComment{#1}}%
    \CommentEndDef{#1}}
\long\def\specialcomment
 #1#2#3{\message{Special comment '#1'}%
    \csarg\def{After#1Comment}{#2\AfterIncludedComment#3}%
    \csarg\def{#1}{\BeforeIncludedComment
          \ProcessComment{#1}}%
    \CommentEndDef{#1}}
\restoreat
\else
%%%%
%%%%plain TeX and other formats
%%%%
\def\includecomment
 #1{\message{Including comment '#1'}%
    \csarg\def{#1}{}%
    \csarg\def{end#1}{}}
\long\def\specialcomment
 #1#2#3{\message{Special comment '#1'}%
    \csarg\def{#1}{\def\ThisComment{}\def\AfterComment{#3}#2%
           \ProcessComment{#1}}%
    \CommentEndDef{#1}}
\fi

%%%%
%%%% general definition of skipped comment
%%%%
\def\excludecomment
 #1{\message{Excluding comment '#1'}%
    \csarg\def{#1}{\let\AfterComment\relax
           \def\ThisComment####1{}\ProcessComment{#1}}%
    \CommentEndDef{#1}}

\if 0%
\ifx\fmtname\latexename
    0%
\else \ifx\fmtname\latexname
          0%
      \else
          1%
\fi   \fi
% latex & latex2e:
\def\EndOfComment#1{\endgroup\end{#1}%
    \csname After#1Comment\endcsname}
\def\CommentEndDef#1{{\escapechar=-1\relax
    \csarg\xdef{End#1Test}{\string\\end\string\{#1\string\}}%
    }}
\else
% plain & other
\def\EndOfComment#1{\endgroup\AfterComment}
\def\CommentEndDef#1{{\escapechar=-1\relax
    \csarg\xdef{End#1Test}{\string\\end#1}%
    }}
\fi

\excludecomment{comment}

\endinput