[comp.sources.d] v02i086: Determine Troff document type

anw@nott-cs.UUCP (04/12/88)

The referenced article in "comp.sources.misc" is Yet Another Attempt to
Construct Huge Pipes Automatically.  Here at Nottingham, all such attempts,
and indeed "*roff" themselves, have been superceded by a slightly different
technique.  The idea is that a document should, broadly speaking, itself
know what filters and packages it needs.  Thus, a typical document starts

		.\"tbl
		.\"eqn
		.\"roff -ms
		.\"
		.TL
		A Proof of Fermat's Last Theorem
		.AU
		... etc

(The syntax is ugly, but portable.)  This is faster than YAACHPA, both
for the computer and for humans, because only the first few lines of the
file need to be looked at.  It is cleverer than YAACHPA because new filters,
such as `.\"chess', can be added to the file whether or not YAACHPA knows
how to detect them, and because flags can be added that YAACHPA would find
very hard to produce automatically (`.\"refer -a -e').

	What I've told you so far can be implemented almost trivially as
a shell script using `sed'.  In fact, the local version, ingeniously named
`runoff', is written in C and does rather more than this.  It knows a lot
about peripherals, and so, given a "-T" flag, can decide whether "nroff" or
"troff" or "someotherroff" should be used, whether "col" should be used,
and so on.  Given a "-P" flag ("runoff -Plwriter files"), it not only sets
up the "tbl files | eqn | troff -ms -Tlwriter" pipe, but also spools the
output to the appropriate printer.  It has lots of extra flags, eg

 -C2	either as `.\"roff -ms -C2' in the document or as a flag to
	"runoff" means to make two copies,
 -A5	means `set the page and line lengths initially to format for A5
	output', again either as a semi-permanent feature of the document
	or as a command line flag,
 -L-A4.5-6 means `if the output device is the LaserWriter (which is the
	only device we have which is capable of such high jinks), format
	the document as though for A4.5 [halfway between A4 and A5], but
	print it compressed to A6, with four pages to each sheet of A4
	paper' (all the hard work for this is, of course, done in the LW).

	Virtually all the local text formatting is done via `runoff';  I
have scarcely used `nroff' or `troff' directly for years.  Comments
welcomed.  I would gladly supply the code, thus ensuring my place in
the "comp.sources.{misc|unix}" hall of fame, but it's not mine to give:
contact Dr D. R. Woodall, "drw@maths.nott.ac.uk".  He may be reluctant to
hand it out (he's not a CompSci specialist, virtually all his C being
learned the hard way while hacking DWB;  the code is not written for
portability;  and it's designed to work best with the locally hacked
versions of "troff", "tbl", etc), but you can try persuasion.  Failing that,
you get to roll your own;  it really isn't too difficult.

--
Andy Walker, Maths Dept., Nott'm Univ.
anw@maths.nott.ac.uk