Bell 32V development
[unix-history] / usr / doc / trofftut / tt09
CommitLineData
43b33daf
TL
1.NH
2Titles, Pages and Numbering
3.PP
4This is an area where things get tougher,
5because nothing is done for you automatically.
6Of necessity, some of this section is a cookbook,
7to be copied literally until you get some experience.
8.PP
9Suppose you want a title at the top of each page,
10saying just
11.sp 3p
12.lt 2.8i
13.tl '~~~~left top'center top'right top~~~~'
14.lt
15.sp 3p
16In
17.UL roff ,
18one can say
19.P1 2
20^he 'left top'center top'right top'
21^fo 'left bottom'center bottom'right bottom'
22.P2
23to get headers and footers automatically on every page.
24Alas, this doesn't work in
25.UL troff ,
26a serious hardship for the novice.
27Instead you have to do a lot of specification.
28.PP
29You have to say what the actual title is (easy);
30when to print it (easy enough);
31and what to do at and around the title line (harder).
32Taking these in reverse order,
33first we define a macro
34.BD .NP
35(for `new page') to process
36titles and the like at the end of one page
37and the beginning of the next:
38.P1
39^de NP
40\(fmbp
41\(fmsp 0.5i
42\&.tl 'left top'center top'right top'
43\(fmsp 0.3i
44^^
45.P2
46To make sure we're at the top of a page,
47we issue a `begin page' command
48.BD \(fmbp ,
49which causes a skip to top-of-page
50(we'll explain the
51.BD \(fm
52shortly).
53Then we space down half an inch,
54print the title
55(the use of
56.BD .tl
57should be self explanatory; later we will discuss parameterizing the titles),
58space another 0.3 inches,
59and we're done.
60.PP
61To ask for
62.BD .NP
63at the bottom of each page,
64we have to say something like
65`when the text is within an inch
66of the bottom of the page,
67start the processing
68for a new page.'
69This is done with a `when' command
70.BD .wh :
71.P1
72^wh \-1i NP
73.P2
74(No `.' is used before NP;
75this is simply the name of a macro, not a macro call.)
76The minus sign means
77`measure up from the bottom of the page',
78so
79`\-1i' means `one inch from the bottom'.
80.PP
81The
82.BD .wh
83command appears in the input outside the definition of
84.BD .NP ;
85typically the input would be
86.P1
87^de NP
88^^^
89^^
90^wh \-1i NP
91.P2
92.PP
93Now what happens?
94As text is actually being output,
95.UL troff
96keeps track of its vertical position on the page,
97and after a line is printed within one inch from the bottom,
98the
99.BD .NP
100macro is activated.
101(In the jargon, the
102.BD .wh
103command sets a
104.ul
105trap
106at the specified place,
107which is `sprung' when that point is passed.)
108.BD .NP
109causes a skip to the top of the next page
110(that's what the
111.BD \(fmbp
112was for),
113then prints the title with the appropriate margins.
114.PP
115Why
116.BD \(fmbp
117and
118.BD \(fmsp
119instead of
120.BD .bp
121and
122.BD .sp ?
123The answer is that
124.BD .sp
125and
126.BD .bp ,
127like several other commands,
128cause a
129.ul
130break
131to take place.
132That is, all the input text collected but not yet printed
133is flushed out as soon as possible,
134and the next input line is guaranteed to start
135a new line of output.
136If we had used
137.BD .sp
138or
139.BD .bp
140in the
141.BD .NP
142macro,
143this would cause a break in the middle
144of the current output line when a new page is started.
145The effect would be to print the left-over part of that line
146at the top of the page, followed by the next input line on a new output line.
147This is
148.ul
149not
150what we want.
151Using
152.BD \(fm
153instead of
154.BD .
155for a command
156tells
157.UL troff
158that
159no break is to take place _
160the output line
161currently being filled
162should
163.ul
164not
165be forced out before the space or new page.
166.PP
167The list of commands that cause a break
168is short and natural:
169.P1
170^bp ^br ^ce ^fi ^nf ^sp ^in ^ti
171.P2
172All others cause
173.ul
174no
175break,
176regardless of whether you use a
177.BD .
178or a
179.BD \(fm .
180If you really need a break, add a
181.BD .br
182command at the appropriate place.
183.PP
184One other thing to beware of _
185if you're changing fonts or point sizes a lot,
186you may find that
187if you cross a page boundary
188in an unexpected font or size,
189your titles come out in that size and font
190instead of what you intended.
191Furthermore, the length of a title is independent of the current line length,
192so titles will come out at the default length of 6.5 inches
193unless you change it,
194which is done with the
195.BD .lt
196command.
197.PP
198There are several ways to fix the problems of point sizes
199and fonts in titles.
200For the simplest applications, we can change
201.BD .NP
202to set the proper size and font for the title,
203then restore the previous values, like this:
204.P1 2
205.ta .8i
206^de NP
207\(fmbp
208\(fmsp 0.5i
209^ft R \e" set title font to roman
210^ps 10 \e" and size to 10 point
211^lt 6i \e" and length to 6 inches
212^tl 'left'center'right'
213^ps \e" revert to previous size
214^ft P \e" and to previous font
215\(fmsp 0.3i
216^^
217.P2
218.PP
219This version of
220.BD .NP
221does
222.ul
223not
224work if the fields in the
225.BD .tl
226command contain size or font changes.
227To cope with that
228requires
229.UL troff 's
230`environment' mechanism,
231which we will discuss in Section 13.
232.PP
233To get a footer at the bottom of a page,
234you can modify
235.BD .NP
236so it does
237some processing before
238the
239.BD \(fmbp
240command,
241or split the job into a footer macro invoked
242at the bottom margin and a header macro invoked
243at the top of the page.
244These variations are left as exercises.
245.WS
246.PP
247Output page numbers are computed automatically
248as each page is produced (starting at 1),
249but no numbers are printed unless you ask for them explicitly.
250To get page numbers printed,
251include the character
252.BD %
253in the
254.BD .tl
255line at
256the position where you want the number to appear.
257For example
258.P1
259^tl ''- % -''
260.P2
261centers the page number inside hyphens, as on this page.
262You can set the page number at any time
263with either
264.BD .bp\ n ,
265which immediately starts a new page numbered
266.BD n ,
267or with
268.BD .pn\ n ,
269which sets the page number for the next page
270but doesn't cause a skip to the new page.
271Again,
272.BD .bp\ +n
273sets the page number to
274.BD n
275more than its current value;
276.BD .bp
277means
278.BD .bp\ +1 .