home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / doc / beg / u3 < prev    next >
Encoding:
Text File  |  1975-06-26  |  9.9 KB  |  432 lines

  1. .sp
  2. .SH
  3. III. DOCUMENT PREPARATION
  4. .sp
  5. .PP
  6. .UC UNIX
  7. is extensively used for document preparation.
  8. There are three major 
  9. .ul
  10. formatting
  11. programs,
  12. that is,
  13. programs which produce a text with
  14. justified right margins, automatic page numbering and titling,
  15. automatic hyphenation,
  16. and the like.
  17. The simplest of these formatters is
  18. .C roff ,
  19. which
  20. in fact is simple enough that if you type almost any text
  21. into a file and
  22. ``roff'' 
  23. it,
  24. you will get plausibly formatted output.
  25. You can do better with a little knowledge,
  26. but basically it's 
  27. easy to learn and use.
  28. We'll get back to 
  29. .C roff
  30. shortly.
  31. .PP
  32. .C nroff
  33. is similar to
  34. .C roff
  35. but does much less for you automatically.
  36. It will do a great deal more,
  37. once you know how to use it.
  38. .PP
  39. Both
  40. .C roff
  41. and
  42. .C nroff
  43. are designed to produce output on terminals,
  44. line-printers, and the like.
  45. The third formatter,
  46. .C troff
  47. (pronounced ``tee-roff''),
  48. instead drives a Graphic Systems phototypesetter,
  49. which produces very high quality output on photographic paper.
  50. This 
  51. paper
  52. was printed on the phototypesetter by
  53. .C troff .
  54. .if n (Or at least it will be.)
  55. .PP
  56. Because
  57. .C nroff
  58. and
  59. .C troff
  60. are relatively hard to learn to use effectively,
  61. several
  62. ``packages'' of canned formatting requests are available
  63. which let you do things
  64. like paragraphs, running titles, multi-column output,
  65. and so on, with little effort.
  66. Regrettably, details vary from system to system.
  67. .SH
  68. ROFF
  69. .PP
  70. The basic idea of
  71. .C roff
  72. (and of
  73. .C nroff
  74. and
  75. .C troff ,
  76. for that matter)
  77. is that the text to be formatted
  78. contains within it ``formatting commands''
  79. that indicate in detail how the formatted text is to look.
  80. For example, there might be commands that specify how long lines are,
  81. whether to use single or double spacing,
  82. and what running titles to use on each page.
  83. In general, you don't have to spell
  84. out all of the possible formatting details.
  85. Most of them have
  86. ``default values'',
  87. which you will get if you say nothing at all.
  88. For example,
  89. unless you take special precautions,
  90. you'll get single-spaced output, 65-character lines,
  91. justified right margins, and 58 text lines per page
  92. when you 
  93. .C roff
  94. a file.
  95. This is the reason that
  96. .C roff
  97. is so simple _
  98. most of the decisions have already been made
  99. for you.
  100. .PP
  101. Some things do have to be done, however.
  102. If you want a document
  103. broken into paragraphs, you have to tell
  104. .C roff
  105. where to add the extra blank lines.
  106. This is done with the
  107. ``.sp'' command:
  108. .B1
  109. .ne 3
  110. this is the end of one paragraph.
  111. ^sp
  112. This begins the next paragraph ...
  113. .B2
  114. In
  115. .C roff
  116. (and in
  117. .C nroff
  118. and
  119. .C troff ),
  120. formatting commands consist of a period followed by two letters,
  121. and they must appear at the beginning of a line, all by themselves.
  122. The ``.sp'' command tells
  123. .C roff
  124. to finish printing any of the previous
  125. line
  126. that might be still unprinted,
  127. then print a blank line before continuing.
  128. You can have more space if you wish;
  129. ``.sp 2'' asks for 2 spaces, and so on.
  130. .PP
  131. If you simply want to
  132. ensure that subsequent text appears on a fresh output line,
  133. you can use the command ``.br'' (for ``break'')
  134. instead of ``.sp''.
  135. .PP
  136. Most of the other commonly-used
  137. .C roff
  138. commands are equally simple.
  139. For example you can center one or more lines with the ``.ce'' command.
  140. .B1
  141. .ne 3
  142. ^ce
  143. Title of Paper
  144. ^sp 2
  145. .B2
  146. causes the title to be centered,
  147. then followed by two blank lines.
  148. As with ``.sp'', ``.ce'' can be followed by a number;
  149. in that case, that many input lines are centered.
  150. .PP
  151. ``.ul'' underlines lines, and can also be followed by a number:
  152. .B1
  153. .ne 5
  154. ^ce 2
  155. ^ul 2
  156. An Earth-shaking Paper
  157. ^sp
  158. John Q. Scientist
  159. .B2
  160. will center and underline the two text lines.
  161. Notice that the ``.sp'' between them
  162. is not part of the line count.
  163. .PP
  164. You can get multiple-line spacing instead of the default single-spacing
  165. with the ``.ls'' command:
  166. .B1
  167. ^ls 2
  168. .B2
  169. causes double spacing.
  170. .PP
  171. If you're typing things like tables,
  172. you will not want the automatic filling-up and justification
  173. of output lines that is done by default.
  174. You can turn this off with the command
  175. ``.nf'' (no-fill),
  176. and then back on again with ``.fi'' (fill).
  177. Thus
  178. .B1
  179. .ne 7
  180. this section is filled by default.
  181. ^nf
  182. here lines will appear just
  183. as you typed them _
  184. no extra spaces, no moving of words.
  185. ^fi
  186. Now go back to filling up output lines.
  187. .B2
  188. .PP
  189. You can change the line-length with ``.ll'',
  190. and the left margin (the indent) by ``.in''.
  191. These are often used together to make offset blocks of text:
  192. .B1
  193. ^ll \-10
  194. ^in +10
  195. .fi
  196. .ll -5
  197. this text will be moved 10 spaces to the right
  198. and the lines will also be shortened 10 characters from the right.
  199. The ``+'' and ``\-'' mean to 
  200. .ul
  201. change
  202. the previous value by that much.
  203. Now revert:
  204. .ll +5
  205. .nf
  206. ^ll +10
  207. ^in \-10
  208. .B2
  209. Notice that ``.ll +10'' adds ten characters to the line length,
  210. while ``.ll 10'' makes the line ten characters
  211. .ul
  212. long.
  213. .PP
  214. The ``.ti'' command
  215. indents (in either direction) just like ``.in'', except for only one line.
  216. Thus to make a new paragraph with a 10-character indent,
  217. you would say
  218. .B1
  219. .ne 3
  220. ^sp
  221. ^ti +10
  222. New paragraph ...
  223. .B2
  224. .PP
  225. You can put running titles on both top and bottom of each page,
  226. like this:
  227. .B1
  228. .ne 2
  229. ^he "left top"center top"right top"
  230. ^fo "left bottom"center bottom"right bottom"
  231. .B2
  232. The header or footer is divided into three parts,
  233. which are marked off by any character you like.
  234. (We used a double quote.)
  235. If there's nothing between the markers, that part
  236. of the title will be blank.
  237. If you use a percent sign anywhere in ``.he'' or ``.fo'',
  238. the current page number will be inserted.
  239. So to get centered page numbers with dashes around them,
  240. at the top,
  241. use
  242. .B1
  243. ^he ""\- % \-""
  244. .B2
  245. You can skip to the top of a new page at any time
  246. with the ``.bp'' command;
  247. if ``.bp'' is followed by a number,
  248. that will be the new page number.
  249. .PP
  250. The foregoing is probably enough about 
  251. .C roff
  252. for you to go off and format most everyday documents.
  253. Read
  254. .SE roff (I)
  255. for more details.
  256. .SH
  257. Hints for Preparing Documents
  258. .PP
  259. Most documents go through several versions (always more than you expected) before they
  260. are finally finished.
  261. Accordingly, you should do whatever possible to make
  262. the job of changing them easy.
  263. .PP
  264. First, when you do the purely mechanical operations of typing,
  265. type so subsequent editing will be easy.
  266. Start each sentence on a new line.
  267. Make lines short,
  268. and break lines at natural places,
  269. such as after commas and semicolons,
  270. rather than randomly.
  271. Since most people change documents by rewriting phrases
  272. and adding, deleting and rearranging sentences,
  273. these precautions simplify any editing
  274. you have to do later.
  275. .PP
  276. The second aspect of making change easy
  277. is not to commit yourself to formatting details too early.
  278. For example, if you decide that each paragraph is to have
  279. a space and an indent of 10 characters,
  280. you might type, before each,
  281. .B1
  282. .ne 2
  283. ^sp
  284. ^ti +10
  285. .B2
  286. But what happens when later you decide that it would have
  287. been better to have
  288. no space and an indent of only 5 characters?
  289. It's tedious indeed to go back and patch this up.
  290. .PP
  291. Fortunately, all of the formatters let
  292. you delay decisions until the actual moment of running.
  293. The secret is to define a new operation
  294. (called a
  295. .ul
  296. macro),
  297. for each formatting operation you want to do,
  298. like making a new paragraph.
  299. You can say, in all three formatters,
  300. .B1
  301. .ne 4
  302. ^de PP
  303. .ne 2
  304. ^sp
  305. ^ti +10
  306. ^^
  307. .B2
  308. This
  309. .ul
  310. defines
  311. ``.PP''
  312. as a new
  313. .C roff
  314. (or
  315. .C nroff 
  316. or
  317. .C troff )
  318. operation,
  319. whose meaning is exactly
  320. .B1
  321. ^sp
  322. ^ti +10
  323. .B2
  324. (The ``..'' marks the end of the definition.)
  325. Whenever ``.PP'' is encountered in the text,
  326. it is as if you had typed 
  327. the two lines of the definition
  328. in place of it.
  329. .PP
  330. The beauty of this scheme is that now, if you change your mind
  331. about what a paragraph should look like,
  332. you can change the formatted output
  333. merely by changing the definition of
  334. ``.PP''
  335. and re-running the formatter.
  336. .PP
  337. As a rule of thumb, for all but the most trivial jobs,
  338. you should type a document in terms of a set of macros
  339. like ``.PP'',
  340. and then define them appropriately.
  341. As long as you have entered the text in some systematic way,
  342. it can always be cleaned up and re-formatted
  343. by a judicious combination of
  344. editing and macro definitions.
  345. The packages of formatting commands
  346. that we mentioned earlier are simply collections
  347. of macros designed for particular formatting tasks.
  348. .PP
  349. One of the main differences between
  350. .C roff
  351. and the other formatters
  352. is that macros in
  353. .C roff
  354. can only be lines of text and formatting commands.
  355. In
  356. .C nroff 
  357. and
  358. .C troff ,
  359. macros may have arguments,
  360. so they can have different effects
  361. depending on how they are called
  362. (in exactly the same way that the ``.sp'' command
  363. has an argument, the number of spaces you want).
  364. .SH
  365. Miscellany
  366. .PP
  367. In addition to the basic formatters,
  368. .UC UNIX
  369. provides
  370. a host of supporting programs.
  371. .C eqn
  372. and
  373. .C neqn
  374. let you integrate mathematics
  375. into the text of a document,
  376. in a language that closely resembles the way
  377. you would speak it aloud.
  378. .C spell
  379. and
  380. .C typo
  381. detect possible spelling mistakes in a document.
  382. .C grep
  383. looks for lines
  384. containing a particular text pattern 
  385. (rather like the editor's context search does,
  386. but on a whole series of files).
  387. For example,
  388. .B1
  389. grep  "ing$"  chap*
  390. .B2
  391. will find all lines ending
  392. in the letters ``ing'' in the series of files ``chap*''.
  393. (It is almost always a good practice to put quotes around
  394. the pattern you're searching for,
  395. in case it contains characters that have a special meaning for the shell.)
  396. .PP
  397. .C wc
  398. counts the words and (optionally) lines in a set of files.
  399. .C tr
  400. translates characters into other characters;
  401. for example it will convert upper to lower case and vice versa.
  402. This translates upper into lower:
  403. .B1
  404. tr  "[A-Z]"  "[a-z]"
  405. .B2
  406. .PP
  407. .C diff
  408. prints a list of the differences between
  409. two files,
  410. so you can compare
  411. two versions of something automatically
  412. (which certainly beats proofreading by hand).
  413. .C sort
  414. sorts files in a variety of ways;
  415. .C cref
  416. makes cross-references;
  417. .C ptx
  418. makes a permuted index
  419. (keyword-in-context listing).
  420. .PP
  421. Most of these programs are either independently documented
  422. (like
  423. .C eqn
  424. and
  425. .C neqn ),
  426. or are sufficiently simple that the description in
  427. the
  428. .ul 2
  429. .UC UNIX
  430. Programmer's Manual
  431. is adequate explanation.
  432.