src/Tools/isac/Doc/comment.sty
author Walther Neuper <walther.neuper@jku.at>
Wed, 11 Mar 2020 15:25:52 +0100
changeset 59827 168abe8dd1e3
permissions -rw-r--r--
start formally checked documentation with Lucas_Interpreter

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