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