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