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