185 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			TeX
		
	
	
	
			
		
		
	
	
			185 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			TeX
		
	
	
	
%%% moreverb.sty
 | 
						|
%%% AJCD 20 Sep 91
 | 
						|
%%% adds various verbatim environments using Rainer Sch\"opf's new verbatim
 | 
						|
%%% environment.
 | 
						|
 | 
						|
%%% load verbatim style if not already loaded.
 | 
						|
\@ifundefined{verbatim@processline}{\input verbatim.sty}{}
 | 
						|
 | 
						|
%%% verbatimwrite writes all text in its body to a file, the name of which it
 | 
						|
%%% is given as an argument. Written by RmS.
 | 
						|
\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}
 | 
						|
 | 
						|
\def\endverbatimwrite{%
 | 
						|
  \immediate\closeout\verbatim@out
 | 
						|
  \@esphack}
 | 
						|
 | 
						|
%%% Auxiliary macros and counters for expanding tabs. Use by listing and
 | 
						|
%%% verbatimtab environments.
 | 
						|
\newcount\tab@position \newcount\tab@size
 | 
						|
\newcount\verbatimtabsize \verbatimtabsize=8
 | 
						|
\def\@xobeytab{\leavevmode\penalty\@M
 | 
						|
   {\loop\ \global\advance\tab@position-1 \ifnum\tab@position>0 \repeat}}
 | 
						|
\begingroup
 | 
						|
  \catcode`\^^I=\active
 | 
						|
  \gdef\@vobeytabs{\catcode`\^^I\active\let^^I\@xobeytab}%
 | 
						|
\endgroup
 | 
						|
\def\verbatim@tabexpand#1{%
 | 
						|
  \ifx#1\@nil \let\next\par \else
 | 
						|
    \ifx#1\@xobeysp \@xobeysp\advance\tab@position-1 \else
 | 
						|
    \ifx#1\@xobeytab \@xobeytab\else
 | 
						|
       #1\advance\tab@position-1
 | 
						|
    \fi\fi
 | 
						|
    \ifnum\tab@position=0 \tab@position\tab@size \fi
 | 
						|
    \let\next\verbatim@tabexpand
 | 
						|
  \fi\next
 | 
						|
}
 | 
						|
 | 
						|
%%% listing defines a verbatim environment with numbered lines; it takes an
 | 
						|
%%% optional argument specifying the number of lines between numbered
 | 
						|
%%% lines, and a mandatory argument specifying the starting line. listingcont
 | 
						|
%%% continues from the place where listing left off.
 | 
						|
%%% The style in which the label is set can be altered by re-defining
 | 
						|
%%% \listinglabel. * versions are provided.
 | 
						|
\newcount\listing@line \listing@line=1 \newcount\listing@step \listing@step=1
 | 
						|
% Adding an \hbox in front of the line causes a line break, so I go
 | 
						|
% through this rigmarole to get the lines aligned nicely. I probably
 | 
						|
% missed some obvious reason why \hboxes don't work.
 | 
						|
\def\listinglabel#1{\rlap{\small\rm\the#1}\hskip2.5em}
 | 
						|
\def\thelisting@line{%
 | 
						|
  \setbox0\hbox{\listinglabel\listing@line}%
 | 
						|
  \@tempcnta=\listing@line
 | 
						|
  \divide\@tempcnta\listing@step \multiply\@tempcnta\listing@step
 | 
						|
  \ifnum\listing@line=1 \unhbox0
 | 
						|
  \else \ifnum\@tempcnta=\listing@line \unhbox0
 | 
						|
  \else \hskip\wd0
 | 
						|
  \fi\fi}
 | 
						|
\def\listing{\@ifnextchar[{\@listing}{\@listing[1]}}
 | 
						|
\def\@listing[#1]#2{%
 | 
						|
  \global\listing@line=#2\global\listing@step=#1\listingcont}
 | 
						|
\def\listingcont{%
 | 
						|
  \tab@size=\verbatimtabsize
 | 
						|
  \def\verbatim@processline{\tab@position\tab@size
 | 
						|
    \thelisting@line \global\advance\listing@line1
 | 
						|
    \expandafter\verbatim@tabexpand\the\verbatim@line\@nil}%
 | 
						|
  \@verbatim\frenchspacing\@vobeyspaces\@vobeytabs\verbatim@start}
 | 
						|
\let\endlisting=\endtrivlist
 | 
						|
\let\endlistingcont=\endtrivlist
 | 
						|
\@namedef{listing*}{\@ifnextchar[{\@listingstar}{\@listingstar[1]}}
 | 
						|
\def\@listingstar[#1]#2{%
 | 
						|
  \global\listing@line=#2\global\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}
 | 
						|
\expandafter\let\csname endlisting*\endcsname =\endtrivlist
 | 
						|
\expandafter\let\csname endlistingcont*\endcsname =\endtrivlist
 | 
						|
 | 
						|
%%% file input version of listing
 | 
						|
\def\listinginput{%
 | 
						|
   \@ifnextchar[{\@listinginput}{\@listinginput[1]}}
 | 
						|
{\catcode`\~=\active \lccode`\~=`\^^M \lccode`\N=`\N
 | 
						|
 \lowercase{%
 | 
						|
  \gdef\@listinginput[#1]#2#3{\begingroup
 | 
						|
     \global\listing@line=#2\global\listing@step=#1
 | 
						|
     \tab@size=\verbatimtabsize
 | 
						|
     \def\verbatim@processline{\tab@position\tab@size
 | 
						|
        \thelisting@line \global\advance\listing@line1
 | 
						|
        \expandafter\verbatim@tabexpand\the\verbatim@line\@nil}%
 | 
						|
     \@verbatim\frenchspacing\@vobeyspaces\@vobeytabs
 | 
						|
     \def\verbatim@addtoline##1~{%
 | 
						|
        \verbatim@line\expandafter{\the\verbatim@line##1}}%
 | 
						|
     \openin\verbtab@in=#3
 | 
						|
     \ifeof\verbtab@in\typeout{No file #3.}\else
 | 
						|
       \verbtab@oktrue
 | 
						|
       \loop
 | 
						|
          \read\verbtab@in to \verbtab@line
 | 
						|
          \ifeof\verbtab@in\verbtab@okfalse\else
 | 
						|
             \expandafter\verbatim@addtoline\verbtab@line
 | 
						|
             \verbatim@processline
 | 
						|
             \verbatim@startline
 | 
						|
          \fi
 | 
						|
       \ifverbtab@ok\repeat
 | 
						|
       \closein\verbtab@in\fi
 | 
						|
     \endtrivlist\endgroup\@doendpe}}}
 | 
						|
 | 
						|
%%% verbatimcmd is a verbatim environment with the exception of the escape and
 | 
						|
%%% grouping characters \, {, }.
 | 
						|
\def\verbatimcmd{%
 | 
						|
  \@verbatim \catcode`\\=0 \catcode`\{=1 \catcode`\}=2
 | 
						|
  \frenchspacing\@vobeyspaces\verbatim@start
 | 
						|
}
 | 
						|
\def\endverbatimcmd{%
 | 
						|
  \let\par\relax
 | 
						|
  \def\verbatim@{\endtrivlist\endgroup}%
 | 
						|
  \begingroup}
 | 
						|
 | 
						|
%%% boxedverbatim produces a verbatim environment in a framed box.
 | 
						|
%%% written by Victor Eijkhout
 | 
						|
\def\boxedverbatim{%
 | 
						|
  % redefine `processline' to produce only a line as wide
 | 
						|
  % as the natural width of the line
 | 
						|
  \def\verbatim@processline{%
 | 
						|
    {\setbox0=\hbox{\the\verbatim@line}%
 | 
						|
    \hsize=\wd0 \the\verbatim@line\par}}%
 | 
						|
  % save the verbatim code in a box
 | 
						|
  \setbox0=\vbox\bgroup \verbatim
 | 
						|
}
 | 
						|
\def\endboxedverbatim{%
 | 
						|
  \endverbatim
 | 
						|
  \egroup % close the box and `fbox' it
 | 
						|
  \fbox{\box0}% <<<=== change here for centering,...
 | 
						|
}
 | 
						|
 | 
						|
%%% verbatimtab is a verbatim environment which expands tab characters; it
 | 
						|
%%% takes an optional argument specifying the width of tab stops
 | 
						|
\def\verbatimtab{\futurelet\next\@verbatimtab}
 | 
						|
\def\@verbatimtab{\if\next[ \let\next\@@verbatimtab\else
 | 
						|
                     \def\next{\@@verbatimtab[\the\verbatimtabsize]}\fi\next}
 | 
						|
\def\@@verbatimtab[#1]{%
 | 
						|
  \do@verbatimtab{#1}{%
 | 
						|
     \@verbatim\frenchspacing\@vobeyspaces\@vobeytabs\verbatim@start}%
 | 
						|
}
 | 
						|
\def\do@verbatimtab#1#2{%
 | 
						|
  \tab@size=#1
 | 
						|
  \def\verbatim@processline{\tab@position\tab@size
 | 
						|
     \expandafter\verbatim@tabexpand\the\verbatim@line\@nil}#2
 | 
						|
}
 | 
						|
\let\endverbatimtab=\endtrivlist
 | 
						|
 | 
						|
%%% file input version of verbatimtab
 | 
						|
\newread\verbtab@in \newif\ifverbtab@ok
 | 
						|
\def\verbatimtabinput{%
 | 
						|
   \@ifnextchar[{\@verbatimtabinput}{\@verbatimtabinput[\the\verbatimtabsize]}}
 | 
						|
{\catcode`\~=\active \lccode`\~=`\^^M \lccode`\N=`\N
 | 
						|
 \lowercase{%
 | 
						|
  \gdef\@verbatimtabinput[#1]#2{\begingroup
 | 
						|
     \do@verbatimtab{#1}{%
 | 
						|
       \@verbatim\frenchspacing\@vobeyspaces\@vobeytabs}%
 | 
						|
     \def\verbatim@addtoline##1~{%
 | 
						|
        \verbatim@line\expandafter{\the\verbatim@line##1}}%
 | 
						|
     \openin\verbtab@in=#2
 | 
						|
     \ifeof\verbtab@in\typeout{No file #2.}\else
 | 
						|
       \verbtab@oktrue
 | 
						|
       \loop
 | 
						|
          \read\verbtab@in to \verbtab@line
 | 
						|
          \ifeof\verbtab@in\verbtab@okfalse\else
 | 
						|
             \expandafter\verbatim@addtoline\verbtab@line
 | 
						|
             \verbatim@processline
 | 
						|
             \verbatim@startline
 | 
						|
          \fi
 | 
						|
       \ifverbtab@ok\repeat
 | 
						|
       \closein\verbtab@in\fi
 | 
						|
     \endtrivlist\endgroup\@doendpe}}}
 |