From: garys@homer.ds.boeing.com
Newsgroups: comp.text.tex
Subject: Sumary, listing macros (Eplain verbatim)
Date: 28 Sep 92 23:20:30 GMT
Organization: Boeing Defense & Space Group

Macros available for your use:
listing    widelisting    eightwidelisting .

Sumary of posting responses.

I wanted to use TeX to list files to various laser printers independently of
unique host, printer, and printer queue commands.
I tried the latex verbatimfiles.sty (as modified by Russell) from the archive.
It kind of works for 80column portrait, but the page layout is a little odd.
The 132 column landscape gets told its too wide and messes up long lines,
besides having bad page layout.

I posted a request for a better solution in hopes that 
someone might have a ready scheme.

David Tanner <UFTANNER@nervm.nerdc.ufl.edu> helpfully replied with the
Eplain macros from Karl Berry.

The following modified Eplain macros enable one, through TeX, to list files.
Two simple example file types for which they can be used
are FORTRAN 80 column source files in portrait, 
and FORTRAN compiled listings files 132 columns wide in landscape.

They provide a method, independent of computer system and printer,
to output in a known non-proportionally-spaced clearly readable font 
with most desired characters present, ( verbatim )
with the text nicely page centered.
The primary assumption is that the TeX printer driver and queue are set up to
output basic TeX (with a capability for landscape for 132 col).

These have been tried in plain tex, but latex should? be ok.
                                   Dwight Rousu <dwight@sslvax.boeing.com>
% provided by David Tanner, modified by Dwight Rousu and David Tanner:
% ---------------------------- cut here ---------------------------------
%
% Karl Berry's Eplain has a nice listing macro for plain tex. You say
% \listing{filename.tex} and filename.tex gets typeset in \tt font using
% the current \hsize and \vsize.
% (This has been modified here to change \hsize and \vsize when needed.)
% Here is the relevant code:  (might benefit from even more comments?)
% This is
%%%%%%%%%%%%%%%%%%%%%% part of %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the ``extended plain'' TeX format that's described in
% TeX for the Impatient.  We assume plain has been loaded.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Written 1989, 1990 by (mostly) Karl Berry.
%
% The original macros are Copyright @copyright{} 1989, 1991 Free Software
% Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA under the terms
% of the GNU general public license (q.v.).
%
% Some macros were written and/or inspired by Paul Abrahams.
% Other sources (e.g., The TeXbook) are cited at the appropriate places.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Category codes, etc.
%
\def\makeactive#1{\catcode`#1 = \active \ignorespaces}%
\chardef\letter = 11
\chardef\other = 12
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The next macro is defined in The TeXbook, but it never made it
% into plain TeX.  \dospecials is defined there, though.
%
\def\uncatcodespecials{%
   \def\do##1{\catcode`##1 = \other}%
   \dospecials
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Swallow parameters.
%
\def\gobble#1{}%
%
\catcode`@ = \letter % So we can have private control sequences.
%
% In order to do anything with ^^L (=formfeed,<FF>) inside a macro, it must
% be made non-\outer.
%
\def^^L{\par}%
%
% Macros that produce output.
%
% \obeywhitespace makes both end-of-lines and spaces in the input be
% respected in the output.  Even spaces at the beginning of lines turn
% into blank space the size of the natural space of the current font.
% The reason why plain TeX's \obeyspaces does not do this last is that
% it produces actual space characters, i.e., glue, and glue is discarded
% at a (n output) line break, and so if line breaks in the input are
% line breaks in the output...
%
% Tabs are not affected by this; they will still produce glue.
%
\begingroup
   \makeactive\^^M \makeactive\ %No spaces or ^^M's from here on. ^^M = linefeed
\gdef\obeywhitespace{%
\makeactive\^^M\def^^M{\par\futurelet\next\@finishobeyedreturn}%
\makeactive\ \def {\ }%
%
% The group we use here is the one \obeywhitespace must be enclosed in.
% If we don't do this, then if the obeyed stuff ends in a newline, the
% indent produced by the definition of ^^M will make that line indented,
% even if it isn't the end of the paragraph.
%
\aftergroup\@removebox%
\futurelet\next\@finishobeywhitespace%
}%
%
% \@finishobeywhitespace eats any spaces and/or the end-of-line after
% the \obeywhitespace command itself.  The group here is the one that it
% itself creates.
%
\gdef\@finishobeywhitespace{{%
\ifx\next %
\aftergroup\@obeywhitespaceloop%
\else\ifx\next^^M%
\aftergroup\gobble%
\fi\fi}}%
%
% \@finishobeyedreturn is invoked at the end of every input line.  We
% check if the next thing is also a return, and, if so, insert extra
% space.  Then we start the next line.
%
\gdef\@finishobeyedreturn{%
\ifx\next^^M\vskip\blanklineskipamount\fi%
\indent%
}%
\endgroup
%
% The argument here is the space that we are supposed to eat after the
% \obeywhitespace command.
%
\def\@obeywhitespaceloop#1{\futurelet\next\@finishobeywhitespace}%
%
% This removes the last box, if it was an indentation box.
% (The main vertical list can never have been ``entirely contributed
% to the current page'' at this point, and it wouldn't make any sense to
% use \obeywhitespace in math mode, so \lastbox is legal.)
%
\def\@removebox{%
   \setbox0 = \lastbox
   \ifdim\wd0=\parindent
     \setbox2 = \hbox{\unhbox0}%
     \ifdim\wd2=0pt
       % Don't put it back: it was an indentation box.
       % This \ignorespaces ignores spaces after the group.
       \ignorespaces
     \else
       \box2 % Put it back: it wasn't empty.
     \fi
   \else
      \box0 % Put it back: it wasn't the right width.
   \fi
}%
%
% We allow for extra (possibly negative) space when we hit blank lines.
%
\newskip\blanklineskipamount
\blanklineskipamount = 0pt
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Verbatim listing ... well, almost verbatim.  We assume the font \tt
% has all the characters that will appear.  Control characters, except
% for tabs and form feeds (and returns) won't produce anything useful.
% Tabs produce a fixed amount of space, and form feeds produce a page
% break.
%
% This is based on Knuth's ideas in Appendix D of the TeXbook, p. 380.
% The argument should be a filename.
%
% if you need to do something more for your particular fonts and/or
% environment before the file is input, give a definition to
% \setuplistinghook.  If you want line numbers on the output, you can
% say \let\setuplistinghook = \linenumberedlisting.
%
\def\listing#1{%
   \eject%            make sure starting on blank page, so not over-full losses.
   \par \begingroup
   \@setuplisting
   \setuplistinghook
   \input #1
   \endgroup
}%
%
\let\setuplistinghook = \relax
%
\def\linenumberedlisting{%
  \ifx\lineno\undefined \innernewcount\lineno \fi
  \lineno = 0
  \everypar = {\advance\lineno by 1 \printlistinglineno}%
}%
\def\printlistinglineno{\llap{[\the\lineno]\quad}}%
%
%
% \uncatcodespecials must come before \obeywhitespace, lest a space
% character in the input produce character 32 from the \tt font.
%   (^^I is tab, ^^L is formfeed)
\def\@setuplisting{%
   \uncatcodespecials
   \obeywhitespace
   \makeactive\`
   \makeactive\^^I % ^^I==<tab>
   \def^^L{% ^^L==<FF>. Attempt to avoid blank page if encountered at page top
      \dimen@=\pagegoal \advance\dimen@ by -\pagetotal
      \ifdim\dimen@<\vsize \ifdim\dimen@>\z@ \vfill\eject \fi\fi}%
   \tt
}%
%
% Give definitions to the characters we want to be special.
%
% Have to do ` separately, so can use ` in the \catcode commands
% elsewhere.
%
{%
   \makeactive\`
   \gdef`{\relax\lq}% Defeat ligatures.
}%
{%
   \makeactive\^^I % ^^I==<tab>
   \tt
   \gdef^^I{\hskip8\fontdimen2\font \relax}%
}%
%
% read fonts that will be used:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Macro \readfont only reads in a specified font if it hasn't already
%  been defined. This saves time and disk i/o
%        example: \readfont\twelverm{cmr10}1
%  \twelverm is the name as known to TeX; cmr10 is the name of the .TFM
%   and .PK file; 1 is the \magstep it is read in at.
%
\def\readfont#1#2#3{\ifx #1\undefined \global\font#1=#2 scaled \magstep#3\fi}%
%
\readfont\tentt{cmtt10}0
\readfont\eighttt{cmtt8}0
% hook for printer drivers that accept it. t2 does not?
% \def\dothespecial{\special{landscape}}%
\def\dothespecial{}%
%
% dnr: Added following to set up with landscape wide listing in mind:
%      Sizes set here allow 132 character lines in the default 10pt font size.
%    (\global\hsize=9.60truein\global\vsize=6.50truein\global\hoffset-0.4truein
%      without the parskip,lineskip,baselineskip
%    will work, but lines per page doesnt match Vax FORTRAN listing 57 + header)
%     and the Vax FORTRAN header apparently has tabs forcing more than 132 char.
%     Note: vsize has to be large enough to capture the <FF> at the end of
%          each full page, or the clever setuplisting scheme here,
%          or else TeX gives blank page ejects every other page.
%     Caution: if used with other macros, should reset sizes on exit?
%
\newdimen\widehsize \widehsize=9.9truein % 9.9 for vax fortran header tab
\newdimen\widevsize \widevsize=8.1truein
\newdimen\widehoffset \widehoffset=-0.4truein
\newdimen\widevoffset \widevoffset=-0.8truein
%
\def\widelisting#1{%
%  \def\tt{\fam\ttfam\tentt}% activate to set 10 pt if not default
%  \textfont\ttfam=\tentt
%  \tt \relax
  \global\hsize=\widehsize
  \global\vsize=\widevsize
  \global\hoffset=\widehoffset
  \global\voffset=\widevoffset
  \global\parskip0ex \global\lineskip0ex \global\baselineskip2.20ex
  \noindent\nopagenumbers\global\parindent0.0em
  \dothespecial % for printer drivers as defined above if needed.
  \listing{#1}%
}%
% Now a further alternative, use the 8pt font for more spacing between lines.
%
\newdimen\eightwidehsize \eightwidehsize=9.9truein
\newdimen\eightwidevsize \eightwidevsize=7.9truein
\newdimen\eightwidehoffset \eightwidehoffset=0.00truein
\newdimen\eightwidevoffset \eightwidevoffset=-0.8truein
%
\def\eightwidelisting#1{%
  \def\tt{\fam\ttfam\eighttt}% 8 pt works, but seems smaller than necessary
  \textfont\ttfam=\eighttt
  \tt \relax
  \global\hsize=\eightwidehsize
  \global\vsize=\eightwidevsize
  \global\hoffset=\eightwidehoffset
  \global\voffset=\eightwidevoffset
  \global\parskip0ex\global\lineskip0ex\global\baselineskip2.60ex
  \noindent\nopagenumbers\global\parindent0.0em
  \dothespecial % for printer drivers as needed
  \listing{#1}%
}%
\catcode`@ = \other
% ---------------------------- cut here ---------------------------------
% end of dnr addition.  Usage: $tex listing
% tested on vax vms with       \widelisting{file}
% t2 postscript driver         $t2/script/landscape/queue=script_xxx listing
%
% The following lines are for testing width effect of 80 col and 132 col lines
% by listing THIS file using \listing{listing.tex} and \widelisting{listing.tex}
%        11111111112222222222333333333344444444445555555555666666666677777777778
%2345678901234567890123456789012345678901234567890123456789012345678901234567890
%    6                                                                  xxxxxxxx
%        The following lines are test lines to 132 characters.
%        They may get truncated or wrapped in transmission.
%                                                                                                  111111111111111111111111111111111
%        111111111122222222223333333333444444444455555555556666666666777 77777788888888889999999999000000000011111111112222222222333
%23456789012345678901234567890123456789012345678901234567890123456789012 45678901234567890123456789012345678901234567890123456789012
%        |         |         |         |         |         |         |         |         |         |         |         |         |