📄 u3
字号:
.sp.SHIII. DOCUMENT PREPARATION.sp.PP.UC UNIXis extensively used for document preparation.There are three major .ulformattingprograms,that is,programs which produce a text withjustified right margins, automatic page numbering and titling,automatic hyphenation,and the like.The simplest of these formatters is.C roff ,whichin fact is simple enough that if you type almost any textinto a file and``roff'' it,you will get plausibly formatted output.You can do better with a little knowledge,but basically it's easy to learn and use.We'll get back to .C roffshortly..PP.C nroffis similar to.C roffbut does much less for you automatically.It will do a great deal more,once you know how to use it..PPBoth.C roffand.C nroffare designed to produce output on terminals,line-printers, and the like.The third formatter,.C troff(pronounced ``tee-roff''),instead drives a Graphic Systems phototypesetter,which produces very high quality output on photographic paper.This paperwas printed on the phototypesetter by.C troff ..if n (Or at least it will be.).PPBecause.C nroffand.C troffare relatively hard to learn to use effectively,several``packages'' of canned formatting requests are availablewhich let you do thingslike paragraphs, running titles, multi-column output,and so on, with little effort.Regrettably, details vary from system to system..SHROFF.PPThe basic idea of.C roff(and of.C nroffand.C troff ,for that matter)is that the text to be formattedcontains within it ``formatting commands''that indicate in detail how the formatted text is to look.For example, there might be commands that specify how long lines are,whether to use single or double spacing,and what running titles to use on each page.In general, you don't have to spellout all of the possible formatting details.Most of them have``default values'',which you will get if you say nothing at all.For example,unless you take special precautions,you'll get single-spaced output, 65-character lines,justified right margins, and 58 text lines per pagewhen you .C roffa file.This is the reason that.C roffis so simple _most of the decisions have already been madefor you..PPSome things do have to be done, however.If you want a documentbroken into paragraphs, you have to tell.C roffwhere to add the extra blank lines.This is done with the``.sp'' command:.B1.ne 3this is the end of one paragraph.^spThis begins the next paragraph ....B2In.C roff(and in.C nroffand.C troff ),formatting commands consist of a period followed by two letters,and they must appear at the beginning of a line, all by themselves.The ``.sp'' command tells.C roffto finish printing any of the previouslinethat might be still unprinted,then print a blank line before continuing.You can have more space if you wish;``.sp 2'' asks for 2 spaces, and so on..PPIf you simply want toensure that subsequent text appears on a fresh output line,you can use the command ``.br'' (for ``break'')instead of ``.sp''..PPMost of the other commonly-used.C roffcommands are equally simple.For example you can center one or more lines with the ``.ce'' command..B1.ne 3^ceTitle of Paper^sp 2.B2causes the title to be centered,then followed by two blank lines.As with ``.sp'', ``.ce'' can be followed by a number;in that case, that many input lines are centered..PP``.ul'' underlines lines, and can also be followed by a number:.B1.ne 5^ce 2^ul 2An Earth-shaking Paper^spJohn Q. Scientist.B2will center and underline the two text lines.Notice that the ``.sp'' between themis not part of the line count..PPYou can get multiple-line spacing instead of the default single-spacingwith the ``.ls'' command:.B1^ls 2.B2causes double spacing..PPIf you're typing things like tables,you will not want the automatic filling-up and justificationof output lines that is done by default.You can turn this off with the command``.nf'' (no-fill),and then back on again with ``.fi'' (fill).Thus.B1.ne 7this section is filled by default.^nfhere lines will appear justas you typed them _no extra spaces, no moving of words.^fiNow go back to filling up output lines..B2.PPYou can change the line-length with ``.ll'',and the left margin (the indent) by ``.in''.These are often used together to make offset blocks of text:.B1^ll \-10^in +10.fi.ll -5this text will be moved 10 spaces to the rightand the lines will also be shortened 10 characters from the right.The ``+'' and ``\-'' mean to .ulchangethe previous value by that much.Now revert:.ll +5.nf^ll +10^in \-10.B2Notice that ``.ll +10'' adds ten characters to the line length,while ``.ll 10'' makes the line ten characters.ullong..PPThe ``.ti'' commandindents (in either direction) just like ``.in'', except for only one line.Thus to make a new paragraph with a 10-character indent,you would say.B1.ne 3^sp^ti +10New paragraph ....B2.PPYou can put running titles on both top and bottom of each page,like this:.B1.ne 2^he "left top"center top"right top"^fo "left bottom"center bottom"right bottom".B2The header or footer is divided into three parts,which are marked off by any character you like.(We used a double quote.)If there's nothing between the markers, that partof the title will be blank.If you use a percent sign anywhere in ``.he'' or ``.fo'',the current page number will be inserted.So to get centered page numbers with dashes around them,at the top,use.B1^he ""\- % \-"".B2You can skip to the top of a new page at any timewith the ``.bp'' command;if ``.bp'' is followed by a number,that will be the new page number..PPThe foregoing is probably enough about .C rofffor you to go off and format most everyday documents.Read.SE roff (I)for more details..SHHints for Preparing Documents.PPMost documents go through several versions (always more than you expected) before theyare finally finished.Accordingly, you should do whatever possible to makethe job of changing them easy..PPFirst, when you do the purely mechanical operations of typing,type so subsequent editing will be easy.Start each sentence on a new line.Make lines short,and break lines at natural places,such as after commas and semicolons,rather than randomly.Since most people change documents by rewriting phrasesand adding, deleting and rearranging sentences,these precautions simplify any editingyou have to do later..PPThe second aspect of making change easyis not to commit yourself to formatting details too early.For example, if you decide that each paragraph is to havea space and an indent of 10 characters,you might type, before each,.B1.ne 2^sp^ti +10.B2But what happens when later you decide that it would havebeen better to haveno space and an indent of only 5 characters?It's tedious indeed to go back and patch this up..PPFortunately, all of the formatters letyou delay decisions until the actual moment of running.The secret is to define a new operation(called a.ulmacro),for each formatting operation you want to do,like making a new paragraph.You can say, in all three formatters,.B1.ne 4^de PP.ne 2^sp^ti +10^^.B2This.uldefines``.PP''as a new.C roff(or.C nroff or.C troff )operation,whose meaning is exactly.B1^sp^ti +10.B2(The ``..'' marks the end of the definition.)Whenever ``.PP'' is encountered in the text,it is as if you had typed the two lines of the definitionin place of it..PPThe beauty of this scheme is that now, if you change your mindabout what a paragraph should look like,you can change the formatted outputmerely by changing the definition of``.PP''and re-running the formatter..PPAs a rule of thumb, for all but the most trivial jobs,you should type a document in terms of a set of macroslike ``.PP'',and then define them appropriately.As long as you have entered the text in some systematic way,it can always be cleaned up and re-formattedby a judicious combination ofediting and macro definitions.The packages of formatting commandsthat we mentioned earlier are simply collectionsof macros designed for particular formatting tasks..PPOne of the main differences between.C roffand the other formattersis that macros in.C roffcan only be lines of text and formatting commands.In.C nroff and.C troff ,macros may have arguments,so they can have different effectsdepending on how they are called(in exactly the same way that the ``.sp'' commandhas an argument, the number of spaces you want)..SHMiscellany.PPIn addition to the basic formatters,.UC UNIXprovidesa host of supporting programs..C eqnand.C neqnlet you integrate mathematicsinto the text of a document,in a language that closely resembles the wayyou would speak it aloud..C spelland.C typodetect possible spelling mistakes in a document..C greplooks for linescontaining a particular text pattern (rather like the editor's context search does,but on a whole series of files).For example,.B1grep "ing$" chap*.B2will find all lines endingin the letters ``ing'' in the series of files ``chap*''.(It is almost always a good practice to put quotes aroundthe pattern you're searching for,in case it contains characters that have a special meaning for the shell.).PP.C wccounts the words and (optionally) lines in a set of files..C trtranslates characters into other characters;for example it will convert upper to lower case and vice versa.This translates upper into lower:.B1tr "[A-Z]" "[a-z]".B2.PP.C diffprints a list of the differences betweentwo files,so you can comparetwo versions of something automatically(which certainly beats proofreading by hand)..C sortsorts files in a variety of ways;.C crefmakes cross-references;.C ptxmakes a permuted index(keyword-in-context listing)..PPMost of these programs are either independently documented(like.C eqnand.C neqn ),or are sufficiently simple that the description inthe.ul 2.UC UNIXProgrammer's Manualis adequate explanation.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -