BSD 3 development
[unix-history] / usr / doc / beginners / u3
CommitLineData
8340f87c
BJ
1.sp
2.SH
3III. DOCUMENT PREPARATION
4.PP
5.UC UNIX
6systems are used extensively for document preparation.
7There are two major
8formatting
9programs,
10that is,
11programs that produce a text with
12justified right margins, automatic page numbering and titling,
13automatic hyphenation,
14and the like.
15.UL nroff
16is designed to produce output on terminals and
17line-printers.
18.UL troff
19(pronounced ``tee-roff'')
20instead drives a phototypesetter,
21which produces very high quality output
22on photographic paper.
23This paper was formatted with
24.UL troff .
25.SH
26Formatting Packages
27.PP
28The basic idea of
29.UL nroff
30and
31.UL troff
32is that the text to be formatted contains within it
33``formatting commands'' that indicate in detail
34how the formatted text is to look.
35For example, there might be commands that specify how long
36lines are, whether to use single or double spacing,
37and what running titles to use on each page.
38.PP
39Because
40.UL nroff
41and
42.UL troff
43are relatively hard to learn to use effectively,
44several
45``packages'' of canned formatting requests are available
46to let you specify
47paragraphs, running titles, footnotes, multi-column output,
48and so on, with little effort
49and without having to learn
50.UL nroff
51and
52.UL troff .
53These packages take a modest effort to learn,
54but the rewards for using them are so great
55that it is time well spent.
56.PP
57In this section,
58we will provide a hasty look at the ``manuscript''
59package known as
60.UL \-ms .
61Formatting requests typically consist of a period and two upper-case letters,
62such as
63.UL .TL ,
64which is used to introduce a title,
65or
66.UL .PP
67to begin a new paragraph.
68.PP
69A document is typed so it looks something like this:
70.P1
71\&.TL
72title of document
73\&.AU
74author name
75\&.SH
76section heading
77\&.PP
78paragraph ...
79\&.PP
80another paragraph ...
81\&.SH
82another section heading
83\&.PP
84etc.
85.P2
86The lines that begin with a period are the formatting requests.
87For example,
88.UL .PP
89calls for starting a new paragraph.
90The precise meaning of
91.UL .PP
92depends on what output device is being used
93(typesetter or terminal, for instance),
94and on what publication the document will appear in.
95For example,
96.UL \-ms
97normally assumes that a paragraph is preceded by a space
98(one line in
99.UL nroff ,
100\(12 line in
101.UL troff ),
102and the first word is indented.
103These rules can be changed if you like,
104but they are changed by changing the interpretation
105of
106.UL .PP ,
107not by re-typing the document.
108.PP
109To actually produce a document in standard format
110using
111.UL \-ms ,
112use the command
113.P1
114troff -ms files ...
115.P2
116for the typesetter, and
117.P1
118nroff -ms files ...
119.P2
120for a terminal.
121The
122.UL \-ms
123argument tells
124.UL troff
125and
126.UL nroff
127to use the manuscript package of formatting requests.
128.PP
129There are several similar packages;
130check with a local expert to determine which ones
131are in common use on your machine.
132.SH
133Supporting Tools
134.PP
135In addition to the basic formatters,
136there is
137a host of supporting programs
138that help with document preparation.
139The list in the next few paragraphs
140is far from complete,
141so browse through the manual
142and check with people around you for other possibilities.
143.PP
144.UL eqn
145and
146.UL neqn
147let you integrate mathematics
148into the text of a document,
149in an easy-to-learn language that closely resembles the way
150you would speak it aloud.
151For example, the
152.UL eqn
153input
154.P1
155sum from i=0 to n x sub i ~=~ pi over 2
156.P2
157produces the output
158.EQ
159sum from i=0 to n x sub i ~=~ pi over 2
160.EN
161.PP
162The program
163.UL tbl
164provides an analogous service for preparing tabular material;
165it does all the computations necessary to align complicated columns
166with elements of varying widths.
167.PP
168.UL refer
169prepares bibliographic citations from a data base,
170in whatever style is defined by the formatting package.
171It looks after all the details of numbering references in sequence,
172filling in page and volume numbers,
173getting the author's initials and the journal name right,
174and so on.
175.PP
176.UL spell
177and
178.UL typo
179detect possible spelling mistakes in a document.
180.UL spell
181works by comparing the words in your document
182to a dictionary,
183printing those that are not in the dictionary.
184It knows enough about English spelling to detect plurals and the like,
185so it does a very good job.
186.UL typo
187looks for words which are ``unusual'',
188and prints those.
189Spelling mistakes tend to be more unusual,
190and thus show up early when the most unusual words
191are printed first.
192.PP
193.UL grep
194looks through a set of files for lines
195that contain a particular text pattern
196(rather like the editor's context search does,
197but on a bunch of files).
198For example,
199.P1
200grep \(fming$\(fm chap*
201.P2
202will find all lines that end with
203the letters
204.UL ing
205in the files
206.UL chap* .
207(It is almost always a good practice to put single quotes around
208the pattern you're searching for,
209in case it contains characters like
210.UL *
211or
212.UL $
213that have a special meaning to the shell.)
214.UL grep
215is often useful for finding out in which of a set of files
216the misspelled words detected by
217.UL spell
218are actually located.
219.PP
220.UL diff
221prints a list of the differences between
222two files,
223so you can compare
224two versions of something automatically
225(which certainly beats proofreading by hand).
226.PP
227.UL wc
228counts the words, lines and characters in a set of files.
229.UL tr
230translates characters into other characters;
231for example it will convert upper to lower case and vice versa.
232This translates upper into lower:
233.P1
234tr A-Z a-z <input >output
235.P2
236.PP
237.UL sort
238sorts files in a variety of ways;
239.UL cref
240makes cross-references;
241.UL ptx
242makes a permuted index
243(keyword-in-context listing).
244.UL sed
245provides many of the editing facilities
246of
247.UL ed ,
248but can apply them to arbitrarily long inputs.
249.UL awk
250provides the ability to do both pattern matching and numeric computations,
251and to conveniently process fields within lines.
252These programs are for more advanced users,
253and they are not limited to document preparation.
254Put them on your list of things to learn about.
255.PP
256Most of these programs are either independently documented
257(like
258.UL eqn
259and
260.UL tbl ),
261or are sufficiently simple that the description in
262the
263.ul 2
264.UC UNIX
265Programmer's Manual
266is adequate explanation.
267.SH
268Hints for Preparing Documents
269.PP
270Most documents go through several versions (always more than you expected) before they
271are finally finished.
272Accordingly, you should do whatever possible to make
273the job of changing them easy.
274.PP
275First, when you do the purely mechanical operations of typing,
276type so that subsequent editing will be easy.
277Start each sentence on a new line.
278Make lines short,
279and break lines at natural places,
280such as after commas and semicolons,
281rather than randomly.
282Since most people change documents by rewriting phrases
283and adding, deleting and rearranging sentences,
284these precautions simplify any editing
285you have to do later.
286.PP
287Keep the individual files of a document down
288to modest size,
289perhaps ten to fifteen thousand characters.
290Larger files edit more slowly,
291and of course if you make a dumb mistake
292it's better to have clobbered a small file than a big one.
293Split into files at natural boundaries in the document,
294for the same reasons that you start each sentence
295on a new line.
296.PP
297The second aspect of making change easy
298is to not commit yourself to formatting details too early.
299One of the advantages of formatting packages like
300.UL \-ms
301is that they permit you to delay decisions
302to the last possible moment.
303Indeed,
304until a document is printed,
305it is not even decided whether it will be typeset
306or put on a line printer.
307.PP
308As a rule of thumb, for all but the most trivial jobs,
309you should type a document in terms of a set of requests
310like
311.UL .PP ,
312and then define them appropriately,
313either by using one of the canned packages
314(the better way)
315or by defining your own
316.UL nroff
317and
318.UL troff
319commands.
320As long as you have entered the text in some systematic way,
321it can always be cleaned up and re-formatted
322by a judicious combination of
323editing commands and request definitions.