⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m5

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
字号:
.pn 27.ds H T.tr |.tr ~|.de x1.xx.ftB.in .2i.nf.ne 2.1.ta 1i...de x2.fi.in0.ftR.xx...br.ce.ftB.rs.sp 0.5iTUTORIAL EXAMPLES.ftR.sp2.nr p 0.2C.ns.mh.mkIntroduction.pgAlthough \*(NR and \*(TRhave by design a syntax reminiscentof earlier text processors*.fn.xx*For example:P.|A.|Crisman, Ed.,.ulThe Compatible Time-Sharing System,MIT Press, 1965, Section|AH9.01(Description of RUNOFF program on MIT's CTSS system)..efwith the intent of easing their use,it is almost always necessary toprepare at least a small set of macro definitionsto describe most documents.Such common formatting needsas page margins and footnotesare deliberately not built into \*(NR and \*(TR.Instead,the macro and string definition, number register, diversion,environment switching, page-position trap, and conditional input mechanismsprovide the basis for user-defined implementations..pgThe examples to be discussed are intended to be useful and somewhat realistic,but won't necessarily cover all relevant contingencies.Explicit numerical parameters are usedin the examplesto make them easier to read and toillustrate typical values.In many cases, number registers would really be usedto reduce the number of places where numericalinformation is kept,and to concentrate conditional parameter initializationlike that which depends on whether \*(TR or \*(NR is being used..mhPage Margins.pgAs discussed in \(sc3,\fIheader\fR and \fIfooter\fR macros are usually definedto describe the top and bottom page margin areas respectively.A trap is planted at page position 0 for the header, and at\fI\-N\fR (\fIN\fR from the page bottom) for the footer.The simplest such definitions might be.x1&de hd	\e"define header\'sp 1i&&	\e"end definition&de fo	\e"define footer\'bp&&	\e"end definition&wh 0 hd&wh \-1i fo.x2which provide blank 1|inch top and bottom margins.The header will occur on the \fIfirst\fR page,only if the definition and trap exist prior tothe initial pseudo-page transition (\(sc3).In fill mode, the output line that springs the footer trapwas typically forced out because some part or whole word didn't fit on it.If anything in the footer and header that follows causes a \fIbreak\fR,that word or part word will be forced out.In this and other examples,requests like \fBbp\fR and \fBsp\fR that normally cause breaks are invoked usingthe \fIno-break\fR control character \fB\'\fRto avoid this.When the header\(slfooter design contains materialrequiring independent text processing, theenvironment may be switched, avoidingmost interaction with the running text..pgA more realistic example would be.x1&de hd	\e"header&if t .tl \'\|\e(rn\'\'\e(rn\'  \e"troff cut mark&if \e\en%>1 \e{\e\'sp ~\|0.5i\-1	\e"tl base at 0.5i&tl \'\'\- % \-\'\'	\e"centered page number&ps	\e"restore size&ft	\e"restore font&vs  \e}	\e"restore vs\'sp ~\|1.0i  	\e"space to 1.0i&ns	\e"turn on no-space mode&&&de fo	\e"footer&ps 10	\e"set footer\(slheader size&ft R	\e"set font&vs 12p	\e"set base-line spacing&if \e\en%=1 \e{\e\'sp ~\|\e\en(.pu\-0.5i\-1  \e"tl base 0.5i up&tl \'\'\- % \-\'\' \e}  \e"first page number\'bp&&&wh 0 hd&wh \-1i fo.x2which sets the size, font, and base-line spacing for theheader\(slfooter material, and ultimately restores them.The material in this case is a page number at the bottom of thefirst page and at the top of the remaining pages.If \*(TR is used, a \fIcut mark\fR is drawn in the formof \fIroot-en\fR's at each margin.The \fBsp\fR's refer to absolute positions to avoiddependence on the base-line spacing.Another reason for this in the footeris that the footer is invoked by printing a line whosevertical spacing swept past the trap position by possiblyas much as the base-line spacing.The \fIno-space\fR mode is turned on at the end of \fBhd\fRto render ineffectiveaccidental occurrences of \fBsp\fR at the top of the running text..pgThe above method of restoring size, font, etc. presupposesthat such requests (that set \fIprevious\fR value) are \fInot\fRused in the running text.A better scheme is save and restore both the current \fIand\fRprevious values as shown for size in the following:.x1&de fo&nr s1 \e\en(.s	\e"current size&ps&nr s2 \e\en(.s	\e"previous size&  ---	\e"rest of footer&&&de hd&  ---	\e"header stuff&ps \e\en(s2	\e"restore previous size&ps \e\en(s1	\e"restore current size&&.x2Page numbers may be printed in the bottom marginby a separate macro triggered during the footer'spage ejection:.x1&de bn	\e"bottom number&tl \'\'\- % \-\'\'	\e"centered page number&&&wh \-0.5i\-1v bn	 \e"tl base 0.5i up.x2.mhParagraphs and Headings.pgThe housekeepingassociated with starting a new paragraph should be collectedin a paragraph macrothat, for example,does the desired preparagraph spacing,forces the correct font, size, base-line spacing, and indent,checks that enough space remains for \fImore than one\fR line,andrequests a temporary indent..x1&de pg	\e"paragraph&br	\e"break&ft R	\e"force font,&ps 10	\e"size,&vs 12p	\e"spacing,&in 0	\e"and indent&sp 0.4	\e"prespace&ne 1+\e\en(.Vu	\e"want more than 1 line&ti 0.2i	\e"temp indent&&.x2The first break in \fBpg\fRwill force out any previous partial lines,and must occur before the \fBvs\fR.The forcing of font, etc. ispartly a defense against prior error andpartly to permitthings like section heading macros toset parameters only once.The prespacing parameter is suitable for \*(TR;a larger space, at least as big as the output device vertical resolution, would bemore suitable in \*(NR.The choice of remaining space to test for in the \fBne\fRis the smallest amount greater than one line(the \fB.V\fR is the available vertical resolution)..pgA macro to automatically number section headingsmight look like:.x1&de sc	\e"section&  ---	\e"force font, etc.&sp 0.4	\e"prespace&ne 2.4+\e\en(.Vu \e"want 2.4+ lines.lg 0&fi.lg\e\en+S.&&&nr S 0 1	\e"init S.x2The usage is \fB.sc\fR,followed by the section heading text,followed by \fB.pg\fR.The \fBne\fR test value includes one line of heading,0.4 line in the following \fBpg\fR, andone line of the paragraph text.A word consisting of the next section number and a period isproduced to begin the heading line.The format of the number may be set by \fBaf\fR (\(sc8)..pgAnother common form is the labeled, indented paragraph,where the label protrudes left into the indent space..x1&de lp	\e"labeled paragraph&pg&in 0.5i	\e"paragraph indent&ta 0.2i 0.5i	\e"label, paragraph&ti 0\et\e\e$1\et\ec	\e"flow into paragraph&&.x2The intended usage is "\fB.lp\fR \fIlabel\fR\|";\fIlabel\fR will begin at 0.2\|inch, andcannot exceed a length of 0.3\|inch without intruding intothe paragraph.The label could be right adjusted against 0.4\|inch bysetting the tabs instead with \fB.ta|0.4iR|0.5i\fR.The last line of \fBlp\fR ends with \fB\ec\fR so thatit will become a part of the first line of the textthat follows..mhMultiple Column Output.pgThe production of multiple column pages requiresthe footer macro to decide whether it wasinvoked by other than the last column,so that it will begin a new column rather thanproduce the bottom margin.The header can initialize a column register thatthe footer will increment and test.The following is arranged for two columns, butis easily modified for more..x1&de hd	\e"header&  ---&nr cl 0 1	\e"init column count&mk	\e"mark top of text&&&de fo	\e"footer&ie \e\en+(cl<2 \e{\e&po +3.4i	\e"next column; 3.1+0.3&rt	\e"back to mark&ns \e}	\e"no-space mode&el \e{\e&po \e\enMu	\e"restore left margin&  ---\'bp \e}&&&ll 3.1i	\e"column width&nr M \e\en(.o	\e"save left margin.x2Typically a portion of the top of the first pagecontains full width text;the request for the narrower line length,as well as another \fB.mk\fR wouldbe made where the two column output was to begin..mhFootnote Processing.pgThe footnote mechanism to be described is used byimbedding the footnotes in the input text at thepoint of reference,demarcated by an initial \fB.fn\fR and a terminal \fB.ef\fR:.x1&fn\fIFootnote text and control lines...\fP&ef.x2In the following,footnotes are processed in a separate environment and divertedfor later printing in the space immediately prior to the bottommargin.There is provision for the case where the last collectedfootnote doesn't completely fit in the available space..x1&de hd	\e"header&  ---&nr x 0 1	\e"init footnote count&nr y 0\-\e\enb	\e"current footer place&ch fo \-\e\enbu	\e"reset footer trap&if \e\en(dn .fz	\e"leftover footnote&&&de fo	\e"footer&nr dn 0	\e"zero last diversion size&if \e\enx \e{\e&ev 1	\e"expand footnotes in ev1&nf	\e"retain vertical size&FN	\e"footnotes&rm FN	\e"delete it&if "\e\en(.z"fy" .di	 \e"end overflow diversion&nr x 0	\e"disable fx&ev  \e}	\e"pop environment&  ---\'bp&&&de fx	\e"process footnote overflow&if \e\enx .di fy	\e"divert overflow&&&de fn	\e"start footnote&da FN	\e"divert (append) footnote&ev 1	\e"in environment 1&if \e\en+x=1 .fs	 \e"if first, include separator.lg0&fi	\e"fill mode.lg&&&de ef	\e"end footnote&br	\e"finish output&nr z \e\en(.v	\e"save spacing&ev	\e"pop ev&di	\e"end diversion&nr y \-\e\en(dn	\e"new footer position,&if \e\enx=1 .nr y \-(\e\en(.v\-\e\enz) \e	\e"uncertainty correction&ch fo \e\enyu	\e"y is negative&if (\|\e\en(nl+1v)>(\|\e\en(.p+\e\eny) \e&ch fo \e\en(nlu+1v	 \e"it didn't fit&&&de fs	\e"separator\el\'\|1i\'	\e"1 inch rule&br&&&de fz	\e"get leftover footnote&fn&nf	\e"retain vertical size&fy	\e"where fx put it&ef&&&nr b 1.0i	\e"bottom margin size&wh 0 hd	\e"header trap&wh 12i fo	\e"footer trap, temp position&wh \-\e\enbu fx	\e"fx at footer position&ch fo \-\e\enbu	\e"conceal fx with fo.x2The header \fBhd\fR initializes a footnote count register \fBx\fR,and sets both the current footer trap position register \fBy\fR andthe footer trap itself to a nominal position specified inregister \fBb\fR.In addition, if the register \fBdn\fR indicates a leftover footnote,\fBfz\fR is invoked to reprocess it.The footnote start macro \fBfn\fR begins a diversion (append) in environment 1,and increments the count \fBx\fR; if the count is one, the footnote separator \fBfs\fRis interpolated.The separator is kept in a separate macro to permit user redefinition.The footnote end macro \fBef\fR restoresthe previous environment and ends the diversion after saving the spacing size in register \fBz\fR.\fBy\fR is then decremented by the size of the footnote, available in \fBdn\fR;then on the first footnote, \fBy\fR is further decremented by the differencein vertical base-line spacings of the two environments, toprevent the late triggering the footer trap from causing the lastline of the combined footnotes to overflow.The footer trap is then set to the lower (on the page) of \fBy\fR or the current page position (\fBnl\fR)plus one line, to allow for printing the reference line.If indicated by \fBx\fR, the footer \fBfo\fR rereads the footnotes from \fBFN\fR in nofill modein environment 1,and deletes \fBFN\fR.If the footnotes were too large to fit, the macro \fBfx\fR will be trap-invoked to redivertthe overflow into \fBfy\fR,and the register \fBdn\fR will later indicate to the header whether \fBfy\fR is empty.Both \fBfo\fR and \fBfx\fR are planted in the nominal footer trap position in an orderthat causes \fBfx\fR to be concealed unless the \fBfo\fR trap is moved.The footer then terminates the overflow diversion, if necessary, andzeros \fBx\fR to disable \fBfx\fR,because the uncertainty correctiontogether with a not-too-late triggering of the footer can resultin the footnote rereading finishing before reaching the \fBfx\fR trap..pgA good exercise for the student is to combine the multiple-column and footnote mechanisms..mhThe Last Page.pgAfter the last input file has ended, \*(NR and \*(TRinvoke the \fIend macro\fR (\(sc7), if any,and when it finishes, eject the remainder of the page.During the eject, any traps encountered are processed normally.At the \fIend\fR of this last page, processing terminates\fIunless\fR a partial line, word, or partial word remains.If it is desired that another page be started, the end-macro.x1&de en	\e"end-macro\ec\'bp&&&em en.x2will deposit a null partial word,and effect another last page.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -