home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / doc / trofftut / tt09 < prev    next >
Encoding:
Text File  |  1979-01-10  |  5.6 KB  |  279 lines

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