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