% New version of \listing and \inputverbatim for LaTeX % Michal Jaegermann - June 1990 % % These macros derived from similar macros posted in September of 1989 by % Peter Burgess % New Zealand Government Department of Scientific and Industrial Research % Applied Mathematics Division % (SRWMXPB@WINDY.DSIR.GOVT.NZ) % % \listing modifed to a form \listing[#1]#2#3 where % #1 [optional] specifies how often line numbers should be printed; % a default value is 5, 0 will turn off line numbering % #2 is a value for an indent to be aplied to whole listing % #3 is a name of an input file - specify an extension, unless .tex % % \inputverbatim[#1]#2 is the same as \listing without line numbers % A default value for an optional indent is set to 0 % % \inputverbatim and \listing based on \listing from The TeXbook. % Some things were taken from LaTeX's verbatim environment. \def\uncatcodespecials{\def\do##1{\catcode`##1=12 }\dospecials}% \def\listing{\@ifnextchar[{\listv@rb}{\listv@rb[5]}}% \def\listv@rb[#1]#2#3{\if@minipage\else\vskip\parskip\fi% \begingroup\s@tupv@rblist#1#2 \frenchspacing\@vobeyspaces\input#3 \endgroup}% \def\inputverbatim{\@ifnextchar[{\inv@rb}{\inv@rb[\z@]}}% \def\inv@rb[#1]#2{\listv@rb[\z@]{#1}{#2}}% \newcount\lin@no% number of file lines listed \newcount\lin@rem% number of lines from the last number %first parameter - numbering step %second parameter - indent size for the whole included text \def\s@tupv@rblist#1#2{% \tt% \leftskip#2\rightskip\z@% \parindent\z@\parfillskip\@flushglue\parskip\z@% \def\par{\leavevmode\egroup\box0\endgraf}% \obeylines \uncatcodespecials% \catcode`\`=\active \catcode`\^^I=\active% \lin@no=0 \lin@rem=0 \everypar{% \ifnum#1>0 \advance\lin@no by1 \advance\lin@rem by1 \ifnum\lin@rem=#1 \lin@rem=0 \llap{\scriptsize\it\the\lin@no\ \ }% \fi\fi% \startb@x}}% \def\startb@x{\setbox0=\hbox\bgroup}% {\catcode`\`=\active \gdef`{\relax\lq}}% % code to make tabs work in verbatim. \newdimen\w \setbox0=\hbox{\tt\space} \w=8\wd0 % tab amount {\catcode`\^^I=\active% \gdef^^I{\leavevmode\egroup% \dimen0=\wd0 % the width so far, or since the previous tab \divide\dimen0 by\w \multiply\dimen0 by\w % compute previous multiple of \w \advance\dimen0 by\w % advance to next multiple of \w \wd0=\dimen0 \box0 \startb@x}} %% end