\message{: version 26feb98}
%% Since some of verbatim's definitions rely on ^^M being interpreted as
%% a <return>, verbatim must be included before Knuth's index-making scheme, 
%% in index.tex, is initialized as the latter changes the meaning of ^ outside
%% math mode.

%% here is a button for adjusting the spacing of lines between \begintt ..
%  \endtt
\newdimen\spacingskip\spacingskip-1pt

% After including this file, called  verbatim.tex , by saying
%   \input verbatim
% anything in a line of text fenced like | ... | will be typeset verbatim, 
% in \tt , EXCEPT, of course, a vertical bar. If, e.g., the material  ... to be
% typeset verbatim is  ... a || b ... , then one must use 
%    | ... a |\|\|| b ... |
% to get those two vertical bars done in \tt.
% A complaint about things inside such fences, like a switch to mathmode for
% a caret, or an undefined macro for a backslash, are sure signs that some
% such fence is missing its partner, or that the text was first read in as
% the argument to some macro, in which case the basic scheme used, namely the
% undoing of the special catcodes for special symbols, is defeated since you
% cannot change such catcodes once the character has been read.

%     Anything fenced like | ... | in *mathmode* will be included in 
% absolute-value signs, as is customary.
% For the rare occasion that a computer-word is to appear in math mode, i.e.,
% between dollar signs, you have to revert to putting it explicitly inside 
% braces with a font change to \tt. Unfortunately, this won't work in
% scriptstyle, i.e., when the word is to appear in a sub- or superscript.
% For that, use something like
\def\scw#1{\hbox{\stt #1}}
\font\stt = cmtt8 %at 7pt

%     If entire lines (e.g., program listings) are to be typeset verbatim,
% bracket instead that material by the macros \begintt and \endtt.
% Anything between two such matching macros will be typeset in \tt and
% verbatim, including blanks, with the following EXCEPTIONS:
% (1) Any single vertical bar |  will be interpreted as the escape character,
% hence TeX will think that a macro is being called for. Therefore, to have
% a single vertical bar appear in the output as a single vertical bar, you must 
% double it in the file, i.e., have there  || (to enforce its being done 
% verbatim).  
% (2) Any lines containing 0 or more blanks (and nothing else) will be skipped
% since only something nonblank is taken as the start of a new paragraph).
% If you want to have such a blank line appear in the printed text, replace
% it in the file by the line 
% |strut
% (E.g., in vi, the following global replacement would do this 
%  :<range of stuff>s/^ *$/|strut/
% for all such lines.)

% After a painful attempt at getting this right from scratch, de Boor reverted 
% to a detailed study of the \TeX-file for Knuth's \TeX-book (see excerpt at 
% the end of this file), with the macros below as the result.

%    Note that users might experience some difficulties of a very obscure kind
% if they use standard math macros like  \|  instead of their wordy equivalents
% like \Vert .  E.g., try to explain the printout resulting from \TeX-ing the 
% following statements:
%  \def\norm#1{\|#1\|}
%  \input verbatim
%  $\norm{B}$
%  $\norm{G}$
%  \bye
% Or, try to explain the fontchange effect of the following:
% $$\eqalign{|f(x)|&=|f(x)|\cr}$$



\chardef\other=12{}\chardef\active=13{}
\def\undospecials{\catcode`\\=\other \catcode`\{=\other
  \catcode`\}=\other \catcode`\$=\other \catcode`\&=\other
  \catcode`\#=\other \catcode`\%=\other \catcode`\~=\other
  \catcode`\_=\other \catcode`\^=\other \obeyspaces}
% This makes | into a control sequence, and this causes trouble when we
% want to print a vertical bar in \tt, particularly since \|, at present,
% demands to be in math mode (where it is part of a norm sign). So,
\def\|{\ifmmode\def\next{\delimiter"26B30D}%
\else\def\next{{\tt\char'174}}\fi\next}

\outer\def\begindisplay{\obeylines\startdisplay}
{\obeylines\gdef\startdisplay#1
  {\catcode`\^^M=5$$#1\halign\bgroup\indent##\hfil&&\qquad##\hfil\cr}}
\outer\def\enddisplay{\crcr\egroup$$}
%\smallbreak
\def\ttverbatim{\begingroup\undospecials\obeyspaces\obeylines%
\everypar{\strut\hskip-\parindent }\tt}
{\obeyspaces\gdef {\ }} % \obeyspaces now gives \ , not \space
%\smallbreak
\outer\def\begintt{$$\let\par=\endgraf \ttverbatim \parskip=\spacingskip
  \catcode`\|=0 \rightskip=-5pc \ttfinish}
{\catcode`\|=0 |catcode`|\=\other % | is temporary escape character
  |obeylines % end of line is active
  |gdef|ttfinish#1^^M#2\endtt{#1|vbox{#2}|endgroup$$}}
%\smallbreak
\newskip\ttglue\ttglue=.5em plus.25em minus.15em
\catcode`\|=\active
{\obeylines\gdef|{\ifmmode\def\next{\char`\|}\else%
  \def\next{\ttverbatim\spaceskip=\ttglue\let^^M=\ \let|%
  =\endgroup}\fi\next}}
% In the last definition of the now active | , I had to insert the
% alternative in case of math mode since, otherwise, the absolute value
% signs (and restriction signs and the like) in math formulae would not
% have printed. Note that use of \vert and \Vert can resolve some trouble
% in cases where the absolute value or norm is actually meant.

% Next, getting some lines printed nicely, albeit without those hrules Knuth
% uses ....
\def\beginlines{\par\bgroup\nobreak\medskip\parindent=0pt
  \nobreak \obeylines \everypar{\strut}}
\def\endlines{\egroup\medbreak\noindent}

%  (Well, in the end, the material from the TeXbook contained a perfectly
% good alternative to the following definitions, hence, these are now in
% percents.)
%%\def\specialbar{\ifmmode\def\next{|}\else\def\next{\ttMT}%
%%\begingroup\catcode`\|=\other\undospecials\fi\next}
%%\def\ttMT#1|{\tt#1\endgroup\catcode`\|=\active}
%%\catcode`\|=\active \let|=\specialbar
%% (Note that all special characters
%% need to be made unspecial BEFORE the argument of \ttMT is read.
%% Note also that the reading of the definition of \undospecial occurs
%% before all these changes take effect; e.g., \ remains the escape 
%% character while the definition is read; it is only when it is executed
%% that it loses that distinction. For the same reason, the definition of
%% \ttMT is read flawlessly.
%% Also, it seems that any active character is substituted for at once,
%% hence it was necessary to make | inactive before the argument of \ttMT
%% is read.

%%% below is the material from the TeXbook, for easy reference.
%%\beginlines
%%|\outer\def\begindisplay{\obeylines\startdisplay}|
%%|{\obeylines\gdef\startdisplay#1|
%%|  {\catcode`\^^M=5$$#1\halign|^|\bgroup||\indent##\hfil&&\qquad##\hfil\cr}}|
%%|\outer\def\enddisplay{|^|\crcr|^|\egroup||$$}|^^{dollardollar}
%%\smallbreak
%%^|\chardef|^|\other||=12|
%%|\def\ttverbatim{\begingroup \catcode`\\=\other \catcode`\{=\other|
%%|  \catcode`\}=\other \catcode`\$=\other \catcode`\&=\other|
%%|  \catcode`\#=\other \catcode`\%=\other \catcode`\~=\other|
%%|  \catcode`\_=\other \catcode`\^=\other|
%%|  \obeyspaces \obeylines \tt}|
%%|{|^|\obeyspaces||\gdef {\ }} % \obeyspaces now gives \ , not \space|
%%\smallbreak
%%|\outer\def\begintt{$$\let\par=\endgraf \ttverbatim \parskip=0pt|
%%|  \catcode`\|\||=0 |^|\rightskip||=-5pc \ttfinish}|
%%|{\catcode`\|\||=0 |\||catcode`|\||\=\other % |\|%
%%  | is temporary escape character|
%%|  |\||obeylines % end of line is active|
%%|  |\||gdef|\||ttfinish#1^^M#2\endtt{#1|\||vbox{#2}|\||endgroup$$}}|
%%\smallbreak
%%^|\newskip||\ttglue|^^{atsign}
%%|  \ttglue=.5em plus.25em minus.15em|
%%^|\catcode||`\|\||=|^|\active|
%%|{\obeylines\gdef|\||{\ttverbatim\spaceskip=\ttglue\let^^M=\ \let|\|%
%%  |=\endgroup}}|\kern-.3pt
%%\endlines
%%\beginlines
%%|\def\beginlines{\par\begingroup\nobreak\medskip\parindent=0pt|
%%\nobreak
%%|  |^|\hrule||\kern1pt\nobreak \obeylines |^|\everypar||{\strut}}|
%%|\def\endlines{\kern1pt\hrule\endgroup\medbreak\noindent}|
%%\endlines
%%  stuff for indexmaking, used here to model | ... |
%%\beginlines
%%^|\newif||\ifsilent|
%%|\def\specialhat{\ifmmode\def\next{^}\else\let\next=\beginxref\fi\next}|
%%|\def\beginxref{|^|\futurelet||\next\beginxrefswitch}|
%%|\def\beginxrefswitch{\ifx\next\specialhat\let\next=\silentxref|
%%|  \else\silentfalse\let\next=\xref\fi \next}|
%%|\catcode`\^=\active \let ^=\specialhat|
%%|\def\silentxref^{\silenttrue\xref}|
%%\endlines

