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