Article View: comp.text
Article #721Re: verbatim macros in latex
From: Peter Burgess
Date: Mon, 04 Sep 1989 10:14
Date: Mon, 04 Sep 1989 10:14
58 lines
2996 bytes
2996 bytes
In article <11181@boulder.Colorado.EDU>, hartzell@boulder.Colorado.EDU (George Hartzell) writes:
> I just picked up the verbatimfile style from the latex-style archive,
> and have to questions about it. First, the verbatimlisting
> environment doesn't number blank lines. Second, it doesn't seem to
> deal well with tabs...
Here are some macros I cobbled together from LaTeX, other's examples and the
TeXbook. They cope with both tabs and blank lines. It took me quite a while
to debug them, and I wouldn't stake my life on there not being any special
cases they don't cope with.
%---------------------- Cut Here -----------------------
% \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}
\newcommand{\inputverbatim}[1]{\if@minipage\else\vskip\parskip\fi
\begingroup\setupverbatim \frenchspacing\@vobeyspaces\input#1 \endgroup}
\newcommand{\listing}[1]{\if@minipage\else\vskip\parskip\fi
\begingroup\setuplist \frenchspacing\@vobeyspaces\input#1 \endgroup}
\newcount\lineno % the number of file lines listed
\newcommand{\setuplist}{\tt \lineno=0
\leftskip\@totalleftmargin\rightskip\z@
\parindent\z@\parfillskip\@flushglue\parskip\z@
\def\par{\leavevmode\egroup\box0\endgraf}
\obeylines \uncatcodespecials
\catcode`\`=\active \catcode`\^^I=\active
\everypar{\advance\lineno by1
\llap{\scriptsize\the\lineno\ \ }\startbox}}
\newcommand{\setupverbatim}{\tt
\def\par{\leavevmode\egroup\box0\endgraf}
\leftskip\@totalleftmargin\rightskip\z@
\parindent\z@\parfillskip\@flushglue\parskip\z@
\obeylines \uncatcodespecials
\catcode`\`=\active \catcode`\^^I=\active
\everypar{\startbox}}
{\catcode`\`=\active \gdef`{\relax\lq}}
% code to make tabs work in verbatim.
\newdimen\w \setbox0=\hbox{\tt\space} \w=8\wd0 % tab amount
\def\startbox{\setbox0=\hbox\bgroup}
{\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 \startbox}}
%------------------------ Cut Here ---------------------
Peter Burgess
New Zealand Government Department of Scientific and Industrial Research
Applied Mathematics Division
(SRWMXPB@WINDY.DSIR.GOVT.NZ)
Technical Details
Message-ID:
<650@windy.dsir.govt.nz>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!bionet!ames!uhccux!munnari.oz.au!comp.vuw.ac.nz!windy!srwmxpbReferences:
<11181@boulder.Colorado.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!bionet!ames!uhccux!munnari.oz.au!comp.vuw.ac.nz!windy!srwmxpb From: SRWMXPB@windy.dsir.govt.nz (Peter Burgess) Newsgroups: comp.text,cu.users.tex Subject: Re: verbatim macros in latex Message-ID: <650@windy.dsir.govt.nz> Date: 4 Sep 89 10:14:24 GMT References: <11181@boulder.Colorado.EDU> Organization: DSIR Wellington, NZ Lines: 58