| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 1993-2025 |
| 4 |
% |
| 5 |
% The LaTeX Project and any individual authors listed elsewhere |
| 6 |
% in this file. |
| 7 |
% |
| 8 |
% This file is part of the Standard LaTeX `Tools Bundle'. |
| 9 |
% ------------------------------------------------------- |
| 10 |
% |
| 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 |
% https://www.latex-project.org/lppl.txt |
| 16 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 17 |
% version 2008 or later. |
| 18 |
% |
| 19 |
% The list of all files belonging to the LaTeX `Tools Bundle' is |
| 20 |
% given in the file `manifest.txt'. |
| 21 |
% |
| 22 |
% \fi |
| 23 |
% |
| 24 |
%\iffalse % this is a METACOMMENT ! |
| 25 |
% |
| 26 |
% |
| 27 |
%% Package `verbatim' to use with LaTeX2e |
| 28 |
%% Copyright (C) 1989--2003 by Rainer Sch\"opf. All rights reserved. |
| 29 |
% |
| 30 |
% Copying of this file is authorized only if either |
| 31 |
% (1) you make absolutely no changes to your copy, including name, or |
| 32 |
% (2) if you do make changes, you name it something other than |
| 33 |
% verbatim.dtx. |
| 34 |
% This restriction helps ensure that all styles developed here |
| 35 |
% remain identical. |
| 36 |
% |
| 37 |
% |
| 38 |
% |
| 39 |
% \section{Producing the documentation} |
| 40 |
% |
| 41 |
% We provide a short driver file that can be extracted by the |
| 42 |
% \textsf{DocStrip} program using the conditional `\textsf{driver}'. |
| 43 |
% |
| 44 |
% \begin{macrocode} |
| 45 |
%<*driver> |
| 46 |
\documentclass{ltxdoc} |
| 47 |
|
| 48 |
\pagestyle{myheadings} |
| 49 |
|
| 50 |
\title{A New Implementation of \LaTeX{}'s \\ \texttt{verbatim} |
| 51 |
and \texttt{verbatim*} Environments} |
| 52 |
\author{Rainer Sch\"opf\\ |
| 53 |
\and |
| 54 |
Bernd Raichle\\ |
| 55 |
\and |
| 56 |
Chris Rowley} |
| 57 |
|
| 58 |
\date{2023/11/06} |
| 59 |
\begin{document} |
| 60 |
\markboth{Verbatim style option}{Verbatim style option} |
| 61 |
\MaintainedByLaTeXTeam{tools} |
| 62 |
\maketitle |
| 63 |
\DocInput{verbatim.dtx} |
| 64 |
\end{document} |
| 65 |
%</driver> |
| 66 |
% \end{macrocode} |
| 67 |
% |
| 68 |
% |
| 69 |
%\fi |
| 70 |
% |
| 71 |
% |
| 72 |
% |
| 73 |
% \changes{v1.5x}{2024/01/22}{Added TAB marking support to \cs{verbatiminput*}} |
| 74 |
% \changes{v1.5u}{2020-07-07}{Typo repair and added a missing comment |
| 75 |
% character} |
| 76 |
% \changes{v1.5q}{2003/08/22}{Reintroduced \cs{@noligs}, by popular |
| 77 |
% request.} |
| 78 |
% \changes{v1.5i}{1996/06/04}{Move setting of verbatim font and |
| 79 |
% \cs{@noligs}.} |
| 80 |
% \changes{v1.5g}{1995/04/26}{Removed \cs{fileversion} and |
| 81 |
% \cs{filedate} from running head in |
| 82 |
% driver file, as these are no longer |
| 83 |
% defined.} |
| 84 |
% \changes{v1.5f}{1994/10/25}{Removed extra \cs{typeout} commands.} |
| 85 |
% \changes{v1.5e}{1994/06/10}{Added missing closing verbtest guard.} |
| 86 |
% \changes{v1.5d}{1994/05/30}{\cs{NeedsTeXFormat} and |
| 87 |
% \cs{ProvidesPackage} added.} |
| 88 |
% \changes{v1.5d}{1994/05/30}{\cs{addto@hook} removed, now in kernel.} |
| 89 |
% \changes{v1.5a}{1993/10/12}{Included \cs{newverbtext} command, as |
| 90 |
% written by Chris Rowley.} |
| 91 |
% \changes{v1.5}{1993/10/11}{Included vrbinput style option by Bernd |
| 92 |
% Raichle.} |
| 93 |
% |
| 94 |
% \changes{v1.4j}{1992/06/30}{Used \cs{lowercase}\{\cs{endgroup} |
| 95 |
% \ldots\} trick proposed by Bernd Raichle; changed all \cs{gdef} |
| 96 |
% to \cs{def} since no longer necessary.} |
| 97 |
% \changes{v1.4g}{1991/11/21}{Several improvements in the |
| 98 |
% documentation.} |
| 99 |
% \changes{v1.4f}{1991/08/05}{Corrected bug in documentation. |
| 100 |
% Found by Bernd Raichle.} |
| 101 |
% \changes{v1.4e}{1991/07/24}{Avoid reading this file twice.} |
| 102 |
% \changes{v1.4d}{1991/04/24}{\cs{penalty}\cs{interlinepenalty} added to |
| 103 |
% definition of \cs{par} in \cs{@verbatim}. |
| 104 |
% Necessary to avoid page breaks in |
| 105 |
% the scope of a \cs{samepage} declaration.} |
| 106 |
% \changes{v1.4c}{1990/10/18}{Added \cs{leavevmode} to definition of |
| 107 |
% backquote macro.} |
| 108 |
% \changes{v1.4b}{1990/07/14}{Converted nearly all \cs{verb}'s to |
| 109 |
% \texttt{\protect\string!|\ldots\protect\string!|}.} |
| 110 |
% \changes{v1.4a}{1990/04/04}{Added a number of percent characters |
| 111 |
% to suppress blank space at the end of some code lines.} |
| 112 |
% \changes{v1.4}{1990/03/07}{\cs{verb} rewritten.} |
| 113 |
% |
| 114 |
% \changes{v1.3a}{1990/02/04}{Removed \texttt{verbatimwrite} environment |
| 115 |
% from the code. Now only shown as an example.} |
| 116 |
% |
| 117 |
% \changes{v1.2g}{1990/02/01}{Revised documentation.} |
| 118 |
% \changes{v1.2e}{1990/01/15}{Added \cs{every@verbatim} hook.} |
| 119 |
% \changes{v1.2d}{1989/11/29}{Use token register \cs{@temptokena} |
| 120 |
% instead of macro \cs{@tempb}.} |
| 121 |
% \changes{v1.2d}{1989/11/29}{Use token register \cs{verbatim@line} |
| 122 |
% instead of macro \cs{@tempd}.} |
| 123 |
% \changes{v1.2b}{1989/10/25}{\cs{verbatimfile} renamed to |
| 124 |
% \cs{verbatiminput}. Suggested by Reinhard Wonneberger.} |
| 125 |
% |
| 126 |
% \changes{v1.1a}{1989/10/16}{\cs{verb} added.} |
| 127 |
% \changes{v1.1}{1989/10/09}{Made the code more modular (as suggested by |
| 128 |
% Chris Rowley): introduced |
| 129 |
% \cs{verbatim@addtoline}, etc. Added |
| 130 |
% \cs{verbatimwrite} environment.} |
| 131 |
% |
| 132 |
% \changes{v1.0e}{1989/07/17}{Fixed bug in \cs{verbatimfile} (*-form |
| 133 |
% handling, discovered by Dirk Kreimer).} |
| 134 |
% \changes{v1.0d}{1989/05/16}{Revised documentation, fixed silly bug |
| 135 |
% in \cs{verbatim@@@}.} |
| 136 |
% \changes{v1.0c}{1989/05/12}{Added redefinition of \cs{@sverb}, change |
| 137 |
% in end-of-line handling.} |
| 138 |
% \changes{v1.0b}{1989/05/09}{Change in \cs{verbatim@rescan}.} |
| 139 |
% \changes{v1.0a}{1989/05/07}{Change in \cs{verbatim@@testend}.} |
| 140 |
% |
| 141 |
% |
| 142 |
% \DoNotIndex{\ ,\!,\C,\[,\\,\],\^,\`,\{,\},\~} |
| 143 |
% \DoNotIndex{\@M,\@empty,\@flushglue,\@gobble,\@ifstar,\@ifundefined} |
| 144 |
% \DoNotIndex{\@namedef,\@spaces,\@tempa,\@tempb,\@tempc,\@tempd} |
| 145 |
% \DoNotIndex{\@temptokena,\@totalleftmargin,\@warning,\active} |
| 146 |
% \DoNotIndex{\aftergroup,\arabic,\begingroup,\catcode,\char,\closein} |
| 147 |
% \DoNotIndex{\csname,\def,\do,\docdate,\dospecials,\edef,\else} |
| 148 |
% \DoNotIndex{\endcsname,\endgraf,\endgroup,\endinput,\endlinechar} |
| 149 |
% \DoNotIndex{\endtrivlist,\expandafter,\fi,\filedate,\fileversion} |
| 150 |
% \DoNotIndex{\frenchspacing,\futurelet,\if,\ifcat,\ifeof,\ifnum} |
| 151 |
% \DoNotIndex{\ifx,\immediate,\item,\kern,\lccode,\leftskip,\let} |
| 152 |
% \DoNotIndex{\lowercase,\m@ne,\makeatletter,\makeatother,\newread} |
| 153 |
% \DoNotIndex{\newread,\next,\noexpand,\noindent,\openin,\parfillskip} |
| 154 |
% \DoNotIndex{\parindent,\parskip,\penalty,\read,\relax,\rightskip} |
| 155 |
% \DoNotIndex{\sloppy,\space,\string,\the,\toks@,\trivlist,\tt,\typeout} |
| 156 |
% \DoNotIndex{\vskip,\write,\z@} |
| 157 |
% |
| 158 |
% \changes{v1.5x}{2025-06-04}{Add notice pointing to \pkg{fancyvrb}} |
| 159 |
% \begin{flushleft} |
| 160 |
% \bfseries |
| 161 |
% This package is retained in the \LaTeX{} \pkg{tools} bundle for |
| 162 |
% stability reasons. Whilst bug fixes will be applied to \pkg{verbatim}, |
| 163 |
% no \emph{new} features will be considered. For new material, the |
| 164 |
% \LaTeX{} team recommends that \pkg{fancyvrb} is used in place of |
| 165 |
% \pkg{verbatim}. |
| 166 |
% \end{flushleft} |
| 167 |
% |
| 168 |
% \begin{abstract} |
| 169 |
% This package reimplements the \LaTeX{} \texttt{verbatim} and |
| 170 |
% \texttt{verbatim*} environments. |
| 171 |
% In addition it provides a \texttt{comment} environment |
| 172 |
% that skips any commands or text between |
| 173 |
% |\begin{comment}| |
| 174 |
% and the next |\end{comment}|. |
| 175 |
% It also defines the command |\verbatiminput| to input a whole |
| 176 |
% file verbatim. |
| 177 |
% \end{abstract} |
| 178 |
% |
| 179 |
% \section{Usage notes} |
| 180 |
% |
| 181 |
% \let\docDescribeMacro\DescribeMacro |
| 182 |
% \let\docDescribeEnv\DescribeEnv |
| 183 |
% \def\DescribeMacro#1{} |
| 184 |
% \def\DescribeEnv#1{} |
| 185 |
% \LaTeX's \texttt{verbatim} and \texttt{verbatim*} environments |
| 186 |
% have a few features that may give rise to problems. These are: |
| 187 |
% \begin{itemize} |
| 188 |
% \item |
| 189 |
% Due to the method used to detect the closing |\end{verbatim}| |
| 190 |
% (i.e.\ macro parameter delimiting) you cannot leave spaces |
| 191 |
% between the |\end| token and |{verbatim}|. |
| 192 |
% \item |
| 193 |
% Since \TeX{} has to read all the text between the |
| 194 |
% |\begin{verbatim}| and the |\end{verbatim}| before it can output |
| 195 |
% anything, long verbatim listings may overflow \TeX's memory. |
| 196 |
% \end{itemize} |
| 197 |
% Whereas the first of these points can be considered |
| 198 |
% only a minor nuisance the other one is a real limitation. |
| 199 |
% |
| 200 |
% |
| 201 |
% \DescribeEnv{verbatim} |
| 202 |
% \DescribeEnv{verbatim*} |
| 203 |
% This package file contains a reimplementation of the \texttt{verbatim} |
| 204 |
% and \texttt{verbatim*} environments which overcomes these |
| 205 |
% restrictions. |
| 206 |
% There is, however, one incompatibility between the old and the |
| 207 |
% new implementations of these environments: the old version |
| 208 |
% would treat text on the same line as the |\end{verbatim}| |
| 209 |
% command as if it were on a line by itself. |
| 210 |
% \begin{center} |
| 211 |
% \bf This new version will simply ignore it. |
| 212 |
% \end{center} |
| 213 |
% (This is the price one has to pay for the removal of the old |
| 214 |
% \texttt{verbatim} environment's size limitations.) |
| 215 |
% It will, however, issue a warning message of the form |
| 216 |
% \begin{verbatim} |
| 217 |
%LaTeX warning: Characters dropped after \end{verbatim*}! |
| 218 |
%\end{verbatim} |
| 219 |
% This is not a real problem since this text can easily be put |
| 220 |
% on the next line without affecting the output. |
| 221 |
% |
| 222 |
% This new implementation also solves the second problem mentioned |
| 223 |
% above: it is possible to leave spaces (but \emph{not} begin a new |
| 224 |
% line) between the |\end| and the |{verbatim}| or |{verbatim*}|: |
| 225 |
% \begin{verbatim} |
| 226 |
%\begin {verbatim*} |
| 227 |
% test |
| 228 |
% test |
| 229 |
%\end {verbatim*} |
| 230 |
%\end{verbatim} |
| 231 |
% |
| 232 |
% \DescribeEnv{comment} |
| 233 |
% Additionally we introduce a \texttt{comment} environment, with the |
| 234 |
% effect that the text between |\begin{comment}| and |\end{comment}| |
| 235 |
% is simply ignored, regardless of what it looks like. |
| 236 |
% At first sight this seems to be quite different from the purpose |
| 237 |
% of verbatim listing, but actually the implementation of these two |
| 238 |
% concepts turns out to be very similar. |
| 239 |
% Both rely on the fact that the text between |\begin{...}| and |
| 240 |
% |\end{...}| is read by \TeX{} without interpreting any commands or |
| 241 |
% special characters. |
| 242 |
% The remaining difference between \texttt{verbatim} and |
| 243 |
% \texttt{comment} is only that the text is to be typeset in the |
| 244 |
% first case and to be thrown away in the latter. Note that these |
| 245 |
% environments cannot be nested. |
| 246 |
% |
| 247 |
% \DescribeMacro{\verbatiminput} |
| 248 |
% |\verbatiminput| is a command with one argument that inputs a file |
| 249 |
% verbatim, i.e.\ the command |\verbatiminput{xx.yy}| |
| 250 |
% has the same effect as\\[2pt] |
| 251 |
% \hspace*{\MacroIndent}|\begin{verbatim}|\\ |
| 252 |
% \hspace*{\MacroIndent}\meta{Contents of the file \texttt{xx.yy}}\\ |
| 253 |
% \hspace*{\MacroIndent}|\end{verbatim}|\\[2pt] |
| 254 |
% This command has also a |*|-variant that prints spaces as \verb*+ +. |
| 255 |
% |
| 256 |
% |
| 257 |
% \MaybeStop{} |
| 258 |
% |
| 259 |
% |
| 260 |
% \section{Interfaces for package writers} |
| 261 |
% |
| 262 |
% The \texttt{verbatim} environment of \LaTeXe{} does not |
| 263 |
% offer a good interface to programmers. |
| 264 |
% In contrast, this package provides a simple mechanism to |
| 265 |
% implement similar features, the \texttt{comment} environment |
| 266 |
% implemented here being an example of what can be done and how. |
| 267 |
% |
| 268 |
% |
| 269 |
% \subsection{Simple examples} |
| 270 |
% |
| 271 |
% It is now possible to use the \texttt{verbatim} environment to define |
| 272 |
% environments of your own. |
| 273 |
% E.g., |
| 274 |
%\begin{verbatim} |
| 275 |
% \newenvironment{myverbatim}% |
| 276 |
% {\endgraf\noindent MYVERBATIM:% |
| 277 |
% \endgraf\verbatim}% |
| 278 |
% {\endverbatim} |
| 279 |
%\end{verbatim} |
| 280 |
% can be used afterwards like the \texttt{verbatim} environment, i.e. |
| 281 |
% \begin{verbatim} |
| 282 |
%\begin {myverbatim} |
| 283 |
% test |
| 284 |
% test |
| 285 |
%\end {myverbatim} |
| 286 |
%\end{verbatim} |
| 287 |
% Another way to use it is to write |
| 288 |
% \begin{verbatim} |
| 289 |
%\let\foo=\comment |
| 290 |
%\let\endfoo=\endcomment |
| 291 |
%\end{verbatim} |
| 292 |
% and from that point on environment \texttt{foo} is the same as the |
| 293 |
% comment environment, i.e.\ everything inside its body is ignored. |
| 294 |
% |
| 295 |
% You may also add special commands after the |\verbatim| macro is |
| 296 |
% invoked, e.g. |
| 297 |
%\begin{verbatim} |
| 298 |
%\newenvironment{myverbatim}% |
| 299 |
% {\verbatim\myspecialverbatimsetup}% |
| 300 |
% {\endverbatim} |
| 301 |
%\end{verbatim} |
| 302 |
% though you may want to learn about the hook |\every@verbatim| at |
| 303 |
% this point. |
| 304 |
% \changes{v1.5h}{1995/09/21}{Clarified documentation on use of other |
| 305 |
% environments to define new verbatim-type ones.} |
| 306 |
% However, there are still a number of restrictions: |
| 307 |
% \begin{enumerate} |
| 308 |
% \item |
| 309 |
% You must not use the |\begin| or the |\end| command inside a |
| 310 |
% definition, e.g.~the following two examples will \emph{not} work: |
| 311 |
%\begin{verbatim*} |
| 312 |
%\newenvironment{myverbatim}% |
| 313 |
%{\endgraf\noindent MYVERBATIM:% |
| 314 |
% \endgraf\begin{verbatim}}% |
| 315 |
%{\end{verbatim}} |
| 316 |
%\newenvironment{fred} |
| 317 |
%{\begin{minipage}{30mm}\verbatim} |
| 318 |
%{\endverbatim\end{minipage}} |
| 319 |
%\end{verbatim*} |
| 320 |
% If you try these examples, \TeX{} will report a |
| 321 |
% ``runaway argument'' error. |
| 322 |
% More generally, it is not possible to use |
| 323 |
% |\begin|\ldots\allowbreak|\end| |
| 324 |
% or the related environments in the definition of the new |
| 325 |
% environment. Instead, the correct way to define this environment |
| 326 |
% would be |
| 327 |
% \begin{verbatim*} |
| 328 |
%\newenvironment{fred} |
| 329 |
%{\minipage{30mm}\verbatim} |
| 330 |
%{\endverbatim\endminipage} |
| 331 |
%\end{verbatim*} |
| 332 |
% \item |
| 333 |
% You can\emph{not} use the \texttt{verbatim} environment inside |
| 334 |
% user defined \emph{commands}; e.g., |
| 335 |
% \changes{v1.4g}{1991/11/21}{Corrected wrong position of optional |
| 336 |
% argument to \cs{newcommand}. Discovered by Piet van Oostrum.} |
| 337 |
% \begin{verbatim*} |
| 338 |
%\newcommand{\verbatimfile}[1]% |
| 339 |
% {\begin{verbatim}\input{#1}\end{verbatim}} |
| 340 |
%\end{verbatim*} |
| 341 |
% does \emph{not} work; nor does |
| 342 |
% \begin{verbatim} |
| 343 |
%\newcommand{\verbatimfile}[1]{\verbatim\input{#1}\endverbatim} |
| 344 |
%\end{verbatim} |
| 345 |
% \item The name of the newly defined environment must not contain |
| 346 |
% characters with category code other than $11$ (letter) or |
| 347 |
% $12$ (other), or this will not work. |
| 348 |
% \end{enumerate} |
| 349 |
% |
| 350 |
% |
| 351 |
% \subsection{The interfaces} |
| 352 |
% |
| 353 |
% \DescribeMacro{\verbatim@font} |
| 354 |
% Let us start with the simple things. |
| 355 |
% Sometimes it may be necessary to use a special typeface for your |
| 356 |
% verbatim text, or perhaps the usual computer modern typewriter shape |
| 357 |
% in a reduced size. |
| 358 |
% |
| 359 |
% You may select this by redefining the macro |\verbatim@font|. |
| 360 |
% This macro is executed at the beginning of every verbatim text to |
| 361 |
% select the font shape. |
| 362 |
% Do not use it for other purposes; if you find yourself abusing this |
| 363 |
% you may want to read about the |\every@verbatim| hook below. |
| 364 |
% |
| 365 |
% By default, |\verbatim@font| switches to the typewriter font and |
| 366 |
% disables the ligatures contained therein. |
| 367 |
% |
| 368 |
% |
| 369 |
% \DescribeMacro{\every@verbatim} |
| 370 |
% \DescribeMacro{\addto@hook} |
| 371 |
% There is a hook (i.e.\ a token register) called |\every@verbatim| |
| 372 |
% whose contents are inserted into \TeX's mouth just before every |
| 373 |
% verbatim text. |
| 374 |
% Please use the |\addto@hook| macro to add something to this hook. |
| 375 |
% It is used as follows:\\[2pt] |
| 376 |
% \hspace*{\MacroIndent}|\addto@hook|\meta{name of the hook}^^A |
| 377 |
% |{|\meta{commands to be added}|}| |
| 378 |
% \vspace*{2pt} |
| 379 |
% |
| 380 |
% |
| 381 |
% |
| 382 |
% \DescribeMacro{\verbatim@start} |
| 383 |
% After all specific setup, like switching of category codes, has been |
| 384 |
% done, the |\verbatim@start| macro is called. |
| 385 |
% This starts the main loop of the scanning mechanism implemented here. |
| 386 |
% Any other environment that wants to make use of this feature should |
| 387 |
% execute this macro as its last action. |
| 388 |
% |
| 389 |
% |
| 390 |
% \DescribeMacro{\verbatim@startline} |
| 391 |
% \DescribeMacro{\verbatim@addtoline} |
| 392 |
% \DescribeMacro{\verbatim@processline} |
| 393 |
% \DescribeMacro{\verbatim@finish} |
| 394 |
% These are the things that concern the start of a verbatim |
| 395 |
% environment. |
| 396 |
% Once this (and other) setup has been done, the code in this package |
| 397 |
% reads and processes characters from the input stream in the |
| 398 |
% following way: |
| 399 |
% \begin{enumerate} |
| 400 |
% \item Before the first character of an input line is read, it |
| 401 |
% executes the macro |\verbatim@startline|. |
| 402 |
% \item After some characters have been read, the macro |
| 403 |
% |\verbatim@addtoline| is called with these characters as its only |
| 404 |
% argument. |
| 405 |
% This may happen several times per line (when an |\end| command is |
| 406 |
% present on the line in question). |
| 407 |
% \item When the end of the line is reached, the macro |
| 408 |
% |\verbatim@processline| is called to process the characters that |
| 409 |
% |\verbatim@addtoline| has accumulated. |
| 410 |
% \item Finally, there is the macro |\verbatim@finish| that is called |
| 411 |
% just before the environment is ended by a call to the |\end| |
| 412 |
% macro. |
| 413 |
% \end{enumerate} |
| 414 |
% |
| 415 |
% |
| 416 |
% To make this clear let us consider the standard \texttt{verbatim} |
| 417 |
% environment. |
| 418 |
% In this case the three macros above are defined as follows: |
| 419 |
% \begin{enumerate} |
| 420 |
% \item |\verbatim@startline| clears the character buffer |
| 421 |
% (a token register). |
| 422 |
% \item |\verbatim@addtoline| adds its argument to the character |
| 423 |
% buffer. |
| 424 |
% \item |\verbatim@processline| typesets the characters accumulated |
| 425 |
% in the buffer. |
| 426 |
% \end{enumerate} |
| 427 |
% With this it is very simple to implement the \texttt{comment} |
| 428 |
% environment: |
| 429 |
% in this case |\verbatim@startline| and |\verbatim@processline| are |
| 430 |
% defined to be |
| 431 |
% no-ops whereas |\verbatim@addtoline| discards its argument. |
| 432 |
% |
| 433 |
% |
| 434 |
% Let's use this to define a variant of the |verbatim| |
| 435 |
% environment that prints line numbers in the left margin. |
| 436 |
% Assume that this would be done by a counter called |VerbatimLineNo|. |
| 437 |
% Assuming that this counter was initialized properly by the |
| 438 |
% environment, |\verbatim@processline| would be defined in this case as |
| 439 |
% \begin{verbatim} |
| 440 |
%\def\verbatim@processline{% |
| 441 |
% \addtocounter{VerbatimLineNo}{1}% |
| 442 |
% \leavevmode |
| 443 |
% \llap{\theVerbatimLineNo\ \hskip\@totalleftmargin}% |
| 444 |
% \the\verbatim@line\par} |
| 445 |
%\end{verbatim} |
| 446 |
% |
| 447 |
% A further possibility is to define a variant of the |verbatim| |
| 448 |
% environment that boxes and centers the whole verbatim text. |
| 449 |
% Note that the boxed text should be less than a page, otherwise you |
| 450 |
% have to change this example. |
| 451 |
% |
| 452 |
%\begin{verbatim} |
| 453 |
%\def\verbatimboxed#1{\begingroup |
| 454 |
% \def\verbatim@processline{% |
| 455 |
% {\setbox0=\hbox{\the\verbatim@line}% |
| 456 |
% \hsize=\wd0 |
| 457 |
% \the\verbatim@line\par}}% |
| 458 |
% \setbox0=\vbox{\parskip=0pt\topsep=0pt\partopsep=0pt |
| 459 |
% \verbatiminput{#1}}% |
| 460 |
% \begin{center}\fbox{\box0}\end{center}% |
| 461 |
% \endgroup} |
| 462 |
%\end{verbatim} |
| 463 |
% |
| 464 |
% As a final nontrivial example we describe the definition of an |
| 465 |
% environment called \texttt{verbatimwrite}. |
| 466 |
% It writes all text in its body to a file whose name is |
| 467 |
% given as an argument. |
| 468 |
% We assume that a stream number called |\verbatim@out| has already |
| 469 |
% been reserved by means of the |\newwrite| macro. |
| 470 |
% |
| 471 |
% Let's begin with the definition of the macro |\verbatimwrite|. |
| 472 |
% \begin{verbatim} |
| 473 |
%\def\verbatimwrite#1{% |
| 474 |
%\end{verbatim} |
| 475 |
% First we call |\@bsphack| so that this environment does not influence |
| 476 |
% the spacing. |
| 477 |
% Then we open the file and set the category codes of all special |
| 478 |
% characters: |
| 479 |
% \changes{v1.5t}{2020-07-05}{Added quotes around the filename in |
| 480 |
% order to allow a filename with spaces; also added a space and |
| 481 |
% comment-character to allow for thespace dlimited argument.} |
| 482 |
% \begin{verbatim} |
| 483 |
% \@bsphack |
| 484 |
% \immediate\openout \verbatim@out "#1" % |
| 485 |
% \let\do\@makeother\dospecials |
| 486 |
% \catcode`\^^M\active |
| 487 |
%\end{verbatim} |
| 488 |
% The default definitions of the macros |
| 489 |
% \begin{verbatim} |
| 490 |
% \verbatim@startline |
| 491 |
% \verbatim@addtoline |
| 492 |
% \verbatim@finish |
| 493 |
%\end{verbatim} |
| 494 |
% are also used in this environment. |
| 495 |
% Only the macro |\verbatim@processline| has to be changed before |
| 496 |
% |\verbatim@start| is called: |
| 497 |
% \begin{verbatim} |
| 498 |
% \def\verbatim@processline{% |
| 499 |
% \immediate\write\verbatim@out{\the\verbatim@line}}% |
| 500 |
% \verbatim@start} |
| 501 |
%\end{verbatim} |
| 502 |
% The definition of |\endverbatimwrite| is very simple: |
| 503 |
% we close the stream and call |\@esphack| to get the spacing right. |
| 504 |
% \begin{verbatim} |
| 505 |
%\def\endverbatimwrite{\immediate\closeout\verbatim@out\@esphack} |
| 506 |
%\end{verbatim} |
| 507 |
% |
| 508 |
% \section{The implementation} |
| 509 |
% |
| 510 |
% \let\DescribeMacro\docDescribeMacro |
| 511 |
% \let\DescribeEnv\docDescribeEnv |
| 512 |
% |
| 513 |
% \changes{v1.4e}{1991/07/24}{Avoid reading this file twice.} |
| 514 |
% The very first thing we do is to ensure that this file is not read |
| 515 |
% in twice. To this end we check whether the macro |\verbatim@@@| is |
| 516 |
% defined. If so, we just stop reading this file. The `package' |
| 517 |
% guard here allows most of the code to be excluded when extracting |
| 518 |
% the driver file for testing this package. |
| 519 |
% \begin{macrocode} |
| 520 |
%<*package> |
| 521 |
\NeedsTeXFormat{LaTeX2e} |
| 522 |
\ProvidesPackage{verbatim} |
| 523 |
[2024-01-22 v1.5x LaTeX2e package for verbatim enhancements] |
| 524 |
\@ifundefined{verbatim@@@}{}{\endinput} |
| 525 |
% \end{macrocode} |
| 526 |
% |
| 527 |
% We use a mechanism similar to the one implemented for the |
| 528 |
% |\comment|\ldots\allowbreak|\endcomment| macro in \AmSTeX: |
| 529 |
% We input one line at a time and check if it contains the |\end{...}| |
| 530 |
% tokens. |
| 531 |
% Then we can decide whether we have reached the end of the verbatim |
| 532 |
% text, or must continue. |
| 533 |
% |
| 534 |
% |
| 535 |
% \subsection{Preliminaries} |
| 536 |
% |
| 537 |
% \begin{macro}{\every@verbatim} |
| 538 |
% The hook (i.e.\ token register) |\every@verbatim| |
| 539 |
% is initialized to \meta{empty}. |
| 540 |
% \begin{macrocode} |
| 541 |
\newtoks\every@verbatim |
| 542 |
\every@verbatim={} |
| 543 |
% \end{macrocode} |
| 544 |
% \end{macro} |
| 545 |
% |
| 546 |
% |
| 547 |
% \begin{macro}{\@makeother} |
| 548 |
% \changes{v1.1a}{1989/10/16}{\cs{@makeother} added.} |
| 549 |
% |\@makeother| takes as argument a character and changes |
| 550 |
% its category code to $12$ (other). |
| 551 |
% \begin{macrocode} |
| 552 |
\def\@makeother#1{\catcode`#112\relax} |
| 553 |
% \end{macrocode} |
| 554 |
% \end{macro} |
| 555 |
% |
| 556 |
% |
| 557 |
% \begin{macro}{\@vobeyspaces} |
| 558 |
% \changes{v1.5}{1993/10/11}{Changed definition to not use \cs{gdef}.} |
| 559 |
% \changes{v1.1a}{1989/10/16}{\cs{@vobeyspaces} added.} |
| 560 |
% The macro |\@vobeyspaces| causes spaces in the input |
| 561 |
% to be printed as spaces in the output. |
| 562 |
% \begin{macrocode} |
| 563 |
\begingroup |
| 564 |
\catcode`\ =\active% |
| 565 |
% \end{macrocode} |
| 566 |
% Because space is active we can't indent the following code |
| 567 |
% nicely---we would then get the spaces at the beginning of the |
| 568 |
% line as the third and fourth argument to \cs{@ifl@t@r}. |
| 569 |
% \changes{v1.5v}{2023/11/06}{\cs{@vobeytabs} added when available (gh/1160)} |
| 570 |
% \begin{macrocode} |
| 571 |
\@ifl@t@r\fmtversion{2023-11-01}% |
| 572 |
{\def\x{\def\@vobeyspaces{\catcode`\ \active\let \@xobeysp\@vobeytabs}}}% |
| 573 |
{\def\x{\def\@vobeyspaces{\catcode`\ \active\let \@xobeysp}}}% |
| 574 |
\expandafter\endgroup\x |
| 575 |
% \end{macrocode} |
| 576 |
% \end{macro} |
| 577 |
% |
| 578 |
% |
| 579 |
% \begin{macro}{\@xobeysp} |
| 580 |
% \changes{v1.1a}{1989/10/16}{\cs{@xobeysp} added.} |
| 581 |
% The macro |\@xobeysp| produces exactly one space in |
| 582 |
% the output, protected against breaking just before it. |
| 583 |
% (|\@M| is an abbreviation for the number $10000$.) |
| 584 |
% \begin{macrocode} |
| 585 |
\def\@xobeysp{\leavevmode\penalty\@M\ } |
| 586 |
% \end{macrocode} |
| 587 |
% \end{macro} |
| 588 |
% |
| 589 |
% |
| 590 |
% \begin{macro}{\verbatim@line} |
| 591 |
% \changes{v1.2d}{1989/11/29}{Introduced token register |
| 592 |
% \cs{verbatim@line}.} |
| 593 |
% We use a newly defined token register called |\verbatim@line| |
| 594 |
% that will be used as the character buffer. |
| 595 |
% \begin{macrocode} |
| 596 |
\newtoks\verbatim@line |
| 597 |
% \end{macrocode} |
| 598 |
% \end{macro} |
| 599 |
% |
| 600 |
% The following four macros are defined globally in a way suitable for |
| 601 |
% the \texttt{verbatim} and \texttt{verbatim*} environments. |
| 602 |
% \begin{macro}{\verbatim@startline} |
| 603 |
% \begin{macro}{\verbatim@addtoline} |
| 604 |
% \begin{macro}{\verbatim@processline} |
| 605 |
% |\verbatim@startline| initializes processing of a line |
| 606 |
% by emptying the character buffer (|\verbatim@line|). |
| 607 |
% \begin{macrocode} |
| 608 |
\def\verbatim@startline{\verbatim@line{}} |
| 609 |
% \end{macrocode} |
| 610 |
% |\verbatim@addtoline| adds the tokens in its argument |
| 611 |
% to our buffer register |\verbatim@line| without expanding |
| 612 |
% them. |
| 613 |
% \begin{macrocode} |
| 614 |
\def\verbatim@addtoline#1{% |
| 615 |
\verbatim@line\expandafter{\the\verbatim@line#1}} |
| 616 |
% \end{macrocode} |
| 617 |
% Processing a line inside a \texttt{verbatim} or \texttt{verbatim*} |
| 618 |
% environment means printing it. |
| 619 |
% \changes{v1.2c}{1989/10/31}{Changed \cs{@@par} to \cs{par} in |
| 620 |
% \cs{verbatim@processline}. Removed \cs{leavevmode} and \cs{null} |
| 621 |
% (i.e.\ the empty \cs{hbox}).} |
| 622 |
% Ending the line means that we have to begin a new paragraph. |
| 623 |
% We use |\par| for this purpose. Note that |\par| |
| 624 |
% is redefined in |\@verbatim| to force \TeX{} into horizontal |
| 625 |
% mode and to insert an empty box so that empty lines in the input |
| 626 |
% do appear in the output. |
| 627 |
% \changes{v1.2f}{1990/01/31}{\cs{verbatim@startline} removed.} |
| 628 |
% \begin{macrocode} |
| 629 |
\def\verbatim@processline{\the\verbatim@line\par} |
| 630 |
% \end{macrocode} |
| 631 |
% \end{macro} |
| 632 |
% \end{macro} |
| 633 |
% \end{macro} |
| 634 |
% |
| 635 |
% \begin{macro}{\verbatim@finish} |
| 636 |
% As a default, |\verbatim@finish| processes the remaining |
| 637 |
% characters. |
| 638 |
% When this macro is called we are facing the following problem: |
| 639 |
% when the |\end{verbatim}| |
| 640 |
% command is encountered |\verbatim@processline| is called |
| 641 |
% to process the characters preceding the command on the same |
| 642 |
% line. If there are none, an empty line would be output if we |
| 643 |
% did not check for this case. |
| 644 |
% |
| 645 |
% If the line is empty |\the\verbatim@line| expands to |
| 646 |
% nothing. To test this we use a trick similar to that on p.\ 376 |
| 647 |
% of the \TeX{}book, but with |$|\ldots|$| instead of |
| 648 |
% the |!| tokens. These |$| tokens can never have the same |
| 649 |
% category code as a |$| token that might possibly appear in the |
| 650 |
% token register |\verbatim@line|, as such a token will always have |
| 651 |
% been read with category code $12$ (other). |
| 652 |
% Note that |\ifcat| expands the following tokens so that |
| 653 |
% |\the\verbatim@line| is replaced by the accumulated |
| 654 |
% characters |
| 655 |
% \changes{v1.2d}{1989/11/29}{Changed \cs{ifx} to \cs{ifcat} test.} |
| 656 |
% \changes{v1.1b}{1989/10/18}{Corrected bug in if test (found by CRo).} |
| 657 |
% \begin{macrocode} |
| 658 |
\def\verbatim@finish{\ifcat$\the\verbatim@line$\else |
| 659 |
\verbatim@processline\fi} |
| 660 |
% \end{macrocode} |
| 661 |
% \end{macro} |
| 662 |
% |
| 663 |
% |
| 664 |
% \subsection{The \texttt{verbatim} and \texttt{verbatim*} environments} |
| 665 |
% |
| 666 |
% \begin{macro}{\verbatim@font} |
| 667 |
% \changes{v1.2f}{1990/01/31}{\cs{@lquote} macro removed.} |
| 668 |
% \changes{v1.1b}{1989/10/18}{\cs{@noligs} removed. Code inserted |
| 669 |
% directly into \cs{verbatim@font}.} |
| 670 |
% \changes{v1.1a}{1989/10/16}{\cs{verbatim@font} added.} |
| 671 |
% \changes{v1.1a}{1989/10/16}{\cs{@noligs} added.} |
| 672 |
% \changes{v1.1a}{1989/10/16}{\cs{@lquote} added.} |
| 673 |
% We start by defining the macro |\verbatim@font| that is |
| 674 |
% to select the font and to set font-dependent parameters. |
| 675 |
% Then we expand |\@noligs| (defined in the \LaTeXe{} kernel). Among |
| 676 |
% possibly other things, it will go through |\verbatim@nolig@list| |
| 677 |
% to avoid certain ligatures. |
| 678 |
% |\verbatim@nolig@list| is a macro defined in the \LaTeXe{} kernel |
| 679 |
% to expand to |
| 680 |
% \begin{verbatim} |
| 681 |
% \do\`\do\<\do\>\do\,\do\'\do\- |
| 682 |
%\end{verbatim} |
| 683 |
% All the characters in this list can be part of a ligature in some |
| 684 |
% font or other. |
| 685 |
% \changes{v1.2f}{1990/01/31}{\cs{@lquote} macro removed.} |
| 686 |
% \changes{v1.4c}{1990/10/18}{Added \cs{leavevmode}.} |
| 687 |
% \changes{v1.4k}{1992/07/13}{Replaced Blank after $96$ by \cs{relax}. |
| 688 |
% (Proposed by Dan Dill.)} |
| 689 |
% \changes{v1.5}{1993/10/11}{Definition changed according to new code |
| 690 |
% in latex.tex and to avoid global definition.} |
| 691 |
% \changes{v1.5c}{1994/02/07}{Changed to use new font switching |
| 692 |
% commands.} |
| 693 |
% \changes{v1.5m}{2000/01/07}{Disable hyphenation even if the font |
| 694 |
% allows it.} |
| 695 |
% \changes{v1.5q}{2003/08/22}{Use \cs{@noligs}, as it is by now properly |
| 696 |
% defined in the \LaTeXe{} kernel.} |
| 697 |
% \begin{macrocode} |
| 698 |
\def\verbatim@font{\normalfont\ttfamily |
| 699 |
\hyphenchar\font\m@ne |
| 700 |
\@noligs} |
| 701 |
% \end{macrocode} |
| 702 |
% \end{macro} |
| 703 |
% |
| 704 |
% |
| 705 |
% \begin{macro}{\@verbatim} |
| 706 |
% \changes{v1.1a}{1989/10/16}{\cs{@verbatim} added.} |
| 707 |
% The macro |\@verbatim| sets up things properly. |
| 708 |
% First of all, the tokens of the |\every@verbatim| hook |
| 709 |
% are inserted. |
| 710 |
% Then a \texttt{trivlist} environment is started and its first |
| 711 |
% |\item| command inserted. |
| 712 |
% Each line of the \texttt{verbatim} or \texttt{verbatim*} |
| 713 |
% environment will be treated as a separate paragraph. |
| 714 |
% \changes{v1.2e}{1990/01/15}{Added \cs{every@verbatim} hook.} |
| 715 |
% \changes{v1.5b}{1994/01/24}{Removed optional argument of \cs{item}.} |
| 716 |
% \begin{macrocode} |
| 717 |
\def\@verbatim{\the\every@verbatim |
| 718 |
\trivlist \item \relax |
| 719 |
% \end{macrocode} |
| 720 |
% \changes{v1.5b}{1994/01/24}{Set \texttt{@inlabel} switch to false.} |
| 721 |
% \changes{v1.5f}{1994/10/25}{Removed setting of \texttt{@inlabel} |
| 722 |
% switch again.} |
| 723 |
% \changes{v1.3c}{1990/02/26}{Removed extra vertical space. |
| 724 |
% Suggested by Frank Mittelbach.} |
| 725 |
% \changes{v1.5h}{1995/09/21}{Added the space again, since it is |
| 726 |
% necessary for correct vertical spacing if \texttt{verbatim} |
| 727 |
% is nested inside \texttt{quote}.} |
| 728 |
% The following extra vertical space is for compatibility with the |
| 729 |
% \LaTeX{} kernel: otherwise, using the |verbatim| package changes |
| 730 |
% the vertical spacing of a |verbatim| environment nested within a |
| 731 |
% |quote| environment. |
| 732 |
% \begin{macrocode} |
| 733 |
\if@minipage\else\vskip\parskip\fi |
| 734 |
% \end{macrocode} |
| 735 |
% \changes{v1.4k}{1992/07/13}{Added setting for |
| 736 |
% \cs{@beginparpenalty}. Suggested by Frank Mittelbach.} |
| 737 |
% The paragraph parameters are set appropriately: |
| 738 |
% the penalty at the beginning of the environment, |
| 739 |
% left and right margins, paragraph indentation, the glue to |
| 740 |
% fill the last line, and the vertical space between paragraphs. |
| 741 |
% The latter space has to be zero since we do not want to add |
| 742 |
% extra space between lines. |
| 743 |
% \begin{macrocode} |
| 744 |
\@beginparpenalty \predisplaypenalty |
| 745 |
\leftskip\@totalleftmargin\rightskip\z@ |
| 746 |
\parindent\z@\parfillskip\@flushglue\parskip\z@ |
| 747 |
% \end{macrocode} |
| 748 |
% \changes{v1.1b}{1989/10/18}{Added resetting of \cs{parshape} |
| 749 |
% if at beginning of a list. |
| 750 |
% (Problem pointed out by Chris Rowley.)} |
| 751 |
% There's one point to make here: |
| 752 |
% the \texttt{list} environment uses \TeX's |\parshape| |
| 753 |
% primitive to get a special indentation for the first line |
| 754 |
% of the list. |
| 755 |
% If the list begins with a \texttt{verbatim} environment |
| 756 |
% this |\parshape| is still in effect. |
| 757 |
% Therefore we have to reset this internal parameter explicitly. |
| 758 |
% We could do this by assigning $0$ to |\parshape|. |
| 759 |
% However, there is a simpler way to achieve this: |
| 760 |
% we simply tell \TeX{} to start a new paragraph. |
| 761 |
% As is explained on p.~103 of the \TeX{}book, this resets |
| 762 |
% |\parshape| to zero. |
| 763 |
% \changes{v1.1c}{1989/10/19}{Replaced explicit resetting of |
| 764 |
% \cs{parshape} by \cs{@@par}.} |
| 765 |
% \begin{macrocode} |
| 766 |
\@@par |
| 767 |
% \end{macrocode} |
| 768 |
% We now ensure that |\par| has the correct definition, |
| 769 |
% namely to force \TeX{} into horizontal mode |
| 770 |
% and to include an empty box. |
| 771 |
% This is to ensure that empty lines do appear in the output. |
| 772 |
% Afterwards, we insert the |\interlinepenalty| since \TeX{} |
| 773 |
% does not add a penalty between paragraphs (here: lines) |
| 774 |
% by its own initiative. Otherwise a |verbatim| environment |
| 775 |
% could be broken across pages even if a |\samepage| |
| 776 |
% declaration were present. |
| 777 |
% |
| 778 |
% However, in a top-aligned minipage, this will result in an extra |
| 779 |
% empty line added at the top. Therefore, a slightly more |
| 780 |
% complicated construct is necessary. |
| 781 |
% One of the important things here is the inclusion of |
| 782 |
% |\leavevmode| as the first macro in the first line, for example, |
| 783 |
% a blank verbatim line is the first thing in a list item. |
| 784 |
% \changes{v1.2c}{1989/10/31}{Definition of \cs{par} added. |
| 785 |
% Ensures identical behaviour for |
| 786 |
% verbatim and \cs{verbatiminput}. |
| 787 |
% Problem pointed out by Chris.} |
| 788 |
% \changes{v1.4d}{1991/04/24}{\cs{penalty}\cs{interlinepenalty} added. |
| 789 |
% Necessary to avoid page breaks in |
| 790 |
% the scope of a \cs{samepage} declaration.} |
| 791 |
% \changes{v1.5b}{1994/01/24}{Improved definition of \cs{par} to work |
| 792 |
% under all circumstances.} |
| 793 |
% \changes{v1.5f}{1994/10/25}{\cs{leavevmode} added for first line.} |
| 794 |
% \begin{macrocode} |
| 795 |
\def\par{% |
| 796 |
\if@tempswa |
| 797 |
\leavevmode\null\@@par\penalty\interlinepenalty |
| 798 |
\else |
| 799 |
\@tempswatrue |
| 800 |
\ifhmode\@@par\penalty\interlinepenalty\fi |
| 801 |
\fi}% |
| 802 |
% \end{macrocode} |
| 803 |
% But to avoid an error message when the environment |
| 804 |
% doesn't contain any text, we redefine |\@noitemerr| |
| 805 |
% which will in this case be called by |\endtrivlist|. |
| 806 |
% \changes{v1.4j}{1992/06/30}{Introduced warning instead of error |
| 807 |
% for empty body of verbatim text. |
| 808 |
% Suggested by Nelson Beebe.} |
| 809 |
% \begin{macrocode} |
| 810 |
\def\@noitemerr{\@warning{No verbatim text}}% |
| 811 |
% \end{macrocode} |
| 812 |
% Now we call |\obeylines| to make the end of line character |
| 813 |
% active. |
| 814 |
% \begin{macrocode} |
| 815 |
\obeylines |
| 816 |
% \end{macrocode} |
| 817 |
% The category code of all special characters is changed, |
| 818 |
% to $12$ (other). |
| 819 |
% \changes{v1.5i}{1996/06/04}{Moved \cs{verbatim@font} after |
| 820 |
% \cs{dospecials}.} |
| 821 |
% \begin{macrocode} |
| 822 |
\let\do\@makeother \dospecials |
| 823 |
% \end{macrocode} |
| 824 |
% We switch to the font to be used. |
| 825 |
% \begin{macrocode} |
| 826 |
\verbatim@font |
| 827 |
% \end{macrocode} |
| 828 |
% To avoid a breakpoint after the labels box, we remove the penalty |
| 829 |
% put there by the list macros: another use of |\unpenalty|! |
| 830 |
% \changes{v1.5f}{1994/10/25}{Change to \cs{everypar} added.} |
| 831 |
% \begin{macrocode} |
| 832 |
\everypar \expandafter{\the\everypar \unpenalty}} |
| 833 |
% \end{macrocode} |
| 834 |
% \end{macro} |
| 835 |
% |
| 836 |
% |
| 837 |
% \begin{macro}{\verbatim} |
| 838 |
% \begin{macro}{\verbatim*} |
| 839 |
% Now we define the toplevel macros. |
| 840 |
% |\verbatim| is slightly changed: |
| 841 |
% after setting up things properly it calls |
| 842 |
% |\verbatim@start|. |
| 843 |
% \changes{v1.5l}{1999/12/14}{Added \cs{begingroup} for cases where |
| 844 |
% \cs{verbatim} is used directly, rather than in \cs{begin}: see |
| 845 |
% pr/3115.} |
| 846 |
% This is done inside a group, so that |\verbatim| can be used |
| 847 |
% directly, without |\begin|. |
| 848 |
% \begin{macrocode} |
| 849 |
\def\verbatim{\begingroup\@verbatim \frenchspacing\@vobeyspaces |
| 850 |
\verbatim@start} |
| 851 |
% \end{macrocode} |
| 852 |
% |\verbatim*| is defined accordingly. |
| 853 |
% \begin{macrocode} |
| 854 |
\@namedef{verbatim*}{\begingroup\@verbatim |
| 855 |
% \end{macrocode} |
| 856 |
% |
| 857 |
% \changes{v1.5r}{2019/11/10}{Support kernel \cs{verbvisiblespace} (gh/212)} |
| 858 |
% \begin{macrocode} |
| 859 |
\@setupverbvisiblespace\@vobeyspaces |
| 860 |
\verbatim@start} |
| 861 |
% \end{macrocode} |
| 862 |
% \end{macro} |
| 863 |
% \end{macro} |
| 864 |
% |
| 865 |
% \begin{macro}{\endverbatim} |
| 866 |
% \begin{macro}{\endverbatim*} |
| 867 |
% To end the \texttt{verbatim} and \texttt{verbatim*} |
| 868 |
% environments it is only necessary to finish the |
| 869 |
% \texttt{trivlist} environment started in |\@verbatim| and |
| 870 |
% close the corresponding group. |
| 871 |
% \changes{v1.5l}{1999/12/14}{Added \cs{endgroup} for cases where |
| 872 |
% \cs{endverbatim} is used directly, rather than in \cs{end}: see |
| 873 |
% pr/3115.} |
| 874 |
% \changes{v1.5n}{2000/08/03}{Added \cs{@endpetrue}: needed when |
| 875 |
% faking such a \cs{end} (pr/3234).} |
| 876 |
% \changes{v1.5o}{2000/08/23}{Changed \cs{@endpetrue} to \cs{@doendpe}: |
| 877 |
% see (pr/3234).} |
| 878 |
% \begin{macrocode} |
| 879 |
\def\endverbatim{\endtrivlist\endgroup\@doendpe} |
| 880 |
\expandafter\let\csname endverbatim*\endcsname =\endverbatim |
| 881 |
% \end{macrocode} |
| 882 |
% \end{macro} |
| 883 |
% \end{macro} |
| 884 |
% |
| 885 |
% |
| 886 |
% \subsection{The \texttt{comment} environment} |
| 887 |
% |
| 888 |
% \begin{macro}{\comment} |
| 889 |
% \begin{macro}{\endcomment} |
| 890 |
% \changes{v1.1c}{1989/10/19}{Added \cs{@bsphack}/\cs{@esphack} to the |
| 891 |
% \texttt{comment} environment. Suggested by Chris Rowley.} |
| 892 |
% The |\comment| macro is similar to |\verbatim*|. |
| 893 |
% However, we do not need to switch fonts or set special |
| 894 |
% formatting parameters such as |\parindent| or |\parskip|. |
| 895 |
% We need only set the category code of all special characters |
| 896 |
% to $12$ (other) and that of |^^M| (the end of line character) |
| 897 |
% to $13$ (active). |
| 898 |
% The latter is needed for macro parameter delimiter matching in |
| 899 |
% the internal macros defined below. |
| 900 |
% In contrast to the default definitions used by the |
| 901 |
% |\verbatim| and |\verbatim*| macros, |
| 902 |
% we define |\verbatim@addtoline| to throw away its argument |
| 903 |
% and |\verbatim@processline|, |\verbatim@startline|, |
| 904 |
% and |\verbatim@finish| to act as no-ops. |
| 905 |
% Then we call |\verbatim@|. |
| 906 |
% But the first thing we do is to call |\@bsphack| so that |
| 907 |
% this environment has no influence whatsoever upon the spacing. |
| 908 |
% \changes{v1.1c}{1989/10/19}{Changed \cs{verbatim@start} to |
| 909 |
% \cs{verbatim@}. Suggested by Chris Rowley.} |
| 910 |
% \changes{v1.1c}{1989/10/19}{\cs{verbatim@startline} and |
| 911 |
% \cs{verbatim@finish} are now |
| 912 |
% also redefined to do nothing.} |
| 913 |
% \begin{macrocode} |
| 914 |
\def\comment{\@bsphack |
| 915 |
\let\do\@makeother\dospecials\catcode`\^^M\active |
| 916 |
\let\verbatim@startline\relax |
| 917 |
\let\verbatim@addtoline\@gobble |
| 918 |
\let\verbatim@processline\relax |
| 919 |
\let\verbatim@finish\relax |
| 920 |
\verbatim@} |
| 921 |
% \end{macrocode} |
| 922 |
% |\endcomment| is very simple: it only calls |
| 923 |
% |\@esphack| to take care of the spacing. |
| 924 |
% The |\end| macro closes the group and therefore takes care |
| 925 |
% of restoring everything we changed. |
| 926 |
% \begin{macrocode} |
| 927 |
\let\endcomment=\@esphack |
| 928 |
% \end{macrocode} |
| 929 |
% \end{macro} |
| 930 |
% \end{macro} |
| 931 |
% |
| 932 |
% |
| 933 |
% |
| 934 |
% \subsection{The main loop} |
| 935 |
% |
| 936 |
% Here comes the tricky part: |
| 937 |
% During the definition of the macros we need to use the special |
| 938 |
% characters |\|, |{|, and |}| not only with their |
| 939 |
% normal category codes, |
| 940 |
% but also with category code $12$ (other). |
| 941 |
% We achieve this by the following trick: |
| 942 |
% first we tell \TeX{} that |\|, |{|, and |}| |
| 943 |
% are the lowercase versions of |!|, |[|, and |]|. |
| 944 |
% Then we replace every occurrence of |\|, |{|, and |}| |
| 945 |
% that should be read with category code $12$ by |!|, |[|, |
| 946 |
% and |]|, respectively, |
| 947 |
% and give the whole list of tokens to |\lowercase|, |
| 948 |
% knowing that category codes are not altered by this primitive! |
| 949 |
% |
| 950 |
% But first we have ensure that |
| 951 |
% |!|, |[|, and |]| themselves have |
| 952 |
% the correct category code! |
| 953 |
% \changes{v1.3b}{1990/02/07}{Introduced \cs{vrb@catcodes} instead |
| 954 |
% of explicit setting of category codes.} |
| 955 |
% To allow special settings of these codes we hide their setting in |
| 956 |
% the macro |\vrb@catcodes|. If it is already defined our new |
| 957 |
% definition is skipped. |
| 958 |
% \begin{macrocode} |
| 959 |
\@ifundefined{vrb@catcodes}% |
| 960 |
{\def\vrb@catcodes{% |
| 961 |
\catcode`\!12\catcode`\[12\catcode`\]12}}{} |
| 962 |
% \end{macrocode} |
| 963 |
% This trick allows us to use this code for applications where other |
| 964 |
% category codes are in effect. |
| 965 |
% |
| 966 |
% We start a group to keep the category code changes local. |
| 967 |
% \begin{macrocode} |
| 968 |
\begingroup |
| 969 |
\vrb@catcodes |
| 970 |
\lccode`\!=`\\ \lccode`\[=`\{ \lccode`\]=`\} |
| 971 |
% \end{macrocode} |
| 972 |
% \changes{v1.2f}{1990/01/31}{Code for TABs removed.} |
| 973 |
% We also need the end-of-line character |^^M|, |
| 974 |
% as an active character. |
| 975 |
% If we were to simply write |\catcode`\^^M=\active| |
| 976 |
% then we would get an unwanted active end of line character |
| 977 |
% at the end of every line of the following macro definitions. |
| 978 |
% Therefore we use the same trick as above: |
| 979 |
% we write a tilde |~| instead of |^^M| and |
| 980 |
% pretend that the |
| 981 |
% latter is the lowercase variant of the former. |
| 982 |
% Thus we have to ensure now that the tilde character has |
| 983 |
% category code $13$ (active). |
| 984 |
% \begin{macrocode} |
| 985 |
\catcode`\~=\active \lccode`\~=`\^^M |
| 986 |
% \end{macrocode} |
| 987 |
% The use of the |\lowercase| primitive leads to one problem: |
| 988 |
% the uppercase character `|C|' needs to be used in the |
| 989 |
% code below and its case must be preserved. |
| 990 |
% So we add the command: |
| 991 |
% \begin{macrocode} |
| 992 |
\lccode`\C=`\C |
| 993 |
% \end{macrocode} |
| 994 |
% Now we start the token list passed to |\lowercase|. |
| 995 |
% We use the following little trick (proposed by Bernd Raichle): |
| 996 |
% The very first token in the token list we give to |\lowercase| is |
| 997 |
% the |\endgroup| primitive. This means that it is processed by |
| 998 |
% \TeX{} immediately after |\lowercase| has finished its operation, |
| 999 |
% thus ending the group started by |\begingroup| above. This avoids |
| 1000 |
% the global definition of all macros. |
| 1001 |
% \begin{macrocode} |
| 1002 |
\lowercase{\endgroup |
| 1003 |
% \end{macrocode} |
| 1004 |
% \begin{macro}{\verbatim@start} |
| 1005 |
% The purpose of |\verbatim@start| is to check whether there |
| 1006 |
% are any characters on the same line as the |\begin{verbatim}| |
| 1007 |
% and to pretend that they were on a line by themselves. |
| 1008 |
% On the other hand, if there are no characters remaining |
| 1009 |
% on the current line we shall just find an end of line character. |
| 1010 |
% |\verbatim@start| performs its task by first grabbing the |
| 1011 |
% following character (its argument). |
| 1012 |
% This argument is then compared to an active |^^M|, |
| 1013 |
% the end of line character. |
| 1014 |
% \begin{macrocode} |
| 1015 |
\def\verbatim@start#1{% |
| 1016 |
\verbatim@startline |
| 1017 |
\if\noexpand#1\noexpand~% |
| 1018 |
% \end{macrocode} |
| 1019 |
% If this is true we transfer control to |\verbatim@| |
| 1020 |
% to process the next line. We use |
| 1021 |
% |\next| as the macro which will continue the work. |
| 1022 |
% \begin{macrocode} |
| 1023 |
\let\next\verbatim@ |
| 1024 |
% \end{macrocode} |
| 1025 |
% Otherwise, we define |\next| to expand to a call |
| 1026 |
% to |\verbatim@| followed by the character just |
| 1027 |
% read so that it is reinserted into the text. |
| 1028 |
% This means that those characters remaining on this line |
| 1029 |
% are handled as if they formed a line by themselves. |
| 1030 |
% \begin{macrocode} |
| 1031 |
\else \def\next{\verbatim@#1}\fi |
| 1032 |
% \end{macrocode} |
| 1033 |
% Finally we call |\next|. |
| 1034 |
% \begin{macrocode} |
| 1035 |
\next}% |
| 1036 |
% \end{macrocode} |
| 1037 |
% \end{macro} |
| 1038 |
% |
| 1039 |
% \begin{macro}{\verbatim@} |
| 1040 |
% The three macros |\verbatim@|, |\verbatim@@|, |
| 1041 |
% and |\verbatim@@@| form the ``main loop'' of the |
| 1042 |
% \texttt{verbatim} environment. |
| 1043 |
% The purpose of |\verbatim@| is to read exactly one line |
| 1044 |
% of input. |
| 1045 |
% |\verbatim@@| and |\verbatim@@@| work together to |
| 1046 |
% find out whether the four characters |
| 1047 |
% |\end| (all with category code $12$ (other)) occur in that |
| 1048 |
% line. |
| 1049 |
% If so, |\verbatim@@@| will call |
| 1050 |
% |\verbatim@test| to check whether this |\end| is |
| 1051 |
% part of |\end{verbatim}| and will terminate the environment |
| 1052 |
% if this is the case. |
| 1053 |
% Otherwise we continue as if nothing had happened. |
| 1054 |
% So let's have a look at the definition of |\verbatim@|: |
| 1055 |
% \changes{v1.1a}{1989/10/16}{Replaced \cs{verbatim@@@} by \cs{@nil}.} |
| 1056 |
% \begin{macrocode} |
| 1057 |
\def\verbatim@#1~{\verbatim@@#1!end\@nil}% |
| 1058 |
% \end{macrocode} |
| 1059 |
% Note that the |!| character will have been replaced by a |
| 1060 |
% |\| with category code $12$ (other) by the |\lowercase| |
| 1061 |
% primitive governing this code before the definition of this |
| 1062 |
% macro actually takes place. |
| 1063 |
% That means that |
| 1064 |
% it takes the line, puts |\end| (four character tokens) |
| 1065 |
% and |\@nil| (one control sequence token) as a |
| 1066 |
% delimiter behind it, and |
| 1067 |
% then calls |\verbatim@@|. |
| 1068 |
% \end{macro} |
| 1069 |
% |
| 1070 |
% \begin{macro}{\verbatim@@} |
| 1071 |
% |\verbatim@@| takes everything up to the next occurrence of |
| 1072 |
% the four characters |\end| as its argument. |
| 1073 |
% \begin{macrocode} |
| 1074 |
\def\verbatim@@#1!end{% |
| 1075 |
% \end{macrocode} |
| 1076 |
% That means: if they do not occur in the original line, then |
| 1077 |
% argument |#1| is the |
| 1078 |
% whole input line, and |\@nil| is the next token |
| 1079 |
% to be processed. |
| 1080 |
% However, if the four characters |\end| are part of the |
| 1081 |
% original line, then |
| 1082 |
% |#1| consists of the characters in front of |\end|, |
| 1083 |
% and the next token is the following character (always remember |
| 1084 |
% that the line was lengthened by five tokens). |
| 1085 |
% Whatever |#1| may be, it is verbatim text, |
| 1086 |
% so |#1| is added to the line currently built. |
| 1087 |
% \begin{macrocode} |
| 1088 |
\verbatim@addtoline{#1}% |
| 1089 |
% \end{macrocode} |
| 1090 |
% The next token in the input stream |
| 1091 |
% is of special interest to us. |
| 1092 |
% Therefore |\futurelet| defines |\next| to be equal |
| 1093 |
% to it before calling |\verbatim@@@|. |
| 1094 |
% \begin{macrocode} |
| 1095 |
\futurelet\next\verbatim@@@}% |
| 1096 |
% \end{macrocode} |
| 1097 |
% \end{macro} |
| 1098 |
% |
| 1099 |
% \begin{macro}{\verbatim@@@} |
| 1100 |
% \changes{v1.1a}{1989/10/16}{Replaced \cs{verbatim@@@} by |
| 1101 |
% \cs{@nil} where used as delimiter.} |
| 1102 |
% |\verbatim@@@| will now read the rest of the tokens on |
| 1103 |
% the current line, |
| 1104 |
% up to the final |\@nil| token. |
| 1105 |
% \begin{macrocode} |
| 1106 |
\def\verbatim@@@#1\@nil{% |
| 1107 |
% \end{macrocode} |
| 1108 |
% If the first of the above two cases occurred, i.e.\ no |
| 1109 |
% |\end| characters were on that line, |#1| is empty |
| 1110 |
% and |\next| is equal to |\@nil|. |
| 1111 |
% This is easily checked. |
| 1112 |
% \begin{macrocode} |
| 1113 |
\ifx\next\@nil |
| 1114 |
% \end{macrocode} |
| 1115 |
% If so, this was a simple line. |
| 1116 |
% We finish it by processing the line we accumulated so far. |
| 1117 |
% Then we prepare to read the next line. |
| 1118 |
% \changes{v1.2f}{1990/01/31}{Added \cs{verbatim@startline}.} |
| 1119 |
% \begin{macrocode} |
| 1120 |
\verbatim@processline |
| 1121 |
\verbatim@startline |
| 1122 |
\let\next\verbatim@ |
| 1123 |
% \end{macrocode} |
| 1124 |
% Otherwise we have to check what follows these |\end| |
| 1125 |
% tokens. |
| 1126 |
% \begin{macrocode} |
| 1127 |
\else |
| 1128 |
% \end{macrocode} |
| 1129 |
% Before we continue, it's a good idea to stop for a moment |
| 1130 |
% and remember where we are: |
| 1131 |
% We have just read the four character tokens |\end| |
| 1132 |
% and must now check whether the name of the environment (surrounded |
| 1133 |
% by braces) follows. |
| 1134 |
% To this end we define a macro called |\@tempa| |
| 1135 |
% that reads exactly one character and decides what to do next. |
| 1136 |
% This macro should do the following: skip spaces until |
| 1137 |
% it encounters either a left brace or the end of the line. |
| 1138 |
% But it is important to remember which characters are skipped. |
| 1139 |
% The |\end|\meta{optional spaces}|{| characters |
| 1140 |
% may be part of the verbatim text, i.e.\ these characters |
| 1141 |
% must be printed. |
| 1142 |
% |
| 1143 |
% Assume for example that the current line contains |
| 1144 |
% \begin{verbatim*} |
| 1145 |
% \end {AVeryLongEnvironmentName} |
| 1146 |
%\end{verbatim*} |
| 1147 |
% As we shall soon see, the scanning mechanism implemented here |
| 1148 |
% will not find out that this is text to be printed until |
| 1149 |
% it has read the right brace. |
| 1150 |
% Therefore we need a way to accumulate the characters read |
| 1151 |
% so that we can reinsert them if necessary. |
| 1152 |
% The token register |\@temptokena| is used for this purpose. |
| 1153 |
% |
| 1154 |
% Before we do this we have to get rid of the superfluous |
| 1155 |
% |\end| tokens at the end of the line. |
| 1156 |
% \changes{v1.4j}{1992/06/30}{Removed use of \cs{toks@}. Suggested by |
| 1157 |
% Bernd Raichle.} |
| 1158 |
% To this end we define a temporary macro whose argument |
| 1159 |
% is delimited by |\end\@nil| (four character tokens |
| 1160 |
% and one control sequence token) to be used below |
| 1161 |
% on the rest of the line, after appending a |\@nil| token to it. |
| 1162 |
% (Note that this token can never appear in |#1|.) |
| 1163 |
% We use the following definition of |
| 1164 |
% |\@tempa| to get the rest of the line (after the first |
| 1165 |
% |\end|). |
| 1166 |
% \begin{macrocode} |
| 1167 |
\def\@tempa##1!end\@nil{##1}% |
| 1168 |
% \end{macrocode} |
| 1169 |
% We mentioned already that we use token register |
| 1170 |
% |\@temptokena| |
| 1171 |
% to remember the characters we skip, in case we need them again. |
| 1172 |
% We initialize this with the |\end| we have thrown away |
| 1173 |
% in the call to |\@tempa|. |
| 1174 |
% \begin{macrocode} |
| 1175 |
\@temptokena{!end}% |
| 1176 |
% \end{macrocode} |
| 1177 |
% We shall now call |\verbatim@test| |
| 1178 |
% to process the characters |
| 1179 |
% remaining on the current line. |
| 1180 |
% But wait a moment: we cannot simply call this macro |
| 1181 |
% since we have already read the whole line. |
| 1182 |
% Therefore we have to first expand the macro |\@tempa| to insert |
| 1183 |
% them again after the |\verbatim@test| token. |
| 1184 |
% A |^^M| character is appended to denote the end of the line. |
| 1185 |
% (Remember that this character comes disguised as a tilde.) |
| 1186 |
% \changes{v1.2}{1989/10/20}{Taken local definition of \cs{@tempa} out |
| 1187 |
% of \cs{verbatim@@@} and introduced |
| 1188 |
% \cs{verbatim@test} instead.} |
| 1189 |
% \begin{macrocode} |
| 1190 |
\def\next{\expandafter\verbatim@test\@tempa#1\@nil~}% |
| 1191 |
% \end{macrocode} |
| 1192 |
% That's almost all, but we still have to |
| 1193 |
% now call |\next| to do the work. |
| 1194 |
% \begin{macrocode} |
| 1195 |
\fi \next}% |
| 1196 |
% \end{macrocode} |
| 1197 |
% \end{macro} |
| 1198 |
% |
| 1199 |
% |
| 1200 |
% \begin{macro}{\verbatim@test} |
| 1201 |
% \changes{v1.2}{1989/10/20}{Introduced \cs{verbatim@test}.} |
| 1202 |
% We define |\verbatim@test| to investigate every token |
| 1203 |
% in turn. |
| 1204 |
% \begin{macrocode} |
| 1205 |
\def\verbatim@test#1{% |
| 1206 |
% \end{macrocode} |
| 1207 |
% First of all we set |\next| equal to |\verbatim@test| |
| 1208 |
% in case this macro must call itself recursively in order to |
| 1209 |
% skip spaces. |
| 1210 |
% \begin{macrocode} |
| 1211 |
\let\next\verbatim@test |
| 1212 |
% \end{macrocode} |
| 1213 |
% We have to distinguish four cases: |
| 1214 |
% \begin{enumerate} |
| 1215 |
% \item The next token is a |^^M|, i.e.\ we reached |
| 1216 |
% the end of the line. That means that nothing |
| 1217 |
% special was found. |
| 1218 |
% Note that we use |\if| for the following |
| 1219 |
% comparisons so that the category code of the |
| 1220 |
% characters is irrelevant. |
| 1221 |
% \begin{macrocode} |
| 1222 |
\if\noexpand#1\noexpand~% |
| 1223 |
% \end{macrocode} |
| 1224 |
% We add the characters accumulated in token register |
| 1225 |
% |\@temptokena| to the current line. Since |
| 1226 |
% |\verbatim@addtoline| does not expand its argument, |
| 1227 |
% we have to do the expansion at this point. Then we |
| 1228 |
% |\let| |\next| equal to |\verbatim@| |
| 1229 |
% to prepare to read the next line. |
| 1230 |
% \changes{v1.2f}{1990/01/31}{Added \cs{verbatim@startline}.} |
| 1231 |
% \begin{macrocode} |
| 1232 |
\expandafter\verbatim@addtoline |
| 1233 |
\expandafter{\the\@temptokena}% |
| 1234 |
\verbatim@processline |
| 1235 |
\verbatim@startline |
| 1236 |
\let\next\verbatim@ |
| 1237 |
% \end{macrocode} |
| 1238 |
% \item A space character follows. |
| 1239 |
% This is allowed, so we add it to |\@temptokena| |
| 1240 |
% and continue. |
| 1241 |
% \begin{macrocode} |
| 1242 |
\else \if\noexpand#1 |
| 1243 |
\@temptokena\expandafter{\the\@temptokena#1}% |
| 1244 |
% \end{macrocode} |
| 1245 |
% \changes{v1.2f}{1990/01/31}{Code for TABs removed.} |
| 1246 |
% \item An open brace follows. |
| 1247 |
% This is the most interesting case. |
| 1248 |
% We must now collect characters until we read the closing |
| 1249 |
% brace and check whether they form the environment name. |
| 1250 |
% This will be done by |\verbatim@testend|, so here |
| 1251 |
% we let |\next| equal this macro. |
| 1252 |
% Again we will process the rest of the line, character |
| 1253 |
% by character. |
| 1254 |
% \changes{v1.2}{1989/10/20}{Moved the initialization of |
| 1255 |
% \cs{@tempc} from \cs{verbatim@testend} into |
| 1256 |
% \cs{verbatim@test}.} |
| 1257 |
% The characters forming the name of the environment will |
| 1258 |
% be accumulated in |\@tempc|. |
| 1259 |
% We initialize this macro to expand to nothing. |
| 1260 |
% \changes{v1.3b}{1990/02/07}{\cs{noexpand} added.} |
| 1261 |
% \begin{macrocode} |
| 1262 |
\else \if\noexpand#1\noexpand[% |
| 1263 |
\let\@tempc\@empty |
| 1264 |
\let\next\verbatim@testend |
| 1265 |
% \end{macrocode} |
| 1266 |
% Note that the |[| character will be a |{| when |
| 1267 |
% this macro is defined. |
| 1268 |
% \item Any other character means that the |\end| was part |
| 1269 |
% of the verbatim text. |
| 1270 |
% Add the characters to the current line and prepare to call |
| 1271 |
% |\verbatim@| to process the rest of the line. |
| 1272 |
% \changes{v1.0f}{1989/10/09}{Fixed \cs{end} \cs{end} bug |
| 1273 |
% found by Chris Rowley} |
| 1274 |
% \begin{macrocode} |
| 1275 |
\else |
| 1276 |
\expandafter\verbatim@addtoline |
| 1277 |
\expandafter{\the\@temptokena}% |
| 1278 |
\def\next{\verbatim@#1}% |
| 1279 |
\fi\fi\fi |
| 1280 |
% \end{macrocode} |
| 1281 |
% \end{enumerate} |
| 1282 |
% The last thing this macro does is to call |\next| |
| 1283 |
% to continue processing. |
| 1284 |
% \begin{macrocode} |
| 1285 |
\next}% |
| 1286 |
% \end{macrocode} |
| 1287 |
% \end{macro} |
| 1288 |
% |
| 1289 |
% \begin{macro}{\verbatim@testend} |
| 1290 |
% |\verbatim@testend| is called when |
| 1291 |
% |\end|\meta{optional spaces}|{| was seen. |
| 1292 |
% Its task is to scan everything up to the next |}| |
| 1293 |
% and to call |\verbatim@@testend|. |
| 1294 |
% If no |}| is found it must reinsert the characters it read |
| 1295 |
% and return to |\verbatim@|. |
| 1296 |
% The following definition is similar to that of |
| 1297 |
% |\verbatim@test|: |
| 1298 |
% it takes the next character and decides what to do. |
| 1299 |
% \changes{v1.2}{1989/10/20}{Removed local definition of \cs{@tempa} |
| 1300 |
% from \cs{verbatim@testend} which now |
| 1301 |
% does the work itself.} |
| 1302 |
% \begin{macrocode} |
| 1303 |
\def\verbatim@testend#1{% |
| 1304 |
% \end{macrocode} |
| 1305 |
% Again, we have four cases: |
| 1306 |
% \begin{enumerate} |
| 1307 |
% \item |^^M|: As no |}| is found in the current line, |
| 1308 |
% add the characters to the buffer. To avoid a |
| 1309 |
% complicated construction for expanding |
| 1310 |
% |\@temptokena| |
| 1311 |
% and |\@tempc| we do it in two steps. Then we |
| 1312 |
% continue with |\verbatim@| to process the |
| 1313 |
% next line. |
| 1314 |
% \changes{v1.2f}{1990/01/31}{Added \cs{verbatim@startline}.} |
| 1315 |
% \begin{macrocode} |
| 1316 |
\if\noexpand#1\noexpand~% |
| 1317 |
\expandafter\verbatim@addtoline |
| 1318 |
\expandafter{\the\@temptokena[}% |
| 1319 |
\expandafter\verbatim@addtoline |
| 1320 |
\expandafter{\@tempc}% |
| 1321 |
\verbatim@processline |
| 1322 |
\verbatim@startline |
| 1323 |
\let\next\verbatim@ |
| 1324 |
% \end{macrocode} |
| 1325 |
% \item |}|: Call |\verbatim@@testend| to check |
| 1326 |
% if this is the right environment name. |
| 1327 |
% \changes{v1.3b}{1990/02/07}{\cs{noexpand} added.} |
| 1328 |
% \begin{macrocode} |
| 1329 |
\else\if\noexpand#1\noexpand]% |
| 1330 |
\let\next\verbatim@@testend |
| 1331 |
% \end{macrocode} |
| 1332 |
% \changes{v1.0f}{1989/10/09}{Introduced check for |
| 1333 |
% {\tt\string\verb!\string|!\string\!\string|} to fix |
| 1334 |
% single brace bug found by Chris Rowley} |
| 1335 |
% \item |\|: This character must not occur in the name of |
| 1336 |
% an environment. Thus we stop collecting characters. |
| 1337 |
% In principle, the same argument would apply to other |
| 1338 |
% characters as well, e.g., |{|. |
| 1339 |
% However, |\| is a special case, since it may be |
| 1340 |
% the first character of |\end|. This means that |
| 1341 |
% we have to look again for |
| 1342 |
% |\end{|\meta{environment name}|}|. |
| 1343 |
% Note that we prefixed the |!| by a |\noexpand| |
| 1344 |
% primitive, to protect ourselves against it being an |
| 1345 |
% active character. |
| 1346 |
% \changes{v1.3b}{1990/02/07}{\cs{noexpand} added.} |
| 1347 |
% \begin{macrocode} |
| 1348 |
\else\if\noexpand#1\noexpand!% |
| 1349 |
\expandafter\verbatim@addtoline |
| 1350 |
\expandafter{\the\@temptokena[}% |
| 1351 |
\expandafter\verbatim@addtoline |
| 1352 |
\expandafter{\@tempc}% |
| 1353 |
\def\next{\verbatim@!}% |
| 1354 |
% \end{macrocode} |
| 1355 |
% \item Any other character: collect it and continue. |
| 1356 |
% We cannot use |\edef| to define |\@tempc| |
| 1357 |
% since its replacement text might contain active |
| 1358 |
% character tokens. |
| 1359 |
% \begin{macrocode} |
| 1360 |
\else \expandafter\def\expandafter\@tempc\expandafter |
| 1361 |
{\@tempc#1}\fi\fi\fi |
| 1362 |
% \end{macrocode} |
| 1363 |
% \end{enumerate} |
| 1364 |
% As before, the macro ends by calling itself, to |
| 1365 |
% process the next character if appropriate. |
| 1366 |
% \begin{macrocode} |
| 1367 |
\next}% |
| 1368 |
% \end{macrocode} |
| 1369 |
% \end{macro} |
| 1370 |
% |
| 1371 |
% \begin{macro}{\verbatim@@testend} |
| 1372 |
% Unlike the previous macros |\verbatim@@testend| is simple: |
| 1373 |
% it has only to check if the |\end{|\ldots|}| |
| 1374 |
% matches the corresponding |\begin{|\ldots|}|. |
| 1375 |
% \begin{macrocode} |
| 1376 |
\def\verbatim@@testend{% |
| 1377 |
% \end{macrocode} |
| 1378 |
% We use |\next| again to define the things that are |
| 1379 |
% to be done. |
| 1380 |
% Remember that the name of the current environment is |
| 1381 |
% held in |\@currenvir|, the characters accumulated |
| 1382 |
% by |\verbatim@testend| are in |\@tempc|. |
| 1383 |
% So we simply compare these and prepare to execute |
| 1384 |
% |\end{|\meta{current environment}|}| |
| 1385 |
% macro if they match. |
| 1386 |
% Before we do this we call |\verbatim@finish| to process |
| 1387 |
% the last line. |
| 1388 |
% We define |\next| via |\edef| so that |
| 1389 |
% |\@currenvir| is replaced by its expansion. |
| 1390 |
% Therefore we need |\noexpand| to inhibit the expansion |
| 1391 |
% of |\end| at this point. |
| 1392 |
% \begin{macrocode} |
| 1393 |
\ifx\@tempc\@currenvir |
| 1394 |
\verbatim@finish |
| 1395 |
\edef\next{\noexpand\end{\@currenvir}% |
| 1396 |
% \end{macrocode} |
| 1397 |
% Without this trick the |\end| command would not be able |
| 1398 |
% to correctly check whether its argument matches the name of |
| 1399 |
% the current environment and you'd get an |
| 1400 |
% interesting \LaTeX{} error message such as: |
| 1401 |
% \begin{verbatim} |
| 1402 |
%! \begin{verbatim*} ended by \end{verbatim*}. |
| 1403 |
%\end{verbatim} |
| 1404 |
% But what do we do with the rest of the characters, those |
| 1405 |
% that remain on that line? |
| 1406 |
% We call |\verbatim@rescan| to take care of that. |
| 1407 |
% Its first argument is the name of the environment just |
| 1408 |
% ended, in case we need it again. |
| 1409 |
% |\verbatim@rescan| takes the list of characters to be |
| 1410 |
% reprocessed as its second argument. |
| 1411 |
% (This token list was inserted after the current macro |
| 1412 |
% by |\verbatim@@@|.) |
| 1413 |
% Since we are still in an |\edef| we protect it |
| 1414 |
% by means of |\noexpand|. |
| 1415 |
% \begin{macrocode} |
| 1416 |
\noexpand\verbatim@rescan{\@currenvir}}% |
| 1417 |
% \end{macrocode} |
| 1418 |
% If the names do not match, we reinsert everything read up |
| 1419 |
% to now and prepare to call |\verbatim@| to process |
| 1420 |
% the rest of the line. |
| 1421 |
% \begin{macrocode} |
| 1422 |
\else |
| 1423 |
\expandafter\verbatim@addtoline |
| 1424 |
\expandafter{\the\@temptokena[}% |
| 1425 |
\expandafter\verbatim@addtoline |
| 1426 |
\expandafter{\@tempc]}% |
| 1427 |
\let\next\verbatim@ |
| 1428 |
\fi |
| 1429 |
% \end{macrocode} |
| 1430 |
% Finally we call |\next|. |
| 1431 |
% \begin{macrocode} |
| 1432 |
\next}% |
| 1433 |
% \end{macrocode} |
| 1434 |
% \end{macro} |
| 1435 |
% |
| 1436 |
% \begin{macro}{\verbatim@rescan} |
| 1437 |
% In principle |\verbatim@rescan| could be used to |
| 1438 |
% analyse the characters remaining after the |\end{...}| |
| 1439 |
% command and pretend that these were read |
| 1440 |
% ``properly'', assuming ``standard'' category codes are in |
| 1441 |
% force.\footnote{Remember that they were all read with |
| 1442 |
% category codes $11$ (letter) and $12$ (other) so |
| 1443 |
% that control sequences are not recognized as such.} |
| 1444 |
% But this is not always possible (when there are unmatched |
| 1445 |
% curly braces in the rest of the line). |
| 1446 |
% Besides, we think that this is not worth the effort: |
| 1447 |
% After a \texttt{verbatim} or \texttt{verbatim*} environment |
| 1448 |
% a new line in the output is begun anyway, |
| 1449 |
% and an |\end{comment}| can easily be put on a line by itself. |
| 1450 |
% So there is no reason why there should be any text here. |
| 1451 |
% For the benefit of the user who did put something there |
| 1452 |
% (a comment, perhaps) |
| 1453 |
% we simply issue a warning and drop them. |
| 1454 |
% The method of testing is explained in Appendix~D, p.\ 376 of |
| 1455 |
% the \TeX{}book. We use |^^M| instead of the |!| |
| 1456 |
% character used there |
| 1457 |
% since this is a character that cannot appear in |#1|. |
| 1458 |
% The two |\noexpand| primitives are necessary to avoid |
| 1459 |
% expansion of active characters and macros. |
| 1460 |
% |
| 1461 |
% One extra subtlety should be noted here: remember that |
| 1462 |
% the token list we are currently building will first be |
| 1463 |
% processed by the |\lowercase| primitive before \TeX{} |
| 1464 |
% carries out the definitions. |
| 1465 |
% This means that the `|C|' character in the |
| 1466 |
% argument to the |\@warning| macro must be protected against |
| 1467 |
% being changed to `|c|'. That's the reason why we added the |
| 1468 |
% |\lccode`\C=`\C| assignment above. |
| 1469 |
% We can now finish the argument to |\lowercase| as well as the |
| 1470 |
% group in which the category codes were changed. |
| 1471 |
% \begin{macrocode} |
| 1472 |
\def\verbatim@rescan#1#2~{\if\noexpand~\noexpand#2~\else |
| 1473 |
\@warning{Characters dropped after `\string\end{#1}'}\fi}} |
| 1474 |
% \end{macrocode} |
| 1475 |
% \end{macro} |
| 1476 |
% |
| 1477 |
% \subsection{The \cs{verbatiminput} command} |
| 1478 |
% |
| 1479 |
% \begin{macro}{\verbatim@in@stream} |
| 1480 |
% We begin by allocating an input stream (out of the 16 available |
| 1481 |
% input streams). |
| 1482 |
%\iffalse |
| 1483 |
% Vorstellbar ist auch der Aufruf von |`verbatiminput| innerhalb eines |
| 1484 |
% |`verbatiminput| (z.B: wenn man |`input|-Anweisungen im zu lesenden |
| 1485 |
% File hat und auch diese Files automatisch lesen will). Dies kann |
| 1486 |
% man jedoch nur ermoeglichen, wenn man einen besseren Mechanismus |
| 1487 |
% verwendet als es das simple, statische |`newread| darstellt. |
| 1488 |
% Vorstellbar fuer eine neuere \LaTeX-Version ist eine (lokale) |
| 1489 |
% Allokation des Streams durch ein |`open| und eine Freigabe des |
| 1490 |
% Streams durch |`close| oder Verlassen der Gruppe. |
| 1491 |
%\fi |
| 1492 |
% \begin{macrocode} |
| 1493 |
\newread\verbatim@in@stream |
| 1494 |
% \end{macrocode} |
| 1495 |
% \end{macro} |
| 1496 |
% |
| 1497 |
% \begin{macro}{\verbatim@readfile} |
| 1498 |
% The macro |\verbatim@readfile| encloses the main loop by calls to |
| 1499 |
% the macros |\verbatim@startline| and |\verbatim@finish|, |
| 1500 |
% respectively. This makes sure |
| 1501 |
% that the user can initialize and finish the command when the file |
| 1502 |
% is empty or doesn't exist. The \texttt{verbatim} environment has a |
| 1503 |
% similar behaviour when called with an empty text. |
| 1504 |
% \begin{macrocode} |
| 1505 |
\def\verbatim@readfile#1{% |
| 1506 |
\verbatim@startline |
| 1507 |
% \end{macrocode} |
| 1508 |
% When the file is not found we issue a warning. |
| 1509 |
% \begin{macrocode} |
| 1510 |
\openin\verbatim@in@stream #1\relax |
| 1511 |
\ifeof\verbatim@in@stream |
| 1512 |
\typeout{No file #1.}% |
| 1513 |
\else |
| 1514 |
% \end{macrocode} |
| 1515 |
% At this point we pass the name of the file to |\@addtofilelist| |
| 1516 |
% so that it appears in the output of a |\listfiles| |
| 1517 |
% command. |
| 1518 |
% \changes{v1.5j}{1996/09/25}{Add \cs{@addtofilelist} and |
| 1519 |
% \cs{ProvidesFile} so that the name of the file |
| 1520 |
% read in appears in the \cs{listfiles} output (Omission pointed |
| 1521 |
% out by Patrick W.~Daly).} |
| 1522 |
% In addition, we use |\ProvidesFile| to make a log entry in the |
| 1523 |
% transcript file and to distinguish files read in via |
| 1524 |
% |\verbatiminput| from others. |
| 1525 |
% \begin{macrocode} |
| 1526 |
\@addtofilelist{#1}% |
| 1527 |
\ProvidesFile{#1}[(verbatim)]% |
| 1528 |
% \end{macrocode} |
| 1529 |
% While reading from the file it is useful to switch off the |
| 1530 |
% recognition of the end-of-line character. This saves us stripping |
| 1531 |
% off spaces from the contents of the line. |
| 1532 |
% \begin{macrocode} |
| 1533 |
\expandafter\endlinechar\expandafter\m@ne |
| 1534 |
\expandafter\verbatim@read@file |
| 1535 |
\expandafter\endlinechar\the\endlinechar\relax |
| 1536 |
\closein\verbatim@in@stream |
| 1537 |
\fi |
| 1538 |
\verbatim@finish |
| 1539 |
} |
| 1540 |
% \end{macrocode} |
| 1541 |
% \end{macro} |
| 1542 |
% |
| 1543 |
% \begin{macro}{\verbatim@read@file} |
| 1544 |
% All the work is done in |\verbatim@read@file|. It reads the input |
| 1545 |
% file line by line and recursively calls itself until the end of |
| 1546 |
% the file. |
| 1547 |
% \begin{macrocode} |
| 1548 |
\def\verbatim@read@file{% |
| 1549 |
\read\verbatim@in@stream to\next |
| 1550 |
\ifeof\verbatim@in@stream |
| 1551 |
\else |
| 1552 |
% \end{macrocode} |
| 1553 |
% For each line we call |\verbatim@addtoline| with the contents of |
| 1554 |
% the line. \hskip0pt plus 3cm\penalty0\hskip0pt plus -3cm |
| 1555 |
% |\verbatim@processline| is called next. |
| 1556 |
% \begin{macrocode} |
| 1557 |
\expandafter\verbatim@addtoline\expandafter{\next}% |
| 1558 |
\verbatim@processline |
| 1559 |
% \end{macrocode} |
| 1560 |
% After processing the line we call |\verbatim@startline| to |
| 1561 |
% initialize all before we read the next line. |
| 1562 |
% \begin{macrocode} |
| 1563 |
\verbatim@startline |
| 1564 |
% \end{macrocode} |
| 1565 |
% Without |\expandafter| each call of |\verbatim@read@file| uses |
| 1566 |
% space in \TeX's input stack.\footnote{A standard \TeX\ would |
| 1567 |
% report an overflow error if you try to read a file with more than |
| 1568 |
% ca.\ 200~lines. The same error occurs if the first line of code |
| 1569 |
% in \S 390 of \textsl{``TeX: The Program''\/} is missing.} |
| 1570 |
% \begin{macrocode} |
| 1571 |
\expandafter\verbatim@read@file |
| 1572 |
\fi |
| 1573 |
} |
| 1574 |
% \end{macrocode} |
| 1575 |
% \end{macro} |
| 1576 |
% |
| 1577 |
% |
| 1578 |
% \begin{macro}{\verbatiminput} |
| 1579 |
% |\verbatiminput| first starts a group to keep font and category |
| 1580 |
% changes local. |
| 1581 |
% Then it calls the macro |\verbatim@input| with additional |
| 1582 |
% arguments, depending on whether an asterisk follows. |
| 1583 |
% \begin{macrocode} |
| 1584 |
\def\verbatiminput{\begingroup |
| 1585 |
% \end{macrocode} |
| 1586 |
% |
| 1587 |
% \changes{v1.5x}{2024/01/22}{Added TAB marking support into the |
| 1588 |
% starred version (gh/1245)} |
| 1589 |
% If starred, we mark spaces and TABs, the two |
| 1590 |
% added pieces are the same as for verbatim*. |
| 1591 |
% \begin{macrocode} |
| 1592 |
\@ifstar{\verbatim@input{\@setupverbvisiblespace\@vobeyspaces}}% |
| 1593 |
{\verbatim@input{\frenchspacing\@vobeyspaces}}} |
| 1594 |
% \end{macrocode} |
| 1595 |
% \end{macro} |
| 1596 |
% |
| 1597 |
% \begin{macro}{\verbatim@input} |
| 1598 |
% \changes{1.5k}{1997/04/30}{Have \cs{verbatim@input} check for |
| 1599 |
% existence of file.} |
| 1600 |
% |\verbatim@input| first checks whether the file exists, using |
| 1601 |
% the standard macro |\IfFileExists| which leaves the name of the |
| 1602 |
% file found in |\@filef@und|. |
| 1603 |
% Then everything is set up as in the |\verbatim| macro. But, as |
| 1604 |
% |\@verbatim| contains a call to |\every@verbatim| which |
| 1605 |
% \emph{might} contain an |\input| statement, which would overwrite |
| 1606 |
% the contents of |\@filef@und|, we need to save it by expanding it |
| 1607 |
% first. The use of |\@swaptwoargs| makes it so that the |
| 1608 |
% \emph{expansion} of |\@filef@und| gets to be the second argument |
| 1609 |
% of |\verbatim@readfile|. |
| 1610 |
% \changes{v1.5t}{2020-07-06}{Expand \cs{@filef@und} before the call |
| 1611 |
% of \cs{@verbatim} (gh/222)} |
| 1612 |
% \begin{macrocode} |
| 1613 |
\def\verbatim@input#1#2{% |
| 1614 |
\IfFileExists {#2}{% |
| 1615 |
\expandafter\@swaptwoargs\expandafter |
| 1616 |
{\expandafter{\@filef@und}}% |
| 1617 |
{\@verbatim #1\relax |
| 1618 |
% \end{macrocode} |
| 1619 |
% Then it reads in the file, finishes off the \texttt{trivlist} |
| 1620 |
% environment started by |\@verbatim| and closes the group. |
| 1621 |
% This restores everything to its normal settings. |
| 1622 |
% \begin{macrocode} |
| 1623 |
\verbatim@readfile}% |
| 1624 |
\endtrivlist\endgroup\@doendpe}% |
| 1625 |
% \end{macrocode} |
| 1626 |
% If the file is not found a more or less helpful message is |
| 1627 |
% printed. The final |\endgroup| is needed to close the group |
| 1628 |
% started in |\verbatiminput| above. |
| 1629 |
% \begin{macrocode} |
| 1630 |
{\typeout {No file #2.}\endgroup}} |
| 1631 |
%</package> |
| 1632 |
% \end{macrocode} |
| 1633 |
% \end{macro} |
| 1634 |
% |
| 1635 |
% |
| 1636 |
% \subsection{Getting verbatim text into arguments} |
| 1637 |
% |
| 1638 |
% One way of achieving this is to define a macro (command) whose |
| 1639 |
% expansion is the required verbatim text. This command can then be |
| 1640 |
% used anywhere that the verbatim text is required. It can be used in |
| 1641 |
% arguments, even moving ones, but it is fragile (at least, the |
| 1642 |
% version here is). |
| 1643 |
% |
| 1644 |
% Here is some code which claims to provide this. It is a much revised |
| 1645 |
% version of something I (Chris) did about 2 years ago. Maybe it needs |
| 1646 |
% further revision. |
| 1647 |
% |
| 1648 |
% It is only intended as an extension to |\verb|, not to the |
| 1649 |
% \texttt{verbatim} environment. It should therefore, perhaps, treat |
| 1650 |
% line-ends similarly to whatever is best for |\verb|. |
| 1651 |
% |
| 1652 |
% \begin{macro}{\newverbtext} |
| 1653 |
% This is the command to produce a new macro whose expansion is |
| 1654 |
% verbatim text. This command itself cannot be used in arguments, |
| 1655 |
% of course! It is used as follows: |
| 1656 |
% |
| 1657 |
% \begin{verbatim} |
| 1658 |
% \newverbtext{\myverb}"^%{ &~_\}}@ #" |
| 1659 |
% \end{verbatim} |
| 1660 |
% |
| 1661 |
% The rules for delimiting the verbatim text are the same as those for |
| 1662 |
% |\verb|. |
| 1663 |
% |
| 1664 |
% \begin{macrocode} |
| 1665 |
%<*verbtext> |
| 1666 |
\def \newverbtext {% |
| 1667 |
\@ifstar {\@tempswatrue \@verbtext }{\@tempswafalse \@verbtext *}% |
| 1668 |
} |
| 1669 |
% \end{macrocode} |
| 1670 |
% \end{macro} |
| 1671 |
% I think that a temporary switch is safe here: if not, then |
| 1672 |
% suitable |\let|s can be used. |
| 1673 |
% \changes{v1.5i}{1996/06/04}{Moved processing of |
| 1674 |
% \cs{verbatim@nolig@list} after \cs{dospecials}.} |
| 1675 |
% \changes{v1.5p}{2001/03/12}{Added missing right brace in |
| 1676 |
% definition of \cs{@verbtext} (PR 3314).} |
| 1677 |
% \begin{macrocode} |
| 1678 |
\def \@verbtext *#1#2{% |
| 1679 |
\begingroup |
| 1680 |
\let\do\@makeother \dospecials |
| 1681 |
\let\do\do@noligs \verbatim@nolig@list |
| 1682 |
\@vobeyspaces |
| 1683 |
\catcode`#2\active |
| 1684 |
\catcode`~\active |
| 1685 |
\lccode`\~`#2% |
| 1686 |
\lowercase |
| 1687 |
% \end{macrocode} |
| 1688 |
% We use a temporary macro here and a trick so that the definition of |
| 1689 |
% the command itself can be done inside the group and be a local |
| 1690 |
% definition (there may be better ways to achieve this). |
| 1691 |
% \begin{macrocode} |
| 1692 |
{\def \@tempa ##1~% |
| 1693 |
{\whitespaces |
| 1694 |
% \end{macrocode} |
| 1695 |
% If these |\noexpand|s were |\noexpand\protect\noexpand|, would |
| 1696 |
% this make these things robust? |
| 1697 |
% \begin{macrocode} |
| 1698 |
\edef #1{\noexpand \@verbtextmcheck |
| 1699 |
\bgroup |
| 1700 |
\if@tempswa |
| 1701 |
\noexpand \visiblespaces |
| 1702 |
\fi |
| 1703 |
\noexpand \@verbtextsetup |
| 1704 |
##1% |
| 1705 |
\egroup}% |
| 1706 |
}% |
| 1707 |
\expandafter\endgroup\@tempa |
| 1708 |
} |
| 1709 |
} |
| 1710 |
% \end{macrocode} |
| 1711 |
% This sets up the correct type of group for the mode: it must not |
| 1712 |
% be expanded at define time! |
| 1713 |
% \begin{macrocode} |
| 1714 |
\def \@verbtextmcheck {% |
| 1715 |
\relax\ifmmode |
| 1716 |
\hbox |
| 1717 |
\else |
| 1718 |
\leavevmode |
| 1719 |
\null |
| 1720 |
\fi |
| 1721 |
} |
| 1722 |
% \end{macrocode} |
| 1723 |
% This contains other things which should not be expanded during the |
| 1724 |
% definition. |
| 1725 |
% \begin{macrocode} |
| 1726 |
\def \@verbtextsetup {% |
| 1727 |
\frenchspacing |
| 1728 |
\verbatim@font |
| 1729 |
\verbtextstyle |
| 1730 |
} |
| 1731 |
% \end{macrocode} |
| 1732 |
% The command |\verbtextstyle| is a document-level hook which can be |
| 1733 |
% used to override the predefined typographic treatment of commands |
| 1734 |
% defined with |\newverbtext| commands. |
| 1735 |
% |
| 1736 |
% |\visiblespaces| and |\whitespaces| are examples of possible values |
| 1737 |
% of this hook. |
| 1738 |
% \begin{macrocode} |
| 1739 |
\let \verbtextstyle \relax |
| 1740 |
\def \visiblespaces {\chardef \ 32\relax} |
| 1741 |
\def \whitespaces {\let \ \@@space} |
| 1742 |
\let \@@space \ % |
| 1743 |
%</verbtext> |
| 1744 |
% \end{macrocode} |
| 1745 |
% |
| 1746 |
% |
| 1747 |
% \section{Testing the implementation} |
| 1748 |
% |
| 1749 |
% For testing the implementation and for demonstration we provide |
| 1750 |
% an extra file. It can be extracted by using the conditional |
| 1751 |
% `\textsf{testdriver}'. It uses a small input file called |
| 1752 |
% `\texttt{verbtest.tst}' that is distributed separately. |
| 1753 |
% Again, we use individual `+' guards. |
| 1754 |
% \begin{macrocode} |
| 1755 |
%<*testdriver> |
| 1756 |
\documentclass{article} |
| 1757 |
|
| 1758 |
\usepackage{verbatim} |
| 1759 |
|
| 1760 |
\newenvironment{myverbatim}% |
| 1761 |
{\endgraf\noindent MYVERBATIM:\endgraf\verbatim}% |
| 1762 |
{\endverbatim} |
| 1763 |
|
| 1764 |
\makeatletter |
| 1765 |
|
| 1766 |
\newenvironment{verbatimlisting}[1]% |
| 1767 |
{\def\verbatim@startline{\input{#1}% |
| 1768 |
\def\verbatim@startline{\verbatim@line{}}% |
| 1769 |
\verbatim@startline}% |
| 1770 |
\verbatim}{\endverbatim} |
| 1771 |
|
| 1772 |
\newwrite\verbatim@out |
| 1773 |
|
| 1774 |
\newenvironment{verbatimwrite}[1]% |
| 1775 |
{\@bsphack |
| 1776 |
\immediate\openout \verbatim@out #1 |
| 1777 |
\let\do\@makeother\dospecials\catcode`\^^M\active |
| 1778 |
\def\verbatim@processline{% |
| 1779 |
\immediate\write\verbatim@out{\the\verbatim@line}}% |
| 1780 |
\verbatim@start}% |
| 1781 |
{\immediate\closeout\verbatim@out\@esphack} |
| 1782 |
|
| 1783 |
\makeatother |
| 1784 |
|
| 1785 |
\addtolength{\textwidth}{30pt} |
| 1786 |
|
| 1787 |
\begin{document} |
| 1788 |
|
| 1789 |
\typeout{} |
| 1790 |
\typeout{===> Expect ``characters dropped'' |
| 1791 |
warning messages in this test! <====} |
| 1792 |
\typeout{} |
| 1793 |
|
| 1794 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1795 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1796 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1797 |
\begin{verbatim} |
| 1798 |
test |
| 1799 |
\end{verbatim*} |
| 1800 |
test |
| 1801 |
\end{verbatim |
| 1802 |
test of ligatures: <`!`?`> |
| 1803 |
\endverbatim |
| 1804 |
test |
| 1805 |
\end verbatim |
| 1806 |
test |
| 1807 |
test of end of line: |
| 1808 |
\end |
| 1809 |
{verbatim} |
| 1810 |
\end{verbatim} Further text to be typeset: $\alpha$. |
| 1811 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1812 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1813 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1814 |
\begin{verbatim*} |
| 1815 |
test |
| 1816 |
test |
| 1817 |
\end {verbatim*} |
| 1818 |
Text Text Text Text Text Text Text Text Text Text Text |
| 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 |
\begin{verbatim*} bla bla |
| 1822 |
test |
| 1823 |
test |
| 1824 |
\end {verbatim*} |
| 1825 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1826 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1827 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1828 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1829 |
|
| 1830 |
First of Chris Rowley's fiendish tests: |
| 1831 |
\begin{verbatim} |
| 1832 |
the double end test<text> |
| 1833 |
\end\end{verbatim} or even \end \end{verbatim} |
| 1834 |
% |
| 1835 |
%not \end\ended?? |
| 1836 |
%\end{verbatim} |
| 1837 |
|
| 1838 |
Another of Chris' devils: |
| 1839 |
\begin{verbatim} |
| 1840 |
the single brace test<text> |
| 1841 |
\end{not the end\end{verbatim} |
| 1842 |
% |
| 1843 |
%not \end}ed?? |
| 1844 |
%\end{verbatim} |
| 1845 |
Back to my own tests: |
| 1846 |
\begin{myverbatim} |
| 1847 |
test |
| 1848 |
test |
| 1849 |
\end {myverbatim} rest of line |
| 1850 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1851 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1852 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1853 |
|
| 1854 |
Test of empty verbatim: |
| 1855 |
\begin{verbatim} |
| 1856 |
\end{verbatim} |
| 1857 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1858 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1859 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1860 |
\begin {verbatimlisting}{verbtest.tex} |
| 1861 |
Additional verbatim text |
| 1862 |
... |
| 1863 |
\end{verbatimlisting} |
| 1864 |
And here for listing a file: |
| 1865 |
\verbatiminput{verbtest.tex} |
| 1866 |
And again, with explicit spaces: |
| 1867 |
\verbatiminput*{verbtest.tex} |
| 1868 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1869 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1870 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1871 |
\begin{comment} |
| 1872 |
test |
| 1873 |
\end{verbatim*} |
| 1874 |
test |
| 1875 |
\end {comment |
| 1876 |
test |
| 1877 |
\endverbatim |
| 1878 |
test |
| 1879 |
\end verbatim |
| 1880 |
test |
| 1881 |
\end {comment} Further text to be typeset: $\alpha$. |
| 1882 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1883 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1884 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1885 |
\begin{comment} bla bla |
| 1886 |
test |
| 1887 |
test |
| 1888 |
\end {comment} |
| 1889 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1890 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1891 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1892 |
Text Text Text Text Text Text Text Text Text Text Text |
| 1893 |
|
| 1894 |
\begin{verbatimwrite}{verbtest.txt} |
| 1895 |
asfa<fa<df |
| 1896 |
sdfsdfasd |
| 1897 |
asdfa<fsa |
| 1898 |
\end{verbatimwrite} |
| 1899 |
|
| 1900 |
\end{document} |
| 1901 |
%</testdriver> |
| 1902 |
% \end{macrocode} |
| 1903 |
% |
| 1904 |
% |
| 1905 |
% \Finale |
| 1906 |
% |
| 1907 |
\endinput |
| 1908 |
%% |