1 % \iffalse meta-comment
5 % The LaTeX3 Project and any individual authors listed elsewhere
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
11 % It may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either version 1.3c
13 % of this license or (at your option) any later version.
14 % The latest version of this license is in
15 % http://www.latex-project.org/lppl.txt
16 % and version 1.3c or later is part of all distributions of LaTeX
17 % version 2005/12/01 or later.
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
25 %\iffalse % this is a METACOMMENT !
28 %% Package `verbatim' to use with LaTeX2e
29 %% Copyright (C) 1989--2003 by Rainer Sch\"opf. All rights reserved.
31 % Copying of this file is authorized only if either
32 % (1) you make absolutely no changes to your copy, including name, or
33 % (2) if you do make changes, you name it something other than
35 % This restriction helps ensure that all styles developed here
40 % \section{Producing the documentation}
42 % We provide a short driver file that can be extracted by the
43 % \textsf{DocStrip} program using the conditional `\textsf{driver}'.
47 \documentclass{ltxdoc}
49 \pagestyle{myheadings}
51 \title{A New Implementation of \LaTeX{}'s \\ \texttt{verbatim}
52 and \texttt{verbatim*} Environments.}
53 \author{Rainer Sch\"opf\\
61 \markboth{Verbatim style option}{Verbatim style option}
62 \MaintainedByLaTeXTeam{tools}
64 \DocInput{verbatim.dtx}
73 % \changes{v1.5q}{2003/08/22}{Reintroduced \cs{@noligs}, by popular
75 % \changes{v1.5i}{1996/06/04}{Move setting of verbatim font and
77 % \changes{v1.5g}{1995/04/26}{Removed \cs{fileversion} and
78 % \cs{filedate} from running head in
79 % driver file, as these are no longer
81 % \changes{v1.5f}{1994/10/25}{Removed extra \cs{typeout} commands.}
82 % \changes{v1.5e}{1994/06/10}{Added missing closing verbtest guard.}
83 % \changes{v1.5d}{1994/05/30}{\cs{NeedsTeXFormat} and
84 % \cs{ProvidesPackage} added.}
85 % \changes{v1.5d}{1994/05/30}{\cs{addto@hook} removed, now in kernel.}
86 % \changes{v1.5a}{1993/10/12}{Included \cs{newverbtext} command, as
87 % written by Chris Rowley.}
88 % \changes{v1.5}{1993/10/11}{Included vrbinput style option by Bernd
91 % \changes{v1.4j}{1992/06/30}{Used \cs{lowercase}\{\cs{endgroup}
92 % \ldots\} trick proposed by Bernd Raichle; changed all \cs{gdef}
93 % to \cs{def} since no longer necessary.}
94 % \changes{v1.4g}{1991/11/21}{Several improvements in the
96 % \changes{v1.4f}{1991/08/05}{Corrected bug in documentation.
97 % Found by Bernd Raichle.}
98 % \changes{v1.4e}{1991/07/24}{Avoid reading this file twice.}
99 % \changes{v1.4d}{1991/04/24}{\cs{penalty}\cs{interlinepenalty} added to
100 % definition of \cs{par} in \cs{@verbatim}.
101 % Necessary to avoid page breaks in
102 % the scope of a \cs{samepage} declaration.}
103 % \changes{v1.4c}{1990/10/18}{Added \cs{leavevmode} to definition of
105 % \changes{v1.4b}{1990/07/14}{Converted nearly all \cs{verb}'s to
106 % \texttt{\protect\string!|\ldots\protect\string!|}.}
107 % \changes{v1.4a}{1990/04/04}{Added a number of percent characters
108 % to suppress blank space at the end of some code lines.}
109 % \changes{v1.4}{1990/03/07}{\cs{verb} rewritten.}
111 % \changes{v1.3a}{1990/02/04}{Removed \texttt{verbatimwrite} environment
112 % from the code. Now only shown as an example.}
114 % \changes{v1.2g}{1990/02/01}{Revised documentation.}
115 % \changes{v1.2e}{1990/01/15}{Added \cs{every@verbatim} hook.}
116 % \changes{v1.2d}{1989/11/29}{Use token register \cs{@temptokena}
117 % instead of macro \cs{@tempb}.}
118 % \changes{v1.2d}{1989/11/29}{Use token register \cs{verbatim@line}
119 % instead of macro \cs{@tempd}.}
120 % \changes{v1.2b}{1989/10/25}{\cs{verbatimfile} renamed to
121 % \cs{verbatiminput}. Suggested by Reinhard Wonneberger.}
123 % \changes{v1.1a}{1989/10/16}{\cs{verb} added.}
124 % \changes{v1.1}{1989/10/09}{Made the code more modular (as suggested by
125 % Chris Rowley): introduced
126 % \cs{verbatim@addtoline}, etc. Added
127 % \cs{verbatimwrite} environment.}
129 % \changes{v1.0e}{1989/07/17}{Fixed bug in \cs{verbatimfile} (*-form
130 % handling, discovered by Dirk Kreimer).}
131 % \changes{v1.0d}{1989/05/16}{Revised documentation, fixed silly bug
132 % in \cs{verbatim@@@}.}
133 % \changes{v1.0c}{1989/05/12}{Added redefinition of \cs{@sverb}, change
134 % in end-of-line handling.}
135 % \changes{v1.0b}{1989/05/09}{Change in \cs{verbatim@rescan}.}
136 % \changes{v1.0a}{1989/05/07}{Change in \cs{verbatim@@testend}.}
139 % \DoNotIndex{\ ,\!,\C,\[,\\,\],\^,\`,\{,\},\~}
140 % \DoNotIndex{\@M,\@empty,\@flushglue,\@gobble,\@ifstar,\@ifundefined}
141 % \DoNotIndex{\@namedef,\@spaces,\@tempa,\@tempb,\@tempc,\@tempd}
142 % \DoNotIndex{\@temptokena,\@totalleftmargin,\@warning,\active}
143 % \DoNotIndex{\aftergroup,\arabic,\begingroup,\catcode,\char,\closein}
144 % \DoNotIndex{\csname,\def,\do,\docdate,\dospecials,\edef,\else}
145 % \DoNotIndex{\endcsname,\endgraf,\endgroup,\endinput,\endlinechar}
146 % \DoNotIndex{\endtrivlist,\expandafter,\fi,\filedate,\fileversion}
147 % \DoNotIndex{\frenchspacing,\futurelet,\if,\ifcat,\ifeof,\ifnum}
148 % \DoNotIndex{\ifx,\immediate,\item,\kern,\lccode,\leftskip,\let}
149 % \DoNotIndex{\lowercase,\m@ne,\makeatletter,\makeatother,\newread}
150 % \DoNotIndex{\newread,\next,\noexpand,\noindent,\openin,\parfillskip}
151 % \DoNotIndex{\parindent,\parskip,\penalty,\read,\relax,\rightskip}
152 % \DoNotIndex{\sloppy,\space,\string,\the,\toks@,\trivlist,\tt,\typeout}
153 % \DoNotIndex{\vskip,\write,\z@}
156 % This package reimplements the \LaTeX{} \texttt{verbatim} and
157 % \texttt{verbatim*} environments.
158 % In addition it provides a \texttt{comment} environment
159 % that skips any commands or text between
161 % and the next |\end{comment}|.
162 % It also defines the command \texttt{verbatiminput} to input a whole
166 % \section{Usage notes}
168 % \let\docDescribeMacro\DescribeMacro
169 % \let\docDescribeEnv\DescribeEnv
170 % \def\DescribeMacro#1{}
171 % \def\DescribeEnv#1{}
172 % \LaTeX's \texttt{verbatim} and \texttt{verbatim*} environments
173 % have a few features that may give rise to problems. These are:
176 % Due to the method used to detect the closing |\end{verbatim}|
177 % (i.e.\ macro parameter delimiting) you cannot leave spaces
178 % between the |\end| token and |{verbatim}|.
180 % Since \TeX{} has to read all the text between the
181 % |\begin{verbatim}| and the |\end{verbatim}| before it can output
182 % anything, long verbatim listings may overflow \TeX's memory.
184 % Whereas the first of these points can be considered
185 % only a minor nuisance the other one is a real limitation.
188 % \DescribeEnv{verbatim}
189 % \DescribeEnv{verbatim*}
190 % This package file contains a reimplementation of the \texttt{verbatim}
191 % and \texttt{verbatim*} environments which overcomes these
193 % There is, however, one incompatibility between the old and the
194 % new implementations of these environments: the old version
195 % would treat text on the same line as the |\end{verbatim}|
196 % command as if it were on a line by itself.
198 % \bf This new version will simply ignore it.
200 % (This is the price one has to pay for the removal of the old
201 % \texttt{verbatim} environment's size limitations.)
202 % It will, however, issue a warning message of the form
204 %LaTeX warning: Characters dropped after \end{verbatim*}!
206 % This is not a real problem since this text can easily be put
207 % on the next line without affecting the output.
209 % This new implementation also solves the second problem mentioned
210 % above: it is possible to leave spaces (but \emph{not} begin a new
211 % line) between the |\end| and the |{verbatim}| or |{verbatim*}|:
219 % \DescribeEnv{comment}
220 % Additionally we introduce a \texttt{comment} environment, with the
221 % effect that the text between |\begin{comment}| and |\end{comment}|
222 % is simply ignored, regardless of what it looks like.
223 % At first sight this seems to be quite different from the purpose
224 % of verbatim listing, but actually the implementation of these two
225 % concepts turns out to be very similar.
226 % Both rely on the fact that the text between |\begin{...}| and
227 % |\end{...}| is read by \TeX{} without interpreting any commands or
228 % special characters.
229 % The remaining difference between \texttt{verbatim} and
230 % \texttt{comment} is only that the text is to be typeset in the
231 % first case and to be thrown away in the latter. Note that these
232 % environments cannot be nested.
234 % \DescribeMacro{\verbatiminput}
235 % |\verbatiminput| is a command with one argument that inputs a file
236 % verbatim, i.e.\ the command |verbatiminput{xx.yy}|
237 % has the same effect as\\[2pt]
238 % \hspace*{\MacroIndent}|\begin{verbatim}|\\
239 % \hspace*{\MacroIndent}\meta{Contents of the file \texttt{xx.yy}}\\
240 % \hspace*{\MacroIndent}|\end{verbatim}|\\[2pt]
241 % This command has also a |*|-variant that prints spaces as \verb*+ +.
247 % \section{Interfaces for package writers}
249 % The \texttt{verbatim} environment of \LaTeXe{} does not
250 % offer a good interface to programmers.
251 % In contrast, this package provides a simple mechanism to
252 % implement similar features, the \texttt{comment} environment
253 % implemented here being an example of what can be done and how.
256 % \subsection{Simple examples}
258 % It is now possible to use the \texttt{verbatim} environment to define
259 % environments of your own.
262 % \newenvironment{myverbatim}%
263 % {\endgraf\noindent MYVERBATIM:%
264 % \endgraf\verbatim}%
267 % can be used afterwards like the \texttt{verbatim} environment, i.e.
274 % Another way to use it is to write
277 %\let\endfoo=\endcomment
279 % and from that point on environment \texttt{foo} is the same as the
280 % comment environment, i.e.\ everything inside its body is ignored.
282 % You may also add special commands after the |\verbatim| macro is
285 %\newenvironment{myverbatim}%
286 % {\verbatim\myspecialverbatimsetup}%
289 % though you may want to learn about the hook |\every@verbatim| at
291 % \changes{v1.5h}{1995/09/21}{Clarified documentation on use of other
292 % environments to define new verbatim-type ones.}
293 % However, there are still a number of restrictions:
296 % You must not use the |\begin| or the |\end| command inside a
297 % definition, e.g.~the following two examples will \emph{not} work:
299 %\newenvironment{myverbatim}%
300 %{\endgraf\noindent MYVERBATIM:%
301 % \endgraf\begin{verbatim}}%
303 %\newenvironment{fred}
304 %{\begin{minipage}{30mm}\verbatim}
305 %{\endverbatim\end{minipage}}
307 % If you try these examples, \TeX{} will report a
308 % ``runaway argument'' error.
309 % More generally, it is not possible to use
310 % |\begin|\ldots\allowbreak|\end|
311 % or the related environments in the definition of the new
312 % environment. Instead, the correct way to define this environment
315 %\newenvironment{fred}
316 %{\minipage{30mm}\verbatim}
317 %{\endverbatim\endminipage}
320 % You can\emph{not} use the \texttt{verbatim} environment inside
321 % user defined \emph{commands}; e.g.,
322 % \changes{v1.4g}{1991/11/21}{Corrected wrong position of optional
323 % argument to \cs{newcommand}. Discovered by Piet van Oostrum.}
325 %\newcommand{\verbatimfile}[1]%
326 % {\begin{verbatim}\input{#1}\end{verbatim}}
328 % does \emph{not} work; nor does
330 %\newcommand{\verbatimfile}[1]{\verbatim\input{#1}\endverbatim}
332 % \item The name of the newly defined environment must not contain
333 % characters with category code other than $11$ (letter) or
334 % $12$ (other), or this will not work.
338 % \subsection{The interfaces}
340 % \DescribeMacro{\verbatim@font}
341 % Let us start with the simple things.
342 % Sometimes it may be necessary to use a special typeface for your
343 % verbatim text, or perhaps the usual computer modern typewriter shape
346 % You may select this by redefining the macro |\verbatim@font|.
347 % This macro is executed at the beginning of every verbatim text to
348 % select the font shape.
349 % Do not use it for other purposes; if you find yourself abusing this
350 % you may want to read about the |\every@verbatim| hook below.
352 % By default, |\verbatim@font| switches to the typewriter font and
353 % disables the ligatures contained therein.
356 % \DescribeMacro{\every@verbatim}
357 % \DescribeMacro{\addto@hook}
358 % There is a hook (i.e.\ a token register) called |\every@verbatim|
359 % whose contents are inserted into \TeX's mouth just before every
361 % Please use the |\addto@hook| macro to add something to this hook.
362 % It is used as follows:\\[2pt]
363 % \hspace*{\MacroIndent}|\addto@hook|\meta{name of the hook}^^A
364 % |{|\meta{commands to be added}|}|
369 % \DescribeMacro{\verbatim@start}
370 % After all specific setup, like switching of category codes, has been
371 % done, the |\verbatim@start| macro is called.
372 % This starts the main loop of the scanning mechanism implemented here.
373 % Any other environment that wants to make use of this feature should
374 % execute this macro as its last action.
377 % \DescribeMacro{\verbatim@startline}
378 % \DescribeMacro{\verbatim@addtoline}
379 % \DescribeMacro{\verbatim@processline}
380 % \DescribeMacro{\verbatim@finish}
381 % These are the things that concern the start of a verbatim
383 % Once this (and other) setup has been done, the code in this package
384 % reads and processes characters from the input stream in the
387 % \item Before the first character of an input line is read, it
388 % executes the macro |\verbatim@startline|.
389 % \item After some characters have been read, the macro
390 % |\verbatim@addtoline| is called with these characters as its only
392 % This may happen several times per line (when an |\end| command is
393 % present on the line in question).
394 % \item When the end of the line is reached, the macro
395 % |\verbatim@processline| is called to process the characters that
396 % |\verbatim@addtoline| has accumulated.
397 % \item Finally, there is the macro |\verbatim@finish| that is called
398 % just before the environment is ended by a call to the |\end|
403 % To make this clear let us consider the standard \texttt{verbatim}
405 % In this case the three macros above are defined as follows:
407 % \item |\verbatim@startline| clears the character buffer
408 % (a token register).
409 % \item |\verbatim@addtoline| adds its argument to the character
411 % \item |\verbatim@processline| typesets the characters accumulated
414 % With this it is very simple to implement the \texttt{comment}
416 % in this case |\verbatim@startline| and |\verbatim@processline| are
418 % no-ops whereas |\verbatim@addtoline| discards its argument.
421 % Let's use this to define a variant of the |verbatim|
422 % environment that prints line numbers in the left margin.
423 % Assume that this would be done by a counter called |VerbatimLineNo|.
424 % Assuming that this counter was initialized properly by the
425 % environment, |\verbatim@processline| would be defined in this case as
427 %\def\verbatim@processline{%
428 % \addtocounter{VerbatimLineNo}{1}%
430 % \llap{\theVerbatimLineNo\ \hskip\@totalleftmargin}%
431 % \the\verbatim@line\par}
434 % A further possibility is to define a variant of the |verbatim|
435 % environment that boxes and centers the whole verbatim text.
436 % Note that the boxed text should be less than a page otherwise you
437 % have to change this example.
440 %\def\verbatimboxed#1{\begingroup
441 % \def\verbatim@processline{%
442 % {\setbox0=\hbox{\the\verbatim@line}%
444 % \the\verbatim@line\par}}%
445 % \setbox0=\vbox{\parskip=0pt\topsep=0pt\partopsep=0pt
446 % \verbatiminput{#1}}%
447 % \begin{center}\fbox{\box0}\end{center}%
451 % As a final nontrivial example we describe the definition of an
452 % environment called \texttt{verbatimwrite}.
453 % It writes all text in its body to a file whose name is
454 % given as an argument.
455 % We assume that a stream number called |\verbatim@out| has already
456 % been reserved by means of the |\newwrite| macro.
458 % Let's begin with the definition of the macro |\verbatimwrite|.
460 %\def\verbatimwrite#1{%
462 % First we call |\@bsphack| so that this environment does not influence
464 % Then we open the file and set the category codes of all special
468 % \immediate\openout \verbatim@out #1
469 % \let\do\@makeother\dospecials
470 % \catcode`\^^M\active
472 % The default definitions of the macros
474 % \verbatim@startline
475 % \verbatim@addtoline
478 % are also used in this environment.
479 % Only the macro |\verbatim@processline| has to be changed before
480 % |\verbatim@start| is called:
482 % \def\verbatim@processline{%
483 % \immediate\write\verbatim@out{\the\verbatim@line}}%
486 % The definition of |\endverbatimwrite| is very simple:
487 % we close the stream and call |\@esphack| to get the spacing right.
489 %\def\endverbatimwrite{\immediate\closeout\verbatim@out\@esphack}
492 % \section{The implementation}
494 % \let\DescribeMacro\docDescribeMacro
495 % \let\DescribeEnv\docDescribeEnv
497 % \changes{v1.4e}{1991/07/24}{Avoid reading this file twice.}
498 % The very first thing we do is to ensure that this file is not read
499 % in twice. To this end we check whether the macro |\verbatim@@@| is
500 % defined. If so, we just stop reading this file. The `package'
501 % guard here allows most of the code to be excluded when extracting
502 % the driver file for testing this package.
505 \NeedsTeXFormat{LaTeX2e}
506 \ProvidesPackage{verbatim}
507 [2014/10/28 v1.5q LaTeX2e package for verbatim enhancements]
508 \@ifundefined{verbatim@@@}{}{\endinput}
511 % We use a mechanism similar to the one implemented for the
512 % |\comment|\ldots\allowbreak|\endcomment| macro in \AmSTeX:
513 % We input one line at a time and check if it contains the |\end{...}|
515 % Then we can decide whether we have reached the end of the verbatim
516 % text, or must continue.
519 % \subsection{Preliminaries}
521 % \begin{macro}{\every@verbatim}
522 % The hook (i.e.\ token register) |\every@verbatim|
523 % is initialized to \meta{empty}.
525 \newtoks\every@verbatim
531 % \begin{macro}{\@makeother}
532 % \changes{v1.1a}{1989/10/16}{\cs{@makeother} added.}
533 % |\@makeother| takes as argument a character and changes
534 % its category code to $12$ (other).
536 \def\@makeother#1{\catcode`#112\relax}
541 % \begin{macro}{\@vobeyspaces}
542 % \changes{v1.5}{1993/10/11}{Changed definition to not use \cs{gdef}.}
543 % \changes{v1.1a}{1989/10/16}{\cs{@vobeyspaces} added.}
544 % The macro |\@vobeyspaces| causes spaces in the input
545 % to be printed as spaces in the output.
549 \def\x{\def\@vobeyspaces{\catcode`\ \active\let \@xobeysp}}
550 \expandafter\endgroup\x
555 % \begin{macro}{\@xobeysp}
556 % \changes{v1.1a}{1989/10/16}{\cs{@xobeysp} added.}
557 % The macro |\@xobeysp| produces exactly one space in
558 % the output, protected against breaking just before it.
559 % (|\@M| is an abbreviation for the number $10000$.)
561 \def\@xobeysp{\leavevmode\penalty\@M\ }
566 % \begin{macro}{\verbatim@line}
567 % \changes{v1.2d}{1989/11/29}{Introduced token register
568 % \cs{verbatim@line}.}
569 % We use a newly defined token register called |\verbatim@line|
570 % that will be used as the character buffer.
572 \newtoks\verbatim@line
576 % The following four macros are defined globally in a way suitable for
577 % the \texttt{verbatim} and \texttt{verbatim*} environments.
578 % \begin{macro}{\verbatim@startline}
579 % \begin{macro}{\verbatim@addtoline}
580 % \begin{macro}{\verbatim@processline}
581 % |\verbatim@startline| initializes processing of a line
582 % by emptying the character buffer (|\verbatim@line|).
584 \def\verbatim@startline{\verbatim@line{}}
586 % |\verbatim@addtoline| adds the tokens in its argument
587 % to our buffer register |\verbatim@line| without expanding
590 \def\verbatim@addtoline#1{%
591 \verbatim@line\expandafter{\the\verbatim@line#1}}
593 % Processing a line inside a \texttt{verbatim} or \texttt{verbatim*}
594 % environment means printing it.
595 % \changes{v1.2c}{1989/10/31}{Changed \cs{@@par} to \cs{par} in
596 % \cs{verbatim@processline}. Removed \cs{leavevmode} and \cs{null}
597 % (i.e.\ the empty \cs{hbox}).}
598 % Ending the line means that we have to begin a new paragraph.
599 % We use |\par| for this purpose. Note that |\par|
600 % is redefined in |\@verbatim| to force \TeX{} into horizontal
601 % mode and to insert an empty box so that empty lines in the input
602 % do appear in the output.
603 % \changes{v1.2f}{1990/01/31}{\cs{verbatim@startline} removed.}
605 \def\verbatim@processline{\the\verbatim@line\par}
611 % \begin{macro}{\verbatim@finish}
612 % As a default, |\verbatim@finish| processes the remaining
614 % When this macro is called we are facing the following problem:
615 % when the |\end{verbatim}|
616 % command is encountered |\verbatim@processline| is called
617 % to process the characters preceding the command on the same
618 % line. If there are none, an empty line would be output if we
619 % did not check for this case.
621 % If the line is empty |\the\verbatim@line| expands to
622 % nothing. To test this we use a trick similar to that on p.\ 376
623 % of the \TeX{}book, but with |$|\ldots|$| instead of
624 % the |!| tokens. These |$| tokens can never have the same
625 % category code as a |$| token that might possibly appear in the
626 % token register |\verbatim@line|, as such a token will always have
627 % been read with category code $12$ (other).
628 % Note that |\ifcat| expands the following tokens so that
629 % |\the\verbatim@line| is replaced by the accumulated
631 % \changes{v1.2d}{1989/11/29}{Changed \cs{ifx} to \cs{ifcat} test.}
632 % \changes{v1.1b}{1989/10/18}{Corrected bug in if test (found by CRo).}
634 \def\verbatim@finish{\ifcat$\the\verbatim@line$\else
635 \verbatim@processline\fi}
640 % \subsection{The \texttt{verbatim} and \texttt{verbatim*} environments}
642 % \begin{macro}{\verbatim@font}
643 % \changes{v1.2f}{1990/01/31}{\cs{@lquote} macro removed.}
644 % \changes{v1.1b}{1989/10/18}{\cs{@noligs} removed. Code inserted
645 % directly into \cs{verbatim@font}.}
646 % \changes{v1.1a}{1989/10/16}{\cs{verbatim@font} added.}
647 % \changes{v1.1a}{1989/10/16}{\cs{@noligs} added.}
648 % \changes{v1.1a}{1989/10/16}{\cs{@lquote} added.}
649 % We start by defining the macro |\verbatim@font| that is
650 % to select the font and to set font-dependent parameters.
651 % Then we expand |\@noligs| (defined in the \LaTeXe{} kernel). Among
652 % possibly other things, it will go through |\verbatim@nolig@list|
653 % to avoid certain ligatures.
654 % |\verbatim@nolig@list| is a macro defined in the \LaTeXe{} kernel
657 % \do\`\do\<\do\>\do\,\do\'\do\-
659 % All the characters in this list can be part of a ligature in some
661 % \changes{v1.2f}{1990/01/31}{\cs{@lquote} macro removed.}
662 % \changes{v1.4c}{1990/10/18}{Added \cs{leavevmode}.}
663 % \changes{v1.4k}{1992/07/13}{Replaced Blank after $96$ by \cs{relax}.
664 % (Proposed by Dan Dill.)}
665 % \changes{v1.5}{1993/10/11}{Definition changed according to new code
666 % in latex.tex and to avoid global definition.}
667 % \changes{v1.5c}{1994/02/07}{Changed to use new font switching
669 % \changes{v1.5m}{2000/01/07}{Disable hyphenation even if the font
671 % \changes{v1.5q}{2003/08/22}{Use \cs{@noligs}, as it is by now properly
672 % defined in the \LaTeXe{} kernel.}
674 \def\verbatim@font{\normalfont\ttfamily
675 \hyphenchar\font\m@ne
681 % \begin{macro}{\@verbatim}
682 % \changes{v1.1a}{1989/10/16}{\cs{@verbatim} added.}
683 % The macro |\@verbatim| sets up things properly.
684 % First of all, the tokens of the |\every@verbatim| hook
686 % Then a \texttt{trivlist} environment is started and its first
687 % |\item| command inserted.
688 % Each line of the \texttt{verbatim} or \texttt{verbatim*}
689 % environment will be treated as a separate paragraph.
690 % \changes{v1.2e}{1990/01/15}{Added \cs{every@verbatim} hook.}
691 % \changes{v1.5b}{1994/01/24}{Removed optional argument of \cs{item}.}
693 \def\@verbatim{\the\every@verbatim
694 \trivlist \item \relax
696 % \changes{v1.5b}{1994/01/24}{Set \texttt{@inlabel} switch to false.}
697 % \changes{v1.5f}{1994/10/25}{Removed setting of \texttt{@inlabel}
699 % \changes{v1.3c}{1990/02/26}{Removed extra vertical space.
700 % Suggested by Frank Mittelbach.}
701 % \changes{v1.5h}{1995/09/21}{Added the space again, since it is
702 % necessary for correct vertical spacing if \texttt{verbatim}
703 % is nested inside \texttt{quote}.}
704 % The following extra vertical space is for compatibility with the
705 % \LaTeX kernel: otherwise, using the |verbatim| package changes
706 % the vertical spacing of a |verbatim| environment nested within a
707 % |quote| environment.
709 \if@minipage\else\vskip\parskip\fi
711 % \changes{v1.4k}{1992/07/13}{Added setting for
712 % \cs{@beginparpenalty}. Suggested by Frank Mittelbach.}
713 % The paragraph parameters are set appropriately:
714 % the penalty at the beginning of the environment,
715 % left and right margins, paragraph indentation, the glue to
716 % fill the last line, and the vertical space between paragraphs.
717 % The latter space has to be zero since we do not want to add
718 % extra space between lines.
720 \@beginparpenalty \predisplaypenalty
721 \leftskip\@totalleftmargin\rightskip\z@
722 \parindent\z@\parfillskip\@flushglue\parskip\z@
724 % \changes{v1.1b}{1989/10/18}{Added resetting of \cs{parshape}
725 % if at beginning of a list.
726 % (Problem pointed out by Chris Rowley.)}
727 % There's one point to make here:
728 % the \texttt{list} environment uses \TeX's |\parshape|
729 % primitive to get a special indentation for the first line
731 % If the list begins with a \texttt{verbatim} environment
732 % this |\parshape| is still in effect.
733 % Therefore we have to reset this internal parameter explicitly.
734 % We could do this by assigning $0$ to |\parshape|.
735 % However, there is a simpler way to achieve this:
736 % we simply tell \TeX{} to start a new paragraph.
737 % As is explained on p.~103 of the \TeX{}book, this resets
738 % |\parshape| to zero.
739 % \changes{v1.1c}{1989/10/19}{Replaced explicit resetting of
740 % \cs{parshape} by \cs{@@par}.}
744 % We now ensure that |\par| has the correct definition,
745 % namely to force \TeX{} into horizontal mode
746 % and to include an empty box.
747 % This is to ensure that empty lines do appear in the output.
748 % Afterwards, we insert the |\interlinepenalty| since \TeX{}
749 % does not add a penalty between paragraphs (here: lines)
750 % by its own initiative. Otherwise a |verbatim| environment
751 % could be broken across pages even if a |\samepage|
752 % declaration were present.
754 % However, in a top-aligned minipage, this will result in an extra
755 % empty line added at the top. Therefore, a slightly more
756 % complicated construct is necessary.
757 % One of the important things here is the inclusion of
758 % |\leavevmode| as the first macro in the first line, for example,
759 % a blank verbatim line is the first thing in a list item.
760 % \changes{v1.2c}{1989/10/31}{Definition of \cs{par} added.
761 % Ensures identical behaviour for
762 % verbatim and \cs{verbatiminput}.
763 % Problem pointed out by Chris.}
764 % \changes{v1.4d}{1991/04/24}{\cs{penalty}\cs{interlinepenalty} added.
765 % Necessary to avoid page breaks in
766 % the scope of a \cs{samepage} declaration.}
767 % \changes{v1.5b}{1994/01/24}{Improved definition of \cs{par} to work
768 % under all circumstances.}
769 % \changes{v1.5f}{1994/10/25}{\cs{leavevmode} added for first line.}
773 \leavevmode\null\@@par\penalty\interlinepenalty
776 \ifhmode\@@par\penalty\interlinepenalty\fi
779 % But to avoid an error message when the environment
780 % doesn't contain any text, we redefine |\@noitemerr|
781 % which will in this case be called by |\endtrivlist|.
782 % \changes{v1.4j}{1992/06/30}{Introduced warning instead of error
783 % for empty body of verbatim text.
784 % Suggested by Nelson Beebe.}
786 \def\@noitemerr{\@warning{No verbatim text}}%
788 % Now we call |\obeylines| to make the end of line character
793 % change the category code of all special characters,
795 % \changes{v1.5i}{1996/06/04}{Moved \cs{verbatim@font} after
798 \let\do\@makeother \dospecials
800 % and switch to the font to be used.
804 % To avoid a breakpoint after the labels box, we remove the penalty
805 % put there by the list macros: another use of |\unpenalty|!
806 % \changes{v1.5f}{1994/10/25}{Change to \cs{everypar} added.}
808 \everypar \expandafter{\the\everypar \unpenalty}}
813 % \begin{macro}{\verbatim}
814 % \begin{macro}{\verbatim*}
815 % Now we define the toplevel macros.
816 % |\verbatim| is slightly changed:
817 % after setting up things properly it calls
819 % \changes{v1.5l}{1999/12/14}{Added \cs{begingroup} for cases where
820 % \cs{verbatim} is used directly, rather than in \cs{begin}: see
822 % This is done inside a group, so that |\verbatim| can be used
823 % directly, without |\begin|.
825 \def\verbatim{\begingroup\@verbatim \frenchspacing\@vobeyspaces
828 % |\verbatim*| is defined accordingly.
830 \@namedef{verbatim*}{\begingroup\@verbatim\verbatim@start}
835 % \begin{macro}{\endverbatim}
836 % \begin{macro}{\endverbatim*}
837 % To end the \texttt{verbatim} and \texttt{verbatim*}
838 % environments it is only necessary to finish the
839 % \texttt{trivlist} environment started in |\@verbatim| and
840 % close the corresponding group.
841 % \changes{v1.5l}{1999/12/14}{Added \cs{endgroup} for cases where
842 % \cs{endverbatim} is used directly, rather than in \cs{end}: see
844 % \changes{v1.5n}{2000/08/03}{Added \cs{@endpetrue}: needed when
845 % faking such a \cs{end} (pr/3234).}
846 % \changes{v1.5o}{2000/08/23}{Changed \cs{@endpetrue} to \cs{@doendpe}:
849 \def\endverbatim{\endtrivlist\endgroup\@doendpe}
850 \expandafter\let\csname endverbatim*\endcsname =\endverbatim
856 % \subsection{The \texttt{comment} environment}
858 % \begin{macro}{\comment}
859 % \begin{macro}{\endcomment}
860 % \changes{v1.1c}{1989/10/19}{Added \cs{@bsphack}/\cs{@esphack} to the
861 % \texttt{comment} environment. Suggested by Chris Rowley.}
862 % The |\comment| macro is similar to |\verbatim*|.
863 % However, we do not need to switch fonts or set special
864 % formatting parameters such as |\parindent| or |\parskip|.
865 % We need only set the category code of all special characters
866 % to $12$ (other) and that of |^^M| (the end of line character)
868 % The latter is needed for macro parameter delimiter matching in
869 % the internal macros defined below.
870 % In contrast to the default definitions used by the
871 % |\verbatim| and |\verbatim*| macros,
872 % we define |\verbatim@addtoline| to throw away its argument
873 % and |\verbatim@processline|, |\verbatim@startline|,
874 % and |\verbatim@finish| to act as no-ops.
875 % Then we call |\verbatim@|.
876 % But the first thing we do is to call |\@bsphack| so that
877 % this environment has no influence whatsoever upon the spacing.
878 % \changes{v1.1c}{1989/10/19}{Changed \cs{verbatim@start} to
879 % \cs{verbatim@}. Suggested by Chris Rowley.}
880 % \changes{v1.1c}{1989/10/19}{\cs{verbatim@startline} and
881 % \cs{verbatim@finish} are now
882 % also redefined to do nothing.}
884 \def\comment{\@bsphack
885 \let\do\@makeother\dospecials\catcode`\^^M\active
886 \let\verbatim@startline\relax
887 \let\verbatim@addtoline\@gobble
888 \let\verbatim@processline\relax
889 \let\verbatim@finish\relax
892 % |\endcomment| is very simple: it only calls
893 % |\@esphack| to take care of the spacing.
894 % The |\end| macro closes the group and therefore takes care
895 % of restoring everything we changed.
897 \let\endcomment=\@esphack
904 % \subsection{The main loop}
906 % Here comes the tricky part:
907 % During the definition of the macros we need to use the special
908 % characters |\|, |{|, and |}| not only with their
909 % normal category codes,
910 % but also with category code $12$ (other).
911 % We achieve this by the following trick:
912 % first we tell \TeX{} that |\|, |{|, and |}|
913 % are the lowercase versions of |!|, |[|, and |]|.
914 % Then we replace every occurrence of |\|, |{|, and |}|
915 % that should be read with category code $12$ by |!|, |[|,
916 % and |]|, respectively,
917 % and give the whole list of tokens to |\lowercase|,
918 % knowing that category codes are not altered by this primitive!
920 % But first we have ensure that
921 % |!|, |[|, and |]| themselves have
922 % the correct category code!
923 % \changes{v1.3b}{1990/02/07}{Introduced \cs{vrb@catcodes} instead
924 % of explicit setting of category codes.}
925 % To allow special settings of these codes we hide their setting in
926 % the macro |\vrb@catcodes|. If it is already defined our new
927 % definition is skipped.
929 \@ifundefined{vrb@catcodes}%
931 \catcode`\!12\catcode`\[12\catcode`\]12}}{}
933 % This trick allows us to use this code for applications where other
934 % category codes are in effect.
936 % We start a group to keep the category code changes local.
940 \lccode`\!=`\\ \lccode`\[=`\{ \lccode`\]=`\}
942 % \changes{v1.2f}{1990/01/31}{Code for TABs removed.}
943 % We also need the end-of-line character |^^M|,
944 % as an active character.
945 % If we were to simply write |\catcode`\^^M=\active|
946 % then we would get an unwanted active end of line character
947 % at the end of every line of the following macro definitions.
948 % Therefore we use the same trick as above:
949 % we write a tilde |~| instead of |^^M| and
951 % latter is the lowercase variant of the former.
952 % Thus we have to ensure now that the tilde character has
953 % category code $13$ (active).
955 \catcode`\~=\active \lccode`\~=`\^^M
957 % The use of the |\lowercase| primitive leads to one problem:
958 % the uppercase character `|C|' needs to be used in the
959 % code below and its case must be preserved.
960 % So we add the command:
964 % Now we start the token list passed to |\lowercase|.
965 % We use the following little trick (proposed by Bernd Raichle):
966 % The very first token in the token list we give to |\lowercase| is
967 % the |\endgroup| primitive. This means that it is processed by
968 % \TeX{} immediately after |\lowercase| has finished its operation,
969 % thus ending the group started by |\begingroup| above. This avoids
970 % the global definition of all macros.
974 % \begin{macro}{\verbatim@start}
975 % The purpose of |\verbatim@start| is to check whether there
976 % are any characters on the same line as the |\begin{verbatim}|
977 % and to pretend that they were on a line by themselves.
978 % On the other hand, if there are no characters remaining
979 % on the current line we shall just find an end of line character.
980 % |\verbatim@start| performs its task by first grabbing the
981 % following character (its argument).
982 % This argument is then compared to an active |^^M|,
983 % the end of line character.
985 \def\verbatim@start#1{%
987 \if\noexpand#1\noexpand~%
989 % If this is true we transfer control to |\verbatim@|
990 % to process the next line. We use
991 % |\next| as the macro which will continue the work.
995 % Otherwise, we define |\next| to expand to a call
996 % to |\verbatim@| followed by the character just
997 % read so that it is reinserted into the text.
998 % This means that those characters remaining on this line
999 % are handled as if they formed a line by themselves.
1001 \else \def\next{\verbatim@#1}\fi
1003 % Finally we call |\next|.
1009 % \begin{macro}{\verbatim@}
1010 % The three macros |\verbatim@|, |\verbatim@@|,
1011 % and |\verbatim@@@| form the ``main loop'' of the
1012 % \texttt{verbatim} environment.
1013 % The purpose of |\verbatim@| is to read exactly one line
1015 % |\verbatim@@| and |\verbatim@@@| work together to
1016 % find out whether the four characters
1017 % |\end| (all with category code $12$ (other)) occur in that
1019 % If so, |\verbatim@@@| will call
1020 % |\verbatim@test| to check whether this |\end| is
1021 % part of |\end{verbatim}| and will terminate the environment
1022 % if this is the case.
1023 % Otherwise we continue as if nothing had happened.
1024 % So let's have a look at the definition of |\verbatim@|:
1025 % \changes{v1.1a}{1989/10/16}{Replaced \cs{verbatim@@@} by \cs{@nil}.}
1027 \def\verbatim@#1~{\verbatim@@#1!end\@nil}%
1029 % Note that the |!| character will have been replaced by a
1030 % |\| with category code $12$ (other) by the |\lowercase|
1031 % primitive governing this code before the definition of this
1032 % macro actually takes place.
1034 % it takes the line, puts |\end| (four character tokens)
1035 % and |\@nil| (one control sequence token) as a
1036 % delimiter behind it, and
1037 % then calls |\verbatim@@|.
1040 % \begin{macro}{\verbatim@@}
1041 % |\verbatim@@| takes everything up to the next occurrence of
1042 % the four characters |\end| as its argument.
1044 \def\verbatim@@#1!end{%
1046 % That means: if they do not occur in the original line, then
1047 % argument |#1| is the
1048 % whole input line, and |\@nil| is the next token
1050 % However, if the four characters |\end| are part of the
1051 % original line, then
1052 % |#1| consists of the characters in front of |\end|,
1053 % and the next token is the following character (always remember
1054 % that the line was lengthened by five tokens).
1055 % Whatever |#1| may be, it is verbatim text,
1056 % so |#1| is added to the line currently built.
1058 \verbatim@addtoline{#1}%
1060 % The next token in the input stream
1061 % is of special interest to us.
1062 % Therefore |\futurelet| defines |\next| to be equal
1063 % to it before calling |\verbatim@@@|.
1065 \futurelet\next\verbatim@@@}%
1069 % \begin{macro}{\verbatim@@@}
1070 % \changes{v1.1a}{1989/10/16}{Replaced \cs{verbatim@@@} by
1071 % \cs{@nil} where used as delimiter.}
1072 % |\verbatim@@@| will now read the rest of the tokens on
1074 % up to the final |\@nil| token.
1076 \def\verbatim@@@#1\@nil{%
1078 % If the first of the above two cases occurred, i.e.\ no
1079 % |\end| characters were on that line, |#1| is empty
1080 % and |\next| is equal to |\@nil|.
1081 % This is easily checked.
1085 % If so, this was a simple line.
1086 % We finish it by processing the line we accumulated so far.
1087 % Then we prepare to read the next line.
1088 % \changes{v1.2f}{1990/01/31}{Added \cs{verbatim@startline}.}
1090 \verbatim@processline
1094 % Otherwise we have to check what follows these |\end|
1099 % Before we continue, it's a good idea to stop for a moment
1100 % and remember where we are:
1101 % We have just read the four character tokens |\end|
1102 % and must now check whether the name of the environment (surrounded
1103 % by braces) follows.
1104 % To this end we define a macro called |\@tempa|
1105 % that reads exactly one character and decides what to do next.
1106 % This macro should do the following: skip spaces until
1107 % it encounters either a left brace or the end of the line.
1108 % But it is important to remember which characters are skipped.
1109 % The |\end|\meta{optional spaces}|{| characters
1110 % may be part of the verbatim text, i.e.\ these characters
1113 % Assume for example that the current line contains
1115 % \end {AVeryLongEnvironmentName}
1117 % As we shall soon see, the scanning mechanism implemented here
1118 % will not find out that this is text to be printed until
1119 % it has read the right brace.
1120 % Therefore we need a way to accumulate the characters read
1121 % so that we can reinsert them if necessary.
1122 % The token register |\@temptokena| is used for this purpose.
1124 % Before we do this we have to get rid of the superfluous
1125 % |\end| tokens at the end of the line.
1126 % \changes{v1.4j}{1992/06/30}{Removed use of \cs{toks@}. Suggested by
1128 % To this end we define a temporary macro whose argument
1129 % is delimited by |\end\@nil| (four character tokens
1130 % and one control sequence token) to be used below
1131 % on the rest of the line, after appending a |\@nil| token to it.
1132 % (Note that this token can never appear in |#1|.)
1133 % We use the following definition of
1134 % |\@tempa| to get the rest of the line (after the first
1137 \def\@tempa##1!end\@nil{##1}%
1139 % We mentioned already that we use token register
1141 % to remember the characters we skip, in case we need them again.
1142 % We initialize this with the |\end| we have thrown away
1143 % in the call to |\@tempa|.
1147 % We shall now call |\verbatim@test|
1148 % to process the characters
1149 % remaining on the current line.
1150 % But wait a moment: we cannot simply call this macro
1151 % since we have already read the whole line.
1152 % Therefore we have to first expand the macro |\@tempa| to insert
1153 % them again after the |\verbatim@test| token.
1154 % A |^^M| character is appended to denote the end of the line.
1155 % (Remember that this character comes disguised as a tilde.)
1156 % \changes{v1.2}{1989/10/20}{Taken local definition of \cs{@tempa} out
1157 % of \cs{verbatim@@@} and introduced
1158 % \cs{verbatim@test} instead.}
1160 \def\next{\expandafter\verbatim@test\@tempa#1\@nil~}%
1162 % That's almost all, but we still have to
1163 % now call |\next| to do the work.
1170 % \begin{macro}{\verbatim@test}
1171 % \changes{v1.2}{1989/10/20}{Introduced \cs{verbatim@test}.}
1172 % We define |\verbatim@test| to investigate every token
1175 \def\verbatim@test#1{%
1177 % First of all we set |\next| equal to |\verbatim@test|
1178 % in case this macro must call itself recursively in order to
1181 \let\next\verbatim@test
1183 % We have to distinguish four cases:
1185 % \item The next token is a |^^M|, i.e.\ we reached
1186 % the end of the line. That means that nothing
1187 % special was found.
1188 % Note that we use |\if| for the following
1189 % comparisons so that the category code of the
1190 % characters is irrelevant.
1192 \if\noexpand#1\noexpand~%
1194 % We add the characters accumulated in token register
1195 % |\@temptokena| to the current line. Since
1196 % |\verbatim@addtoline| does not expand its argument,
1197 % we have to do the expansion at this point. Then we
1198 % |\let| |\next| equal to |\verbatim@|
1199 % to prepare to read the next line.
1200 % \changes{v1.2f}{1990/01/31}{Added \cs{verbatim@startline}.}
1202 \expandafter\verbatim@addtoline
1203 \expandafter{\the\@temptokena}%
1204 \verbatim@processline
1208 % \item A space character follows.
1209 % This is allowed, so we add it to |\@temptokena|
1212 \else \if\noexpand#1
1213 \@temptokena\expandafter{\the\@temptokena#1}%
1215 % \changes{v1.2f}{1990/01/31}{Code for TABs removed.}
1216 % \item An open brace follows.
1217 % This is the most interesting case.
1218 % We must now collect characters until we read the closing
1219 % brace and check whether they form the environment name.
1220 % This will be done by |\verbatim@testend|, so here
1221 % we let |\next| equal this macro.
1222 % Again we will process the rest of the line, character
1224 % \changes{v1.2}{1989/10/20}{Moved the initialization of
1225 % \cs{@tempc} from \cs{verbatim@testend} into
1226 % \cs{verbatim@test}.}
1227 % The characters forming the name of the environment will
1228 % be accumulated in |\@tempc|.
1229 % We initialize this macro to expand to nothing.
1230 % \changes{v1.3b}{1990/02/07}{\cs{noexpand} added.}
1232 \else \if\noexpand#1\noexpand[%
1234 \let\next\verbatim@testend
1236 % Note that the |[| character will be a |{| when
1237 % this macro is defined.
1238 % \item Any other character means that the |\end| was part
1239 % of the verbatim text.
1240 % Add the characters to the current line and prepare to call
1241 % |\verbatim@| to process the rest of the line.
1242 % \changes{v1.0f}{1989/10/09}{Fixed \cs{end} \cs{end} bug
1243 % found by Chris Rowley}
1246 \expandafter\verbatim@addtoline
1247 \expandafter{\the\@temptokena}%
1248 \def\next{\verbatim@#1}%
1252 % The last thing this macro does is to call |\next|
1253 % to continue processing.
1259 % \begin{macro}{\verbatim@testend}
1260 % |\verbatim@testend| is called when
1261 % |\end|\meta{optional spaces}|{| was seen.
1262 % Its task is to scan everything up to the next |}|
1263 % and to call |\verbatim@@testend|.
1264 % If no |}| is found it must reinsert the characters it read
1265 % and return to |\verbatim@|.
1266 % The following definition is similar to that of
1268 % it takes the next character and decides what to do.
1269 % \changes{v1.2}{1989/10/20}{Removed local definition of \cs{@tempa}
1270 % from \cs{verbatim@testend} which now
1271 % does the work itself.}
1273 \def\verbatim@testend#1{%
1275 % Again, we have four cases:
1277 % \item |^^M|: As no |}| is found in the current line,
1278 % add the characters to the buffer. To avoid a
1279 % complicated construction for expanding
1281 % and |\@tempc| we do it in two steps. Then we
1282 % continue with |\verbatim@| to process the
1284 % \changes{v1.2f}{1990/01/31}{Added \cs{verbatim@startline}.}
1286 \if\noexpand#1\noexpand~%
1287 \expandafter\verbatim@addtoline
1288 \expandafter{\the\@temptokena[}%
1289 \expandafter\verbatim@addtoline
1290 \expandafter{\@tempc}%
1291 \verbatim@processline
1295 % \item |}|: Call |\verbatim@@testend| to check
1296 % if this is the right environment name.
1297 % \changes{v1.3b}{1990/02/07}{\cs{noexpand} added.}
1299 \else\if\noexpand#1\noexpand]%
1300 \let\next\verbatim@@testend
1302 % \changes{v1.0f}{1989/10/09}{Introduced check for
1303 % {\tt\string\verb!\string|!\string\!\string|} to fix
1304 % single brace bug found by Chris Rowley}
1305 % \item |\|: This character must not occur in the name of
1306 % an environment. Thus we stop collecting characters.
1307 % In principle, the same argument would apply to other
1308 % characters as well, e.g., |{|.
1309 % However, |\| is a special case, since it may be
1310 % the first character of |\end|. This means that
1311 % we have to look again for
1312 % |\end{|\meta{environment name}|}|.
1313 % Note that we prefixed the |!| by a |\noexpand|
1314 % primitive, to protect ourselves against it being an
1316 % \changes{v1.3b}{1990/02/07}{\cs{noexpand} added.}
1318 \else\if\noexpand#1\noexpand!%
1319 \expandafter\verbatim@addtoline
1320 \expandafter{\the\@temptokena[}%
1321 \expandafter\verbatim@addtoline
1322 \expandafter{\@tempc}%
1323 \def\next{\verbatim@!}%
1325 % \item Any other character: collect it and continue.
1326 % We cannot use |\edef| to define |\@tempc|
1327 % since its replacement text might contain active
1330 \else \expandafter\def\expandafter\@tempc\expandafter
1331 {\@tempc#1}\fi\fi\fi
1334 % As before, the macro ends by calling itself, to
1335 % process the next character if appropriate.
1341 % \begin{macro}{\verbatim@@testend}
1342 % Unlike the previous macros |\verbatim@@testend| is simple:
1343 % it has only to check if the |\end{|\ldots|}|
1344 % matches the corresponding |\begin{|\ldots|}|.
1346 \def\verbatim@@testend{%
1348 % We use |\next| again to define the things that are
1350 % Remember that the name of the current environment is
1351 % held in |\@currenvir|, the characters accumulated
1352 % by |\verbatim@testend| are in |\@tempc|.
1353 % So we simply compare these and prepare to execute
1354 % |\end{|\meta{current environment}|}|
1355 % macro if they match.
1356 % Before we do this we call |\verbatim@finish| to process
1358 % We define |\next| via |\edef| so that
1359 % |\@currenvir| is replaced by its expansion.
1360 % Therefore we need |\noexpand| to inhibit the expansion
1361 % of |\end| at this point.
1363 \ifx\@tempc\@currenvir
1365 \edef\next{\noexpand\end{\@currenvir}%
1367 % Without this trick the |\end| command would not be able
1368 % to correctly check whether its argument matches the name of
1369 % the current environment and you'd get an
1370 % interesting \LaTeX{} error message such as:
1372 %! \begin{verbatim*} ended by \end{verbatim*}.
1374 % But what do we do with the rest of the characters, those
1375 % that remain on that line?
1376 % We call |\verbatim@rescan| to take care of that.
1377 % Its first argument is the name of the environment just
1378 % ended, in case we need it again.
1379 % |\verbatim@rescan| takes the list of characters to be
1380 % reprocessed as its second argument.
1381 % (This token list was inserted after the current macro
1382 % by |\verbatim@@@|.)
1383 % Since we are still in an |\edef| we protect it
1384 % by means of|\noexpand|.
1386 \noexpand\verbatim@rescan{\@currenvir}}%
1388 % If the names do not match, we reinsert everything read up
1389 % to now and prepare to call |\verbatim@| to process
1390 % the rest of the line.
1393 \expandafter\verbatim@addtoline
1394 \expandafter{\the\@temptokena[}%
1395 \expandafter\verbatim@addtoline
1396 \expandafter{\@tempc]}%
1400 % Finally we call |\next|.
1406 % \begin{macro}{\verbatim@rescan}
1407 % In principle |\verbatim@rescan| could be used to
1408 % analyse the characters remaining after the |\end{...}|
1409 % command and pretend that these were read
1410 % ``properly'', assuming ``standard'' category codes are in
1411 % force.\footnote{Remember that they were all read with
1412 % category codes $11$ (letter) and $12$ (other) so
1413 % that control sequences are not recognized as such.}
1414 % But this is not always possible (when there are unmatched
1415 % curly braces in the rest of the line).
1416 % Besides, we think that this is not worth the effort:
1417 % After a \texttt{verbatim} or \texttt{verbatim*} environment
1418 % a new line in the output is begun anyway,
1419 % and an |\end{comment}| can easily be put on a line by itself.
1420 % So there is no reason why there should be any text here.
1421 % For the benefit of the user who did put something there
1422 % (a comment, perhaps)
1423 % we simply issue a warning and drop them.
1424 % The method of testing is explained in Appendix~D, p.\ 376 of
1425 % the \TeX{}book. We use |^^M| instead of the |!|
1426 % character used there
1427 % since this is a character that cannot appear in |#1|.
1428 % The two |\noexpand| primitives are necessary to avoid
1429 % expansion of active characters and macros.
1431 % One extra subtlety should be noted here: remember that
1432 % the token list we are currently building will first be
1433 % processed by the |\lowercase| primitive before \TeX{}
1434 % carries out the definitions.
1435 % This means that the `|C|' character in the
1436 % argument to the |\@warning| macro must be protected against
1437 % being changed to `|c|'. That's the reason why we added the
1438 % |\lccode`\C=`\C| assignment above.
1439 % We can now finish the argument to |\lowercase| as well as the
1440 % group in which the category codes were changed.
1442 \def\verbatim@rescan#1#2~{\if\noexpand~\noexpand#2~\else
1443 \@warning{Characters dropped after `\string\end{#1}'}\fi}}
1447 % \subsection{The \cs{verbatiminput} command}
1449 % \begin{macro}{\verbatim@in@stream}
1450 % We begin by allocating an input stream (out of the 16 available
1453 % Vorstellbar ist auch der Aufruf von |`verbatiminput| innerhalb eines
1454 % |`verbatiminput| (z.B: wenn man |`input|-Anweisungen im zu lesenden
1455 % File hat und auch diese Files automatisch lesen will). Dies kann
1456 % man jedoch nur ermoeglichen, wenn man einen besseren Mechanismus
1457 % verwendet als es das simple, statische |`newread| darstellt.
1458 % Vorstellbar fuer eine neuere \LaTeX-Version ist eine (lokale)
1459 % Allokation des Streams durch ein |`open| und eine Freigabe des
1460 % Streams durch |`close| oder Verlassen der Gruppe.
1463 \newread\verbatim@in@stream
1467 % \begin{macro}{\verbatim@readfile}
1468 % The macro |\verbatim@readfile| encloses the main loop by calls to
1469 % the macros |\verbatim@startline| and |\verbatim@finish|,
1470 % respectively. This makes sure
1471 % that the user can initialize and finish the command when the file
1472 % is empty or doesn't exist. The \texttt{verbatim} environment has a
1473 % similar behaviour when called with an empty text.
1475 \def\verbatim@readfile#1{%
1478 % When the file is not found we issue a warning.
1480 \openin\verbatim@in@stream #1\relax
1481 \ifeof\verbatim@in@stream
1482 \typeout{No file #1.}%
1485 % At this point we pass the name of the file to |\@addtofilelist|
1486 % so that its appears appears in the output of a |\listfiles|
1488 % \changes{v1.5j}{1996/09/25}{Add \cs{@addtofilelist} and
1489 % \cs{ProvidesFile} so that the name of the file
1490 % read in appears in the \cs{listfiles} output (Omission pointed
1491 % out by Patrick W.~Daly).}
1492 % In addition, we use |\ProvidesFile| to make a log entry in the
1493 % transcript file and to distinguish files read in via
1494 % |\verbatiminput| from others.
1496 \@addtofilelist{#1}%
1497 \ProvidesFile{#1}[(verbatim)]%
1499 % While reading from the file it is useful to switch off the
1500 % recognition of the end-of-line character. This saves us stripping
1501 % off spaces from the contents of the line.
1503 \expandafter\endlinechar\expandafter\m@ne
1504 \expandafter\verbatim@read@file
1505 \expandafter\endlinechar\the\endlinechar\relax
1506 \closein\verbatim@in@stream
1513 % \begin{macro}{\verbatim@read@file}
1514 % All the work is done in |\verbatim@read@file|. It reads the input
1515 % file line by line and recursively calls itself until the end of
1518 \def\verbatim@read@file{%
1519 \read\verbatim@in@stream to\next
1520 \ifeof\verbatim@in@stream
1523 % For each line we call |\verbatim@addtoline| with the contents of
1524 % the line. \hskip0pt plus 3cm\penalty0\hskip0pt plus -3cm
1525 % |\verbatim@processline| is called next.
1527 \expandafter\verbatim@addtoline\expandafter{\next}%
1528 \verbatim@processline
1530 % After processing the line we call |\verbatim@startline| to
1531 % initialize all before we read the next line.
1535 % Without |\expandafter| each call of |\verbatim@read@file| uses
1536 % space in \TeX's input stack.\footnote{A standard \TeX\ would
1537 % report an overflow error if you try to read a file with more than
1538 % ca.\ 200~lines. The same error occurs if the first line of code
1539 % in \S 390 of \textsl{``TeX: The Program''\/} is missing.}
1541 \expandafter\verbatim@read@file
1548 % \begin{macro}{\verbatiminput}
1549 % |\verbatiminput| first starts a group to keep font and category
1551 % Then it calls the macro |\verbatim@input| with additional
1552 % arguments, depending on whether an asterisk follows.
1554 \def\verbatiminput{\begingroup
1555 \@ifstar{\verbatim@input\relax}%
1556 {\verbatim@input{\frenchspacing\@vobeyspaces}}}
1560 % \begin{macro}{\verbatim@input}
1561 % \changes{1.5k}{1997/04/30}{Have \cs{verbatim@input} check for
1562 % existence of file.}
1563 % |\verbatim@input| first checks whether the file exists, using
1564 % the standard macro |\IfFileExists| which leaves the name of the
1565 % file found in |\@filef@und|.
1566 % Then everything is set up as in the |\verbatim| macro.
1568 \def\verbatim@input#1#2{%
1569 \IfFileExists {#2}{\@verbatim #1\relax
1571 % Then it reads in the file, finishes off the \texttt{trivlist}
1572 % environment started by |\@verbatim| and closes the group.
1573 % This restores everything to its normal settings.
1575 \verbatim@readfile{\@filef@und}\endtrivlist\endgroup\@doendpe}%
1577 % If the file is not found a more or less helpful message is
1578 % printed. The final |\endgroup| is needed to close the group
1579 % started in |\verbatiminput| above.
1581 {\typeout {No file #2.}\endgroup}}
1587 % \subsection{Getting verbatim text into arguments.}
1589 % One way of achieving this is to define a macro (command) whose
1590 % expansion is the required verbatim text. This command can then be
1591 % used anywhere that the verbatim text is required. It can be used in
1592 % arguments, even moving ones, but it is fragile (at least, the
1595 % Here is some code which claims to provide this. It is a much revised
1596 % version of something I (Chris) did about 2 years ago. Maybe it needs
1599 % It is only intended as an extension to |\verb|, not to the
1600 % \texttt{verbatim} environment. It should therefore, perhaps, treat
1601 % line-ends similarly to whatever is best for |\verb|.
1603 % \begin{macro}{\newverbtext}
1604 % This is the command to produce a new macro whose expansion is
1605 % verbatim text. This command itself cannot be used in arguments,
1606 % of course! It is used as follows:
1609 % \newverbtext{\myverb}"^%{ &~_\}}@ #"
1612 % The rules for delimiting the verbatim text are the same as those for
1617 \def \newverbtext {%
1618 \@ifstar {\@tempswatrue \@verbtext }{\@tempswafalse \@verbtext *}%
1622 % I think that a temporary switch is safe here: if not, then
1623 % suitable |\let|s can be used.
1624 % \changes{v1.5i}{1996/06/04}{Moved processing of
1625 % \cs{verbatim@nolig@list} after \cs{dospecials}.}
1626 % \changes{v1.5p}{2001/03/12}{Added missing right brace in
1627 % definition of \cs{@verbtext} (PR 3314).}
1629 \def \@verbtext *#1#2{%
1631 \let\do\@makeother \dospecials
1632 \let\do\do@noligs \verbatim@nolig@list
1639 % We use a temporary macro here and a trick so that the definition of
1640 % the command itself can be done inside the group and be a local
1641 % definition (there may be better ways to achieve this).
1646 % If these |\noexpand|s were |\noexpand\protect\noexpand|, would
1647 % this make these things robust?
1649 \edef #1{\noexpand \@verbtextmcheck
1652 \noexpand \visiblespaces
1654 \noexpand \@verbtextsetup
1658 \expandafter\endgroup\@tempa
1662 % This sets up the correct type of group for the mode: it must not
1663 % be expanded at define time!
1665 \def \@verbtextmcheck {%
1674 % This contains other things which should not be expanded during the
1677 \def \@verbtextsetup {%
1683 % The command |\verbtextstyle| is a document-level hook which can be
1684 % used to override the predefined typographic treatment of commands
1685 % defined with |\newverbtext| commands.
1687 % |\visiblespaces| and |\whitespaces| are examples of possible values
1690 \let \verbtextstyle \relax
1691 \def \visiblespaces {\chardef \ 32\relax}
1692 \def \whitespaces {\let \ \@@space}
1698 % \section{Testing the implementation}
1700 % For testing the implementation and for demonstration we provide
1701 % an extra file. It can be extracted by using the conditional
1702 % `\textsf{testdriver}'. It uses a small input file called
1703 % `\texttt{verbtest.tst}' that is distributed separately.
1704 % Again, we use individual `+' guards.
1707 \documentclass{article}
1709 \usepackage{verbatim}
1711 \newenvironment{myverbatim}%
1712 {\endgraf\noindent MYVERBATIM:\endgraf\verbatim}%
1717 \newenvironment{verbatimlisting}[1]%
1718 {\def\verbatim@startline{\input{#1}%
1719 \def\verbatim@startline{\verbatim@line{}}%
1720 \verbatim@startline}%
1721 \verbatim}{\endverbatim}
1723 \newwrite\verbatim@out
1725 \newenvironment{verbatimwrite}[1]%
1727 \immediate\openout \verbatim@out #1
1728 \let\do\@makeother\dospecials\catcode`\^^M\active
1729 \def\verbatim@processline{%
1730 \immediate\write\verbatim@out{\the\verbatim@line}}%
1732 {\immediate\closeout\verbatim@out\@esphack}
1736 \addtolength{\textwidth}{30pt}
1741 \typeout{===> Expect ``characters dropped''
1742 warning messages in this test! <====}
1745 Text Text Text Text Text Text Text Text Text Text Text
1746 Text Text Text Text Text Text Text Text Text Text Text
1747 Text Text Text Text Text Text Text Text Text Text Text
1753 test of ligatures: <`!`?`>
1758 test of end of line:
1761 \end{verbatim} Further text to be typeset: $\alpha$.
1762 Text Text Text Text Text Text Text Text Text Text Text
1763 Text Text Text Text Text Text Text Text Text Text Text
1764 Text Text Text Text Text Text Text Text Text Text Text
1769 Text Text Text Text Text Text Text Text Text Text Text
1770 Text Text Text Text Text Text Text Text Text Text Text
1771 Text Text Text Text Text Text Text Text Text Text Text
1772 \begin{verbatim*} bla bla
1776 Text Text Text Text Text Text Text Text Text Text Text
1777 Text Text Text Text Text Text Text Text Text Text Text
1778 Text Text Text Text Text Text Text Text Text Text Text
1779 Text Text Text Text Text Text Text Text Text Text Text
1781 First of Chris Rowley's fiendish tests:
1783 the double end test<text>
1784 \end\end{verbatim} or even \end \end{verbatim}
1789 Another of Chris' devils:
1791 the single brace test<text>
1792 \end{not the end\end{verbatim}
1796 Back to my own tests:
1800 \end {myverbatim} rest of line
1801 Text Text Text Text Text Text Text Text Text Text Text
1802 Text Text Text Text Text Text Text Text Text Text Text
1803 Text Text Text Text Text Text Text Text Text Text Text
1805 Test of empty verbatim:
1808 Text Text Text Text Text Text Text Text Text Text Text
1809 Text Text Text Text Text Text Text Text Text Text Text
1810 Text Text Text Text Text Text Text Text Text Text Text
1811 \begin {verbatimlisting}{verbtest.tex}
1812 Additional verbatim text
1814 \end{verbatimlisting}
1815 And here for listing a file:
1816 \verbatiminput{verbtest.tex}
1817 And again, with explicit spaces:
1818 \verbatiminput*{verbtest.tex}
1819 Text Text Text Text Text Text Text Text Text Text Text
1820 Text Text Text Text Text Text Text Text Text Text Text
1821 Text Text Text Text Text Text Text Text Text Text Text
1832 \end {comment} Further text to be typeset: $\alpha$.
1833 Text Text Text Text Text Text Text Text Text Text Text
1834 Text Text Text Text Text Text Text Text Text Text Text
1835 Text Text Text Text Text Text Text Text Text Text Text
1836 \begin{comment} bla bla
1840 Text Text Text Text Text Text Text Text Text Text Text
1841 Text Text Text Text Text Text Text Text Text Text Text
1842 Text Text Text Text Text Text Text Text Text Text Text
1843 Text Text Text Text Text Text Text Text Text Text Text
1845 \begin{verbatimwrite}{verbtest.txt}
1860 %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
1861 %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
1862 %% Digits \0\1\2\3\4\5\6\7\8\9
1863 %% Exclamation \! Double quote \" Hash (number) \#
1864 %% Dollar \$ Percent \% Ampersand \&
1865 %% Acute accent \' Left paren \( Right paren \)
1866 %% Asterisk \* Plus \+ Comma \,
1867 %% Minus \- Point \. Solidus \/
1868 %% Colon \: Semicolon \; Less than \<
1869 %% Equals \= Greater than \> Question mark \?
1870 %% Commercial at \@ Left bracket \[ Backslash \\
1871 %% Right bracket \] Circumflex \^ Underscore \_
1872 %% Grave accent \` Left brace \{ Vertical bar \|
1873 %% Right brace \} Tilde \~}