Checksum: 55402
Lines: 101
Path: utzoo!sq!dns
From: dns@sq.uucp (David Slocombe)
Date: Wed, 24-Aug-88 17:38:13 EDT
Message-ID: <1988Aug24.173813.11041@sq.uucp>
Newsgroups: comp.text
Subject: Re: nroff/mm problem
Summary: It's a feature, but you can get what you want easily.
References: <372@seila.UUCP>
Reply-To: dns@sq.com (David Slocombe)
Distribution: na
Organization: SoftQuad Inc., Toronto
Keywords: .SP .sp top-of-page .DS/.DE

In article <372@seila.UUCP> don@seila.UUCP (Don Kossman) writes:
 
> how do you force nroff (using the mm macro package)
> to leave n spaces at the top of a page?  .sp and .SP seem
> to have no effect. 

The fact that .sp and .SP have no effect (normally) at the top of
a new page is an important feature of all macro packages that I know of.
TeX *must* have something similar. The reason is that the extra spaces
you usually want between blocks of text *within* a page are
undesirable when they happen to occur at the top of a new page.
Troff (or nroff) has a special pair of builtin requests for assisting
in this: .ns ("nospace": i.e.  ignore any space request until there
has been a line of actual text), and .rs ("restore space": cancel
the "nospace" mode).

The top of page traps of the macro packages do a ".ns" just before
exiting, so a ".sp" request that occurs immediately following will be
ignored.  The -mm ".SP" macro should normally be used because it does
a number of extra useful things, but it calls ".sp" so the above applies to
it too.

Now, having defended the *normal* behaviour of -mm with troff (or
nroff), I'd better show how to get the specific effect you want:

With -mm I think the most intuitively natural is:

	.DS
	.SP 2i \" or whatever: i.e. we have a contiguous block of whitespace.
	.DE

But there are several other quite sensible ways to do it.  The
following troff (or nroff) input illustrates both the normal
behaviour and various ways of achieving the effect you want:

	.P
	This is on Page 1 (at top).
	.sp \n(.tu-0.5v  \" (This ensures that next line is last on page.)
	And this is the last line on Page 1.
	.\" The page traps set you up at the top of a new page here.
	.sp 2i \" (ignored, because "nospace" (.ns) is in effect.)
	This is on Page 2 (at top, correctly, though you wish it weren't).
	.sp \n(.tu-0.5v
	And this is the last line on Page 2.
	.SP 2i \" (same effect as .sp, above)
	This is on Page 3 (at top, correctly, though you wish it weren't).
	.sp \n(.tu-0.5v
	And this is the last line on Page 3.
	.\"
	.\" OK, now we force blank space at the top of a page:
	.\"
	.br \" needed to force above line to end and spring page-trap 
	.rs \" This is first line processed after top-of-page trap
	.sp 2i \" and lo! this works now!
	This is on Page 4 (2 inches down, as it should be).
	.sp \n(.tu-0.5v
	And this is the last line on Page 4.
	.br
	.rs
	.SP 2i (same effect as .sp above)
	This is on Page 5 (2 inches down, as it should be).
	.sp \n(.tu-0.5v
	And this is the last line on Page 5.
	.\" ---------------------------------------------------------------
	.\" The following two examples are conceptually better for -mm users:
	.\" ---------------------------------------------------------------
	.DS
	.sp 2i
	.DE
	This is on Page 6 (2 inches down, as it should be).
	.sp \n(.tu-0.5v
	And this is the last line on Page 6.
	.DS
	.SP 2i
	.DE
	This is on Page 7 (2 inches down, as it should be).
	.P
	And that's all folks!

Finally, my colleague Murray Maloney has pointed out that if you
want to put some extra white space at the top of *every* page (below
the page header), you can define the special "user-exit" macro "PX"
at the start of the document, thus:

	.de PX
	.rs
	'sp 5 \" or whatever: note the "'" no-break control character
	..

This macro is automatically called by the top-of-page trap just before
it exits. (Actually the top-of-page macro does a ".ns" to establish
nospace mode *again* after calling .PX just in case you've done
something like the above, to ensure that "accidental" space is
ignored at the top of page.)

----------------------------------------------------------------
David Slocombe				(416) 963-8337
Vice-President, Research & Development
SoftQuad Inc.				uucp: {uunet!attcan!utzoo, utai}!sq!dns
720 Spadina Ave.			Internet: dns@sq.com
Toronto, Ontario, Canada M5S 2T9
