🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.text.tex
Article #2031

(long) code listings: LaTeX + rotate + 2-column + verbatim???

#2031
From: Jonathan Thornburg
Date: Thu, 03 Sep 1992 10:05
119 lines
5618 bytes
I would like to include listings of some C programs in a LaTeX
document (my thesis).  My difficulties come from the combination
of the following constraints:
- ~30K lines of C spread across ~100 files.  In the format I'm
  planning (see below) this will occupy ~350 pages.  [No, I can't
  include a microfiche listing instead :-( ]
- Files to be listed are C code ==> contain lots of tabs and { }
  characters, which means TeX can't handle them without verbatim
  mode.  I'm using a slightly-hacked version of  verbatim.sty  by
  Michael Fine (thanks, Michael), which handles tabs very nicely
  and can also verbatim-typeset external files via  \inputverbatim .
- Running headers (including page numbers) should be LaTeX-generated.
- I want the listings to be in a monopitch font -- TeX \tt would
  be perfect.
- I need to fit 2 columns of listing on each page.  (This gives
  ~100 lines of code per page ==> ~350 pages counting partial
  page losses.)  To keep the aspect ratio reasonable I need to
  do the columns in "2-up" style, rotated 90 degrees and with
  a very small \tt font.  (By using  rotate.sty  I can easily
  rotate TeX *boxes*.)
- It would be very nice if each file could get an entry in some
  "file index" table, but this isn't absolutely 100% essential.
- It would be very nice if each (sideways) listing column were
  headed by a  pr(1) - like  header giving the directory/file
  name.  But I don't want the file timestamp -- no one is going
  to be running  make  from the listing.
- There need (should) be nothing on the pages except for the
  running headers and the listings and their headings, if any.
  In particular, I don't need any captions or annotations on
  the listings.  Line numbers might be nice, but they're not
  essential.
- I don't need any fancy "break pages at function ends" type
  context-sensetive formatting, just the equivalent of what
   pr(1)  and  lwf(1)  would produce for 2-up, but integrated
  into the LaTeX running headers/page numbers.
- I am using a dvips (Rybicki's) which has excellent Postscript-
  inclusion facilities.
- "Photocopier surgery" is out unless *absolutely* required.
  I want the final result to be a postscript file or files that
  can be printed on any standard postscript printer.



So far as I can see, the requirement that the running headers
and page numbers be LaTeX-generated means that it would be awkard
to use  pr(1)  and/or  lwf(1)  to produce a  2-up  foo.ps  for
each  foo.c , then include this via a dvips \special.  This is
because (so far as I can see) when TeX processes the \special it
has no way to know what's inside, and hence no way to emit the
right number of to-it-blank pages, even if the included postscript
could somehow be merged onto those pages.

I probably *could* use this trick for a fits-on-one-page listing,
though.  I could then use a shell/awk script to split each file
into fits-on-one-page chunks, and bring each one into TeX with a
separate \special.  This would probably work, but it would be an
awful kludge.

Instead, it seems to me that the best way to go is to have the
actual listings be in a LaTeX verbatim mode.  (This also makes it
easier to control fonts, line numbers, & other bells & whistles.)
Now the problem is to combine rotation by 90 degrees with long
listings.



If it weren't for the rotate, I believe I could just say

	\begingroup
	\twocolumn
	\scriptsize
	\verbatiminput{file1.c}
	\verbatiminput{file2.c}
	\verbatiminput{file3.c}
	...
	\endgroup

except for the listing-column headers, and these could be faked
with a simple shell/awk script to stick them onto temporary copies
of the C files.  I don't know if this would run into TeX memory
problems due to it wanting to read an entire verbatim environment
(=  \verbatiminput  command), but I think not.  However, this doesn't
accomplish the 90 degree rotation of each (2-column) page of listings.



If I only had one page of listings, I believe I could say

	\rotate{%%%
	\vbox{%%%
	\twocolumn
	\scriptsize
	\verbatiminput{files.h}
	}%%%			% end of \vbox
	}%%%			% end of \rotate

However, I don't see how this can work for more than one page of
listinghs, because  \rotate  can only rotate (single) TeX *boxes*,
and I don't think a multipage listing can be a (single) box.

Again, I could use a shell/awk script to split each C file into
fit-on-a-page chunks, then use this one-page-of-listings technique
on each chunk.  I believe this would work, but again it's an awful
kludge.



Before I try one of the "awful kludge" solutions, can anyone suggest
an easier way? That is, is there an easier (easy?) way to typeset
multi-page rotated 2-column verbatim text in LaTeX?



Thank you,

- Jonathan Thornburg
  <jonathan@einstein.ph.utexas.edu> or <jonathan@hermes.chpc.utexas.edu>
  University of Texas at Austin / Physics Dept / Center for Relativity
  and (for a few more months) U of British Columbia / {Astronomy,Physics}
Technical Details
Message-ID: <1992Sep3.100519.5663@chpc.utexas.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!hermes.chpc.utexas.edu!jonathan

Show Full Headers
Complete Article Headers
Newsgroups: comp.text.tex
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!hermes.chpc.utexas.edu!jonathan
From: jonathan@chpc.utexas.edu (Jonathan Thornburg)
Subject: (long) code listings: LaTeX + rotate + 2-column + verbatim???
Message-ID: <1992Sep3.100519.5663@chpc.utexas.edu>
Summary: how to do long 2:1 reduced \tt rotated-90-degrees listings in LaTeX?
Keywords: LaTeX rotate multicolumn verbatim program code listing
Sender: jonathan@einstein.ph.utexas.edu
Organization: U of Texas at Austin / Physics Dept / Center or Relativity
Date: Thu, 3 Sep 92 10:05:19 GMT
Lines: 119