From: brown@ftms.UUCP (Vidiot)
Newsgroups: comp.lang.postscript,comp.text
Subject: groff output on A4 paper
Date: 10 Nov 92 20:36:02 GMT
Reply-To: brown@ftms.UUCP (Vidiot)
Organization: Vidiot's Other Hangout


One of the problems with troff is that it was designed for letter paper, the
size of which is 11 inches long (279.4 mm).  A4 paper is 11.69 inches (297 mm)
in length.  Printing letter documents, like man pages, on A4 paper results
in the output not being centered vertically on the paper.  If groff was defined
for letter and the output printed on A4 paper, part of it will get chopped.
If groff is defined for A4, then the output sits near the bottom of the paper
with lots of white space on top of the page.

If any document is going to be printed on both letter and A4 paper, like my
Star Trek: The Next Generation Program Guide, something had to be done to make
the output work on both sizes of paper.  In order to keep the guide formatted
exactly the same, the A4 output needed to be centered vertically and
horizontally.  The horizontal problem is easily solved from within the troff
source, but the vertical problem could not.  The groff program had to be told
that a different sized page was being used and at the same time, not affect
the current PostScript groff configuration.

The remainder of this posting is what I did to get the output to be standard
for both letter and A4 paper.  If you have no interest in this, you can go
on to the next article now.

In order to do what I have done, you must be using groff version 1.06.  Previous
versions of groff require modification to the groff sources.  Groff version
1.06 does not.

The first thing that needs to be done is create a new printer definition.  I
called the new PostScript printer "uk".  You can call it whatever you want,
but you must remember to change all future references from "uk" to whatever you
use.  The location where this is done is /usr/local/lib/groff/font.  This
location is site dependent.  Change the /usr/local/lib to wherever groff/font
resides on your system.  In that directory you will find a devps directory.
You will be making a copy of the devps contents into devuk.  So do:

	mkdir devuk
	cp -pR devps/* devuk

Some Unix OSs do not allow the -R (recursive) option.  In that case you will
need to make the devuk/generate directory and copy the devps/generate contents
into devuk/generate.

Next we need to modify the devuk/DESC file.  Edit it and change the paperlength
value to 816945.  That will move the margin up from the bottom of the A4 sheet
by an amount that will center (vertically) the letter sized output.

Now we need to tell groff which tmac file to preload.  When groff is normally
run, the tmac.ps file is loaded.  But, with the new device "uk", no tmac file
gets loaded.  Even if we copy/link the tmac.ps file to tmac.uk, it still doesn't
get loaded.  This results in many characters not being defined and fonts not
being found.  Change the current directory to the tmac directory by doing:

	cd ../tmac

If you do a listing, you will find all kinds of tmac files and a file called
troffrc.  This file is currently undocumented.  But it is the beast that is
looked at by groff to determine which tmac file to preload.  Edit troffrc
and make it look like:

	.\" Startup file for troff.
	.\" This is tested by pic.
	.nr 0p 0
	.\" Use .do here, so that it works with -C.
	.\" The groff command defines the .X string if the -X option was given.
	.ie r.X .do ds troffrc!ps tmac.Xps
	.el .do ds troffrc!ps tmac.ps
-->	.do ds troffrc!uk tmac.ps
	.do ds troffrc!dvi tmac.dvi
	.do ds troffrc!X75 tmac.X
	.do ds troffrc!X75-12 tmac.X
	.do ds troffrc!X100 tmac.X
	.do ds troffrc!X100-12 tmac.X
	.do ds troffrc!ascii tmac.tty
	.do ds troffrc!latin1 tmac.tty
	.do if d troffrc!\*[.T] \
	.	do mso \*[troffrc!\*[.T]]
	.do rm troffrc!ps troffrc!Xps troffrc!dvi troffrc!X75 troffrc!X75-12 \
-->	troffrc!X100 troffrc!X100-12 troffrc!uk
	.do tr \[char160]
	.\" Don't let blank lines creep in here.

Added/edited lines are marked with the -->

You are now done with the groff-1.06 modifications.  These mods are 100%
compatible with the standard distribution of groff.

The remaining problem has to do with horizontal placement.  The A4 paper is
narrower by about .23 inches (5.9 mm).  This really isn't too much too worry
about.  But if you want your output centered horizontally, the page offset
needs to be reset by 8.362 points to the left.  To make the groff sources
letter and A4 compatible, a command line flag can be set.  I personally
use K.  Since this is groff macro dependent, the following can be used as
as example:

	.ie \nK==1 .po 81.638p
	.el .po 1.25i

Since 1.25 inches equals 90 points, the 81.638p is 8.362 points to the left.
The ST:TNG program guide is a little different than this because of the macro
package that I use and the fact that I also do horizontal shifting of the
even and odd pages 1/4" toward the outside edge.  But, the result is the same.

Putting this all together, the groff program will be called with the following
added options on the command line:

	-Tuk -rK1

When printing on letter paper, the options are not used.

There it is, letter paper output on A4 paper...centered!

I hope this helps someone, even if one person.  If you have any questions or
problems, let me know.

My compliments to James Clark for an excellent troff/ditroff replacement
program and his 1.06 version couldn't have come at a better time, making
adding the uk device so easy.
-- 
harvard\
  ucbvax!uwvax!astroatc!ftms!brown  or  uu2.psi.com!ftms!brown
rutgers/
INTERNET: brown@wi.extrel.com  or  ftms!brown%astroatc.UUCP@cs.wisc.edu