| 1 |
% |
| 2 |
% \iffalse |
| 3 |
% |
| 4 |
% Copyright (C) 1997 2002 2008 2011 by |
| 5 |
% Robin Fairbairns <[email protected]> |
| 6 |
% |
| 7 |
% This work may be distributed and/or modified under the |
| 8 |
% conditions of the LaTeX Project Public License, either |
| 9 |
% version 1.3c of this license or (at your option) any later |
| 10 |
% version. The latest version of this license is in |
| 11 |
% http://www.latex-project.org/lppl.txt |
| 12 |
% and version 1.3c or later is part of all distributions of |
| 13 |
% LaTeX version 2005/12/01 or later. |
| 14 |
% |
| 15 |
% This work has the LPPL maintenance status `maintained'. |
| 16 |
% |
| 17 |
% The current maintainer of this work is Robin Fairbairns. |
| 18 |
% |
| 19 |
% This work consists of the source files moreverb.dtx, |
| 20 |
% moreverb.ins |
| 21 |
% and the derived files moreverb.sty, |
| 22 |
% moreverb.pdf |
| 23 |
% |
| 24 |
% RCS information: |
| 25 |
% |
| 26 |
% $Id: moreverb.dtx,v 1.12 2011/04/18 19:03:28 rf10 Exp rf10 $ |
| 27 |
% |
| 28 |
% \section{Initially: identify the package} |
| 29 |
% |
| 30 |
% We use the same body for the \cs{ProvidesFile} as for the |
| 31 |
% \cs{ProvidesPackage} command. |
| 32 |
% |
| 33 |
% \begin{macrocode} |
| 34 |
\NeedsTeXFormat{LaTeX2e} |
| 35 |
%<*dtx> |
| 36 |
\ProvidesFile{moreverb.dtx} |
| 37 |
%</dtx> |
| 38 |
%<moreverb>\ProvidesPackage{moreverb} |
| 39 |
[2008/06/03 v2.3a |
| 40 |
%<moreverb> `more' verbatim facilities% |
| 41 |
%<*dtx> |
| 42 |
moreverb source file% |
| 43 |
%</dtx> |
| 44 |
] |
| 45 |
% \end{macrocode} |
| 46 |
% Code to compile the thing using LaTeX2e |
| 47 |
% |
| 48 |
%<*driver> |
| 49 |
\documentclass{ltxdoc} |
| 50 |
% |
| 51 |
\setcounter{errorcontextlines}{999} |
| 52 |
% |
| 53 |
\GetFileInfo{moreverb.dtx} |
| 54 |
% |
| 55 |
% The definition of \star in ltxdoc.cls is useless (bug report |
| 56 |
% LaTeX/2117). \env is something I would like to have -- I'm |
| 57 |
% not sure this definition is entirely kosher (in any case, why aren't |
| 58 |
% all these things in doc.sty?) |
| 59 |
% |
| 60 |
\renewcommand\star{\texttt{*}} |
| 61 |
\DeclareRobustCommand\env[1]{\cs{begin\char`\{#1\char`\}}} |
| 62 |
% |
| 63 |
\begin{document} |
| 64 |
\title{The \textsf{moreverb} package\thanks{This file |
| 65 |
has version number \fileversion, last |
| 66 |
revised \filedate}} |
| 67 |
\author{Robin Fairbairns (\small\texttt{[email protected]})\\ |
| 68 |
after\\ |
| 69 |
Angus Duggan, Rainer Sch\"opf and Victor Eijkhout} |
| 70 |
\date{\the\year-\ifnum\month<10 0\fi\the\month |
| 71 |
-\ifnum\day <10 0\fi\the\day} |
| 72 |
\maketitle |
| 73 |
\tableofcontents |
| 74 |
\DocInput{moreverb.dtx} |
| 75 |
\end{document} |
| 76 |
%</driver> |
| 77 |
% |
| 78 |
% \fi |
| 79 |
% |
| 80 |
% \CheckSum{402} |
| 81 |
% |
| 82 |
% \section{This package} |
| 83 |
% |
| 84 |
% This package uses the facilities provide by the \textsf{verbatim} |
| 85 |
% package in the \LaTeXe{} \emph{tools} distribution to provide a |
| 86 |
% number of things that were rejected as unnecessary in the |
| 87 |
% development of that package. (Nevertheless, the tab-expansion code |
| 88 |
% in this package responds to one of the FAQs of |comp.text.tex|) |
| 89 |
% |
| 90 |
% The package provides things in three broad areas: |
| 91 |
% \begin{itemize} |
| 92 |
% \item Tab expansion and related stuff, |
| 93 |
% \item Line numbering, |
| 94 |
% \item Miscellaneous: writing verbatim to a file (for example, for |
| 95 |
% later re-input), and `boxed' verbatim. |
| 96 |
% \end{itemize} |
| 97 |
% |
| 98 |
% \subsection{Tab expansion} |
| 99 |
% |
| 100 |
% The package enables you to specify the expected width of the |
| 101 |
% tabulation, and also allows input of files containing tabs. |
| 102 |
% |
| 103 |
% \DescribeEnv{verbatimtab} |
| 104 |
% |
| 105 |
% \env{verbatimtab}\oarg{tab width} |
| 106 |
% reproduces its body verbatim, with the tabs expanded to the given |
| 107 |
% width (the default value is 8). |
| 108 |
% |
| 109 |
% \DescribeMacro{\verbatimtabinput} |
| 110 |
% |
| 111 |
% \cs{verbatimtabinput}\oarg{tab width}\marg{file name} |
| 112 |
% is a file input version of the \texttt{verbatimtab} environment. |
| 113 |
% |
| 114 |
% \DescribeMacro{\verbatimtabsize} |
| 115 |
% |
| 116 |
% The size of the tabs is stored in \cs{verbatimtabsize}, and persists |
| 117 |
% between uses of the environments. (I.e., an optional argument to |
| 118 |
% one of them applies to all subsequent ones.) |
| 119 |
% |
| 120 |
% \noindent To replace the value other than by use of an optional |
| 121 |
% argument, you need to say: |
| 122 |
% |
| 123 |
% \cs{renewcommand}\cs{verbatimtabsize}|{|\meta{value}\cs{relax}|}| |
| 124 |
% |
| 125 |
% There are no promises offered as to the performance if you omit the |
| 126 |
% \cs{relax}! |
| 127 |
% |
| 128 |
% \subsection{Line numbering} |
| 129 |
% |
| 130 |
% Line numbering is often useful when reproducing code examples |
| 131 |
% (useful, that is, for those of us who don't want to pretty-print |
| 132 |
% such snippets). |
| 133 |
% |
| 134 |
% \DescribeEnv{listing} |
| 135 |
% |
| 136 |
% \env{listing}\oarg{interval}\marg{start line} numbers the lines of |
| 137 |
% its body. The argument \meta{start line} specifies the starting |
| 138 |
% line number. The optional argument \meta{interval} specifies the |
| 139 |
% number of lines between numbered lines: that is, every line whose |
| 140 |
% number \(=0\pmod{\mbox{\meta{interval}}}\) will be numbered in the |
| 141 |
% output. (In addition, line number 1 will always be numbered.) The |
| 142 |
% default value of the \meta{interval} is 1 (i.e., every line will be |
| 143 |
% numbered). |
| 144 |
% |
| 145 |
% \DescribeEnv{listingcont} |
| 146 |
% |
| 147 |
% \env{listingcont} continues from the place where the last |
| 148 |
% listing left off. |
| 149 |
% |
| 150 |
% The style in which the label is set can be altered, for either |
| 151 |
% environment, by re-defining \cs{listinglabel}. Both environments |
| 152 |
% also expand tabs. |
| 153 |
% |
| 154 |
% `\star' versions of both the listing environments are provided; |
| 155 |
% these do the usual |verbatim*| thing of outputting spaces as |
| 156 |
% `\verb*| |', but don't expand tabs. |
| 157 |
% |
| 158 |
% \DescribeMacro{listinginput} |
| 159 |
% |
| 160 |
% \cs{listinginput}\oarg{interval}\marg{start line}\marg{filename} |
| 161 |
% is a file input version of listing. There is no `\star' form. |
| 162 |
% |
| 163 |
% \subsection{Miscellanea} |
| 164 |
% |
| 165 |
% \DescribeEnv{verbatimwrite} |
| 166 |
% |
| 167 |
% \env{verbatimwrite}\marg{filename} writes all text in its body to a |
| 168 |
% file, the name of which it is given as an argument. |
| 169 |
% |
| 170 |
% \DescribeEnv{boxedverbatim} |
| 171 |
% |
| 172 |
% \env{boxedverbatim} puts the contents of a verbatim environment in a |
| 173 |
% framing box. If you try to do this in a na\"\i ve way, you find |
| 174 |
% that the verbatim lines have all become the width of the page, so |
| 175 |
% that the box is, more often than not, a very poor fit to the text it |
| 176 |
% surrounds. |
| 177 |
% |
| 178 |
% \DescribeEnv{verbatimcmd} |
| 179 |
% |
| 180 |
% The |verbatimcmd| environment was provided by the \LaTeX2.09 and |
| 181 |
% early \LaTeXe{} versions of this package. However, its capabilities |
| 182 |
% are now provided by |alltt|, which is defined by the \textsf{alltt} |
| 183 |
% package, now part of the \LaTeX{} base distribution, and so |
| 184 |
% |verbatimcmd| has been withdrawn. |
| 185 |
% |
| 186 |
% \StopEventually{} |
| 187 |
% |
| 188 |
% \section{The code of the package} |
| 189 |
% |
| 190 |
% \begin{macrocode} |
| 191 |
%<*moreverb> |
| 192 |
% \end{macrocode} |
| 193 |
% |
| 194 |
% \subsection{Initial code} |
| 195 |
% |
| 196 |
% Load the \textsf{verbatim} package if it's not already loaded. |
| 197 |
% |
| 198 |
% \begin{macrocode} |
| 199 |
\@ifundefined{verbatim@processline}{\RequirePackage{verbatim}}{} |
| 200 |
% \end{macrocode} |
| 201 |
% |
| 202 |
% \subsection{Writing to a file} |
| 203 |
% |
| 204 |
% \begin{environment}{verbatimwrite} |
| 205 |
% \env{verbatimwrite}\marg{filename} writes all text in its body to a |
| 206 |
% file, the name of which it is given as an argument. (This code was |
| 207 |
% written by Rainer Sch\"opf.) |
| 208 |
% |
| 209 |
% Note that the code creates its own output stream at first use. |
| 210 |
% (This is a conservation measure; if the user never uses |
| 211 |
% \env{verbatimwrite}, no \cs{write} stream is created. An actual |
| 212 |
% problematic use case appeared on tex.sx\dots) |
| 213 |
% |
| 214 |
% \begin{macrocode} |
| 215 |
\def\verbatimwrite#1{% |
| 216 |
\@ifundefined{verbatim@out}{\newwrite\verbatim@out}{}% |
| 217 |
\@bsphack |
| 218 |
\immediate\openout \verbatim@out #1 |
| 219 |
\let\do\@makeother\dospecials |
| 220 |
\catcode`\^^M\active \catcode`\^^I=12 |
| 221 |
\def\verbatim@processline{% |
| 222 |
\immediate\write\verbatim@out |
| 223 |
{\the\verbatim@line}}% |
| 224 |
\verbatim@start} |
| 225 |
% \end{macrocode} |
| 226 |
% \begin{macrocode} |
| 227 |
\def\endverbatimwrite{% |
| 228 |
\immediate\closeout\verbatim@out |
| 229 |
\@esphack} |
| 230 |
% \end{macrocode} |
| 231 |
% \end{environment} |
| 232 |
% |
| 233 |
% \subsection{Tab expansion} |
| 234 |
% |
| 235 |
% We define a few auxiliary macros and counters for expanding tabs. |
| 236 |
% They are used by the |listing| and |verbatimtab| environments. |
| 237 |
% |
| 238 |
% \begin{macrocode} |
| 239 |
\newcount\tab@position \newcount\tab@size |
| 240 |
% \end{macrocode} |
| 241 |
% |
| 242 |
% \cs{verbatimtabsize} used to be a counter, but that seems to me |
| 243 |
% overkill (\LaTeX{} uses too many counters as it is\dots). |
| 244 |
% |
| 245 |
% \begin{macrocode} |
| 246 |
\def\verbatimtabsize{8\relax} |
| 247 |
% \end{macrocode} |
| 248 |
% |
| 249 |
% \begin{macro}{\@xobeytab} |
| 250 |
% |
| 251 |
% \cs{@xobeytab} puts enough spaces in to get us to the next nominal |
| 252 |
% tab stop |
| 253 |
% \begin{macrocode} |
| 254 |
\def\@xobeytab{% |
| 255 |
\loop |
| 256 |
\toks@\expandafter{\the\toks@\@xobeysp}% |
| 257 |
\advance\tab@position-1 |
| 258 |
\ifnum\tab@position>0 \repeat |
| 259 |
} |
| 260 |
% \end{macrocode} |
| 261 |
% \end{macro} |
| 262 |
% |
| 263 |
% \begin{macro}{\@vobeytabs} |
| 264 |
% \cs{@vobeytabs} initialises use of \cs{@xobeytab}. Needs to be |
| 265 |
% executed within a group, as mustn't be allowed to leak out into the |
| 266 |
% wide world. |
| 267 |
% |
| 268 |
% \begin{macrocode} |
| 269 |
\begingroup |
| 270 |
\catcode`\^^I=\active |
| 271 |
\gdef\@vobeytabs{\catcode`\^^I\active\let^^I\@xobeytab}% |
| 272 |
\endgroup |
| 273 |
% \end{macrocode} |
| 274 |
% \end{macro} |
| 275 |
% |
| 276 |
% \begin{macro}{\verbatim@tabexpand} |
| 277 |
% \cs{verbatim@tabexpand}\meta{body of line}\cs{@nil} processes every |
| 278 |
% character of a line by tail recursion, counting the characters and |
| 279 |
% juggling things when a tab is encountered. (What used to be called |
| 280 |
% `line imaging'\dots) |
| 281 |
% |
| 282 |
% \begin{macrocode} |
| 283 |
\def\verbatim@tabexpand#1{% |
| 284 |
\ifx#1\@nil |
| 285 |
% \showthe\toks@ |
| 286 |
\the\toks@ |
| 287 |
\expandafter\par |
| 288 |
\else |
| 289 |
\ifx#1\@xobeytab |
| 290 |
\@xobeytab |
| 291 |
\else |
| 292 |
% \end{macrocode} |
| 293 |
% |
| 294 |
% We can safely put \cs{@xobeysp} into the token register, since it |
| 295 |
% does precisely what we need |
| 296 |
% \begin{macrocode} |
| 297 |
\toks@\expandafter{\the\toks@#1}% |
| 298 |
\advance\tab@position\m@ne |
| 299 |
\fi |
| 300 |
\ifnum\tab@position=0 \tab@position\tab@size \fi |
| 301 |
\expandafter\verbatim@tabexpand |
| 302 |
\fi |
| 303 |
} |
| 304 |
% \end{macrocode} |
| 305 |
% \end{macro} |
| 306 |
% |
| 307 |
% \begin{environment}{listing} |
| 308 |
% \env{listing}\oarg{interval}\marg{start line} |
| 309 |
% |
| 310 |
% Defines a verbatim environment with numbered lines; the optional |
| 311 |
% argument \meta{interval} specifies the number of lines between |
| 312 |
% numbered lines, and the argument \meta{start line} specifies the |
| 313 |
% starting line. |
| 314 |
% |
| 315 |
% \begin{environment}{listingcont} |
| 316 |
% \env{listingcont} |
| 317 |
% |
| 318 |
% Continues from the place where listing left off. The style in which |
| 319 |
% the label is set can be altered by re-defining \cs{listinglabel}. |
| 320 |
% |
| 321 |
% `\star' versions of both environments are provided. |
| 322 |
% |
| 323 |
% \begin{macro}{\listing@line} |
| 324 |
% \cs{listing@line} holds the current line number; its default value |
| 325 |
% is 1, so one can merrily use |listingcont| throughout a document if |
| 326 |
% there's but one stream of verbatim text being written. |
| 327 |
% |
| 328 |
% \begin{macrocode} |
| 329 |
\newcount\listing@line \listing@line=1 |
| 330 |
% \end{macrocode} |
| 331 |
% \end{macro} |
| 332 |
% |
| 333 |
% \begin{macro}{\listing@step} |
| 334 |
% \cs{listing@step} is another case where a counter used to be used, |
| 335 |
% to no very obvious utility, but using up a valuable count register. |
| 336 |
% Again, the value is modal; the trailing \cs{relax} is necessary. |
| 337 |
% |
| 338 |
% \begin{macrocode} |
| 339 |
\def\listing@step{1\relax} |
| 340 |
% \end{macrocode} |
| 341 |
% \end{macro} |
| 342 |
% |
| 343 |
% Adding an \cs{hbox} in front of the line causes a line break, so |
| 344 |
% I\footnote{The personal pronoun was present in the comments in the |
| 345 |
% original version of this package; I'm not sure who it relates |
| 346 |
% to~--- RF} go through this rigmarole to get the lines aligned |
| 347 |
% nicely. I probably missed some obvious reason why \cs{hbox}es don't |
| 348 |
% work\footnote{It's because an \cs{hbox} in vertical mode makes a |
| 349 |
% complete paragraph in its own right; this problem could be dealt |
| 350 |
% with in the fullness of time, but just now\dots}. |
| 351 |
% |
| 352 |
% \begin{macrocode} |
| 353 |
\def\listinglabel#1{\llap{\small\rmfamily\the#1}\hskip\listingoffset\relax} |
| 354 |
\def\thelisting@line{% |
| 355 |
\setbox0\hbox{\listinglabel\listing@line}% |
| 356 |
\@tempcnta=\listing@line |
| 357 |
\divide\@tempcnta\listing@step \multiply\@tempcnta\listing@step |
| 358 |
\ifnum\listing@line=\@ne |
| 359 |
\unhbox0 |
| 360 |
\else |
| 361 |
\ifnum\@tempcnta=\listing@line |
| 362 |
\unhbox0 |
| 363 |
\else |
| 364 |
\hskip\wd0 |
| 365 |
\fi |
| 366 |
\fi} |
| 367 |
% \end{macrocode} |
| 368 |
% |
| 369 |
% \begin{macro}{\listingoffset} |
| 370 |
% \cs{listingoffset} is the separation between the line number and the |
| 371 |
% actual line being listed; default value is \verb|1.5em| |
| 372 |
% \begin{macrocode} |
| 373 |
\providecommand\listingoffset{1.5em} |
| 374 |
% \end{macrocode} |
| 375 |
% \end{macro} |
| 376 |
% |
| 377 |
% Define \cs{listing} simply to suck in parameters and then to use |
| 378 |
% \cs{listingcont} |
| 379 |
% |
| 380 |
% \begin{macrocode} |
| 381 |
\newcommand\listing[2][1]{% |
| 382 |
\global\listing@line=#2\relax |
| 383 |
\gdef\listing@step{#1\relax} |
| 384 |
\listingcont} |
| 385 |
% \end{macrocode} |
| 386 |
% |
| 387 |
% \cs{listingcont} is the business end of the two environments. |
| 388 |
% |
| 389 |
% \begin{macrocode} |
| 390 |
\def\listingcont{% |
| 391 |
\tab@size=\verbatimtabsize |
| 392 |
\def\verbatim@processline{\tab@position\tab@size |
| 393 |
\thelisting@line \global\advance\listing@line1 |
| 394 |
\toks@{}% |
| 395 |
\expandafter\verbatim@tabexpand\the\verbatim@line\@nil}% |
| 396 |
\@verbatim\frenchspacing\@vobeyspaces\@vobeytabs\verbatim@start} |
| 397 |
% \end{macrocode} |
| 398 |
% |
| 399 |
% Nothing special at the end of the two environments. |
| 400 |
% |
| 401 |
% \begin{macrocode} |
| 402 |
\let\endlisting=\endtrivlist |
| 403 |
\let\endlistingcont=\endtrivlist |
| 404 |
% \end{macrocode} |
| 405 |
% |
| 406 |
% Now the same rigmarole for the `\verb+*+' versions. |
| 407 |
% |
| 408 |
% \begin{macrocode} |
| 409 |
\expandafter\newcommand\csname listing*\endcsname[2][1]{% |
| 410 |
\global\listing@line=#2\relax |
| 411 |
\gdef\listing@step{#1\relax} |
| 412 |
\csname listingcont*\endcsname} |
| 413 |
\@namedef{listingcont*}{% |
| 414 |
\def\verbatim@processline{% |
| 415 |
\thelisting@line \global\advance\listing@line1 |
| 416 |
\the\verbatim@line\par}% |
| 417 |
\@verbatim\verbatim@start} |
| 418 |
% \end{macrocode} |
| 419 |
% |
| 420 |
% Nobbut a bit of hassle in the name definitions for the end of the |
| 421 |
% environments |
| 422 |
% |
| 423 |
% \begin{macrocode} |
| 424 |
\expandafter\let\csname endlisting*\endcsname\endtrivlist |
| 425 |
\expandafter\let\csname endlistingcont*\endcsname\endtrivlist |
| 426 |
% \end{macrocode} |
| 427 |
% \end{environment} |
| 428 |
% \end{environment} |
| 429 |
% |
| 430 |
% \begin{macro}{listinginput} |
| 431 |
% \cs{listinginput}\oarg{interval}\marg{start line}\marg{filename} |
| 432 |
% is a file input version of listing. |
| 433 |
% |
| 434 |
% \begin{macrocode} |
| 435 |
\def\listinginput{% |
| 436 |
\@ifnextchar[%] |
| 437 |
{\@listinginput}% |
| 438 |
{\@listinginput[1]}} |
| 439 |
\begingroup |
| 440 |
\catcode`\~=\active \lccode`\~=`\^^M \lccode`\N=`\N |
| 441 |
\lowercase{\endgroup |
| 442 |
\def\@listinginput[#1]#2#3{\begingroup |
| 443 |
\global\listing@line=#2 |
| 444 |
\gdef\listing@step{#1\relax} |
| 445 |
\tab@size=\verbatimtabsize |
| 446 |
\def\verbatim@processline{\tab@position\tab@size |
| 447 |
\thelisting@line \global\advance\listing@line1 |
| 448 |
\toks@{}% |
| 449 |
\expandafter\verbatim@tabexpand\the\verbatim@line\@nil}% |
| 450 |
\@verbatim\frenchspacing\@vobeyspaces\@vobeytabs |
| 451 |
\def\verbatim@addtoline##1~{% |
| 452 |
\verbatim@line\expandafter{\the\verbatim@line##1}}% |
| 453 |
\openin\verbatim@in@stream=#3 |
| 454 |
\ifeof\verbatim@in@stream |
| 455 |
\PackageWarning{moreverb}{No file #3.}% |
| 456 |
\else |
| 457 |
\do@verbatimtabinput |
| 458 |
\closein\verbatim@in@stream |
| 459 |
\fi |
| 460 |
\endtrivlist\endgroup |
| 461 |
\@doendpe |
| 462 |
}% |
| 463 |
} |
| 464 |
% \end{macrocode} |
| 465 |
% \end{macro} |
| 466 |
% |
| 467 |
% \begin{macro}{verbatimcmd} |
| 468 |
% \texttt{verbatimcmd} was a verbatim environment with the exception |
| 469 |
% of the escape and grouping characters \verb+\+, \verb+{+, \verb+}+. |
| 470 |
% This is (err) exactly the specification of the \texttt{alltt} |
| 471 |
% environment, and that is in the \textsf{alltt} package that is now |
| 472 |
% part of the base distribution. |
| 473 |
% \begin{macrocode} |
| 474 |
\def\verbatimcmd{% |
| 475 |
\PackageError{moreverb}{The verbatimcmd environment is obsolete}% |
| 476 |
{Use alltt (from the LaTeX required package |
| 477 |
alltt) in place of verbatimcmd}% |
| 478 |
} |
| 479 |
\let\endverbatimcmd\relax |
| 480 |
% \end{macrocode} |
| 481 |
% \end{macro} |
| 482 |
% |
| 483 |
% \begin{environment}{boxedverbatim} |
| 484 |
% \texttt{boxedverbatim} puts the contents of a verbatim environment |
| 485 |
% in a framing box. |
| 486 |
% |
| 487 |
% (Written by Victor Eijkhout.) |
| 488 |
% |
| 489 |
% \noindent Bug fixes: |
| 490 |
% \begin{itemize} |
| 491 |
% \item David Carlisle 1995-12-28, dealing with spacing issues (iirc) |
| 492 |
% \item Moretn H\o gholm 2008-06-01, positioning of frame in lists |
| 493 |
% \end{itemize} |
| 494 |
% |
| 495 |
% First, redefine `processline' to produce only a line as wide |
| 496 |
% as the natural width of the line |
| 497 |
% |
| 498 |
% \begin{macrocode} |
| 499 |
\def\boxedverbatim{% |
| 500 |
\def\verbatim@processline{% |
| 501 |
{\setbox0=\hbox{\the\verbatim@line}% |
| 502 |
\hsize=\wd0 \the\verbatim@line\par}}% |
| 503 |
% \end{macrocode} |
| 504 |
% |
| 505 |
% Now save the verbatim code in a box |
| 506 |
% |
| 507 |
% \begin{macrocode} |
| 508 |
\@minipagetrue % DPC |
| 509 |
\@tempswatrue % DPC |
| 510 |
\@totalleftmargin\z@ % MH |
| 511 |
\setbox0=\vbox\bgroup \verbatim |
| 512 |
} |
| 513 |
% \end{macrocode} |
| 514 |
% |
| 515 |
% At the end of the environment, we (umm) simply have to stick the |
| 516 |
% results into a frame. |
| 517 |
% |
| 518 |
% \begin{macrocode} |
| 519 |
\def\endboxedverbatim{% |
| 520 |
\endverbatim |
| 521 |
\unskip\setbox0=\lastbox % DPC |
| 522 |
% \end{macrocode} |
| 523 |
% |
| 524 |
% Now everything's in the box, so we can close it\dots |
| 525 |
% \begin{macrocode} |
| 526 |
\egroup |
| 527 |
% \end{macrocode} |
| 528 |
% |
| 529 |
% To change the code for centring, the next line needs a spot of |
| 530 |
% hacking. |
| 531 |
% \begin{macrocode} |
| 532 |
\fbox{\box0}% |
| 533 |
} |
| 534 |
% \end{macrocode} |
| 535 |
% \end{environment} |
| 536 |
% |
| 537 |
% \begin{environment}{verbatimtab} |
| 538 |
% \env{verbatimtab}\oarg{tab width} |
| 539 |
% is a verbatim environment which expands tab characters; the optional |
| 540 |
% argument specifies the distance between tab stops. |
| 541 |
% |
| 542 |
% Executing \cs{obeylines} before looking for the optional argument |
| 543 |
% prevents an empty first line of the environment becoming a \cs{par} |
| 544 |
% token (this bug was reported by Werner Lemberg). |
| 545 |
% \begin{macrocode} |
| 546 |
\newenvironment{verbatimtab}{\obeylines\@verbatimtab}{\endtrivlist} |
| 547 |
% \end{macrocode} |
| 548 |
% |
| 549 |
% Process the optional argument of the |verbatimtab|, now that we have |
| 550 |
% protected ourselves from the dreaded \cs{par} tokens |
| 551 |
% \begin{macrocode} |
| 552 |
\newcommand\@verbatimtab[1][\verbatimtabsize]{% |
| 553 |
\do@verbatimtab{#1}{% |
| 554 |
\@verbatim\frenchspacing\@vobeyspaces\@vobeytabs\verbatim@start}% |
| 555 |
} |
| 556 |
% \end{macrocode} |
| 557 |
% \end{environment} |
| 558 |
% |
| 559 |
% \begin{macro}{\do@verbatimtab} |
| 560 |
% |
| 561 |
% Prepare a tabbing environment; \verb+#1+ is the value of the tab |
| 562 |
% size (generally, originally, an optional argument), \verb+#2+ is the |
| 563 |
% `startup commands' to execute once an appropriate definition of |
| 564 |
% \cs{verbatim@processline} has been established: |
| 565 |
% \begin{macrocode} |
| 566 |
\def\do@verbatimtab#1#2{% |
| 567 |
\tab@size=#1 |
| 568 |
\def\verbatim@processline{\tab@position\tab@size |
| 569 |
\toks@{}% |
| 570 |
\expandafter\verbatim@tabexpand\the\verbatim@line\@nil}% |
| 571 |
#2% |
| 572 |
} |
| 573 |
% \end{macrocode} |
| 574 |
% \end{macro} |
| 575 |
% |
| 576 |
% \begin{macro}{\verbatimtabinput} |
| 577 |
% \cs{verbatimtabinput}\oarg{tab width}\marg{file name} |
| 578 |
% is a file input version of the \texttt{verbatimtab} environment. |
| 579 |
% |
| 580 |
% We use the input stream acquired by the \textsf{verbatim} package; |
| 581 |
% we did after all require it to be loaded. (One has to admit that |
| 582 |
% the name of that stream isn't actually part of the package's defined |
| 583 |
% interface, but on the other hand there's no particular likelihood |
| 584 |
% that it will ever change.) |
| 585 |
% |
| 586 |
% We didn't (originally) use fancy features of \cs{newcommand} since |
| 587 |
% the definition was inside a group, and hence global. So \dots\ |
| 588 |
% `traditional' code to provide a command with an optional argument |
| 589 |
% (which may no longer be necessary): |
| 590 |
% |
| 591 |
% \begin{macrocode} |
| 592 |
\def\verbatimtabinput{% |
| 593 |
\@ifnextchar[%] |
| 594 |
{\@verbatimtabinput}% |
| 595 |
{\@verbatimtabinput[\verbatimtabsize]}} |
| 596 |
\begingroup |
| 597 |
\catcode`\~=\active \lccode`\~=`\^^M \lccode`\N=`\N |
| 598 |
\lowercase{\endgroup |
| 599 |
\def\@verbatimtabinput[#1]#2{\begingroup |
| 600 |
\do@verbatimtab{#1}{% |
| 601 |
\@verbatim\frenchspacing\@vobeyspaces\@vobeytabs}% |
| 602 |
\def\verbatim@addtoline##1~{% |
| 603 |
\verbatim@line\expandafter{\the\verbatim@line##1}}% |
| 604 |
\openin\verbatim@in@stream=#2 |
| 605 |
\ifeof\verbatim@in@stream |
| 606 |
\PackageWarning{moreverb}{No file #2.} |
| 607 |
\else |
| 608 |
\@addtofilelist{#2}% |
| 609 |
\do@verbatimtabinput |
| 610 |
\closein\verbatim@in@stream |
| 611 |
\fi |
| 612 |
\endtrivlist\endgroup\@doendpe}% |
| 613 |
} |
| 614 |
% \end{macrocode} |
| 615 |
% \end{macro} |
| 616 |
% |
| 617 |
% \begin{macro}{\do@verbatimtabinput} |
| 618 |
% Written-out (tail recursion) loop for reading the file |
| 619 |
% \begin{macrocode} |
| 620 |
\def\do@verbatimtabinput{% |
| 621 |
\read\verbatim@in@stream to \verbtab@line |
| 622 |
\ifeof\verbatim@in@stream |
| 623 |
\else |
| 624 |
\expandafter\verbatim@addtoline\verbtab@line |
| 625 |
\verbatim@processline |
| 626 |
\verbatim@startline |
| 627 |
\expandafter\do@verbatimtabinput |
| 628 |
\fi |
| 629 |
} |
| 630 |
%</moreverb> |
| 631 |
% \end{macrocode} |
| 632 |
% \end{macro} |
| 633 |
% |
| 634 |
% \Finale |
| 635 |
% |
| 636 |
\endinput |
| 637 |
% |
| 638 |
%% \CharacterTable |
| 639 |
%% {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 |
| 640 |
%% 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 |
| 641 |
%% Digits \0\1\2\3\4\5\6\7\8\9 |
| 642 |
%% Exclamation \! Double quote \" Hash (number) \# |
| 643 |
%% Dollar \$ Percent \% Ampersand \& |
| 644 |
%% Acute accent \' Left paren \( Right paren \) |
| 645 |
%% Asterisk \* Plus \+ Comma \, |
| 646 |
%% Minus \- Point \. Solidus \/ |
| 647 |
%% Colon \: Semicolon \; Less than \< |
| 648 |
%% Equals \= Greater than \> Question mark \? |
| 649 |
%% Commercial at \@ Left bracket \[ Backslash \\ |
| 650 |
%% Right bracket \] Circumflex \^ Underscore \_ |
| 651 |
%% Grave accent \` Left brace \{ Vertical bar \| |
| 652 |
%% Right brace \} Tilde \~} |