summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/comment/comment.tex
blob: e6f3d5422c5788c9f0dc462c5405ad1cb6538fdd (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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
\documentclass[parskip=false, DIV=8, headings=normal, pagesize=auto]{artikel3}%{scrartcl}

\usepackage{fixltx2e}
\usepackage{etex}
\usepackage{xspace}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{microtype}
\usepackage[unicode=true]{hyperref}

\newenvironment*{noverb}{%
  \flushleft
  \vskip\parskip
  \parskip=0pt\relax
}{%
  \endflushleft
}

\newcommand*{\mail}[1]{\href{mailto:#1}{\texttt{#1}}}
\newcommand*{\pkg}[1]{\textsf{#1}}
\newcommand*{\cs}[1]{\texttt{\textbackslash#1}}
\makeatletter
\newcommand*{\cmd}[1]{\cs{\expandafter\@gobble\string#1}}
\makeatother
\newcommand*{\env}[1]{\texttt{#1}}
\newcommand*{\meta}[1]{\textlangle\textsl{#1}\textrangle}
\newcommand*{\marg}[1]{\texttt{\{}\meta{#1}\texttt{\}}}

%\addtokomafont{title}{\rmfamily}

\title{The \pkg{comment} package\thanks{This manual corresponds to
    \pkg{comment}~v3.8 of July 2016.}}
%
\author{Victor Eijkhout\\\mail{victor@eijkhout.net}} \date{August 2016}


\begin{document}

\maketitle

\section{Purpose:}

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.

Plain \TeX\ support has been phased out.

As of 3.8 the package will increasingly use e\TeX\ features, for
instance to solve Unicode support issues.

\section{Usage:}

The `\env{comment}' environment is defined by default:
all text included between
%
\begin{verbatim}
\begin{comment}
 ... 
\end{comment}
\end{verbatim}
%
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, and the comment can be arbitrary text.

Other `\env{comment}' environments are defined by
and are selected/deselected with
%
\begin{verbatim}
\includecomment{versiona}
\excludecoment{versionb}
\end{verbatim}
%
These environments are used as
%
\begin{verbatim}
\begin{versiona}
 ... 
\end{versiona}
\end{verbatim}
%
with the opening and closing commands again on a line of 
their own.

Note: for an included comment, the
\cmd{\begin} and \cmd{\end} lines act as if they don't exist.
In particular, they don't imply grouping, so assignments 
\&c are not local.

Trick for short in/exclude macros (such as \verb+\maybe{this snippet}+):
%
\begin{verbatim}
\includecomment{cond}
\newcommand{\maybe}[1]{}
\begin{cond}
\renewcommand{\maybe}[1]{#1}
\end{cond}
\end{verbatim}

\section{Special comments}

It is possible to make highly customized versions of the comment environment.
Special comments are defined as
%
\begin{noverb}
\cmd{\specialcomment}\marg{name}\marg{before commands}\marg{after commands}
\end{noverb}
%
where the second and third arguments are executed before
and after each comment block. You can use this for global
formatting commands.

To keep definitions \&c local, you can include \cmd{\begingroup}
in the `\meta{before commands}' and \cmd{\endgroup} in the `\meta{after commands}'.

Example:
%
\begin{verbatim}
\specialcomment{smalltt}
    {\begingroup\ttfamily\footnotesize}{\endgroup}
\end{verbatim}
%
Special comments are automatically included.

The comment environments use two auxiliary commands. You can get
nifty special effects by redefining them.

\subsection{The cutfile}

The commented text is written to an external file, the `cutfile'. Default definition:
\begin{verbatim}
  \def\CommentCutFile{comment.cut}
\end{verbatim}

Included comments are processed like this:
\begin{verbatim}
  \def\ProcessCutFile{\input{\CommentCutFile}\relax}
\end{verbatim}
  and excluded files have
\begin{verbatim}
  \def\ProcessCutFile{}
\end{verbatim}

\begin{itemize}
\item By redefining the name of the cutfile, the value of the macro
  \cmd{CommentCutFile}, it becomes possible to have nested comment environments.
\item If you are writing a textbook, you could have the answers to
  exercises in your source, but write them to file rather than
  formatting them:
\begin{verbatim}
\generalcomment{answer}
  {\begingroup
   \edef\tmp{\def\noexpand\CommentCutFile
                 {answers/\chapshortname-an\noexpand\arabic{excounter}.tex}}\tmp
   \def\ProcessCutFile{}}
  {\ifIncludeAnswers \begin{quote}
   \leavevmode
   \hbox{\kern-\unitindent 
         \textbf Solution to exercise \arabic{chapter}.\arabic{excounter}.\hspace{1em}}%
     \ignorespaces\it
   \input{\CommentCutFile}
   \end{quote}\fi
   \endgroup}
\end{verbatim}
\end{itemize}

\subsection{Comment inclusion}

The inclusion of the comment is done
by \cmd{\ProcessCutFile}, so you can redefine that:
\begin{verbatim}
  \specialcomment
    {mathexamplewithcode}
    {\begingroup\def\ProcessCutFile{}} % arg1
    {\verbatiminput{\CommentCutFile}   % arg2
     \endgroup
     This gives:
     \begin{equation} \input{\CommentCutFile} \end{equation}
    }
\end{verbatim}
The idea here is to disable inclusion of the file,
but include it in the after commands, in display math.

\subsection{Processing each line}

You can also apply processing to each line.
By defining a control sequence 
\begin{verbatim}
  \def\Thiscomment##1{...}
\end{verbatim}
in the before commands the user can
specify what is to be done with each comment line. If something 
needs to be written to file, use \verb+\WriteCommentLine{the stuff}+
Example:
\begin{verbatim}
  \specialcomment
    {underlinecomment}
    {\def\ThisComment##1{\WriteCommentLine{\underline{##1}\par}}
     \par}
    {\par}
\end{verbatim}

\subsection{More examples}

\begin{verbatim}
\newcount\comlines
\specialcomment{countedcomment}
 {\comlines=0\relax \def\ProcessCutFile{}%
  \def\ThisComment##1{\global\advance\comlines1\relax}}
 {**Comment: \number\comlines\ line(s) removed**}
\end{verbatim}

\begin{verbatim}
\specialcomment
    {underlinecomment}
    {%
      \def\ProcessCutFile{\input{\CommentCutFile}\relax}
      \def\ThisComment##1{\WriteCommentLine{u: \underline{##1}\par}}
      \par
    }
    {\par}
\end{verbatim}

\section{Unicode support}

Unicode support works if you use e\TeX, which is for instance the case
if you use pdflatex. You need the following lines:
\begin{verbatim}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\end{verbatim}
in your preamble.

\section{Change log}

\subsection{Changes in version 3.1}

\begin{itemize}
\item updated author's address
\item cleaned up some code
\item trailing contents on \cmd{\begin}\marg{env} line is always discarded
    even if you've done \cmd{\includecomment}\marg{env}
\item comments no longer define grouping!! you can even
  % 
\begin{verbatim}
\includecomment{env}
\begin{env}
\begin{itemize}
\end{env}
\end{verbatim}
  % 
  Isn't that something\ldots
\item included comments are written to file and input again.
\end{itemize}


\subsection{Changes in 3.2}

\begin{itemize}
\item \cmd{\specialcomment} brought up to date (thanks to Ivo Welch).
\end{itemize}


\subsection{Changes in 3.3}

\begin{itemize}
\item updated author's address again
\item parametrised \cmd{\CommentCutFile}
\end{itemize}


\subsection{Changes in 3.4}

\begin{itemize}
\item added GNU public license
\item added \cmd{\processcomment}, because Ivo's fix (above) brought an
  inconsistency to light.
\end{itemize}

  
\subsection{Changes in 3.5}

\begin{itemize}
\item corrected typo in header.
\item changed author email
\item corrected \cmd{\specialcomment} yet again.
\item fixed excludecomment of an earlier defined environment.
\end{itemize}


\subsection{Changes in 3.6}

\begin{itemize}
\item The `cut' file is now written more verbatim, using \cmd{\meaning};
  some people reported having trouble with ISO~latin~1, or \texttt{umlaute.sty}.
\item removed some \cmd{\newif} statements.
  Has this suddenly become \cmd{\outer} again?
\end{itemize}


\subsection{Changes in 3.8}

T1 font encoding is now supported. See t1test.tex.

\end{document}