?? ch12_03.htm
字號:
<html><head><title>Conceptual Overview (UNIX in a Nutshell: System V Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Arnold Robbins" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="1-56592-427-4" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="UNIX in a Nutshell: System V Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Book Title" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch12_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch12_04.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">12.3. Conceptual Overview</h2><p><a name="IXT-12-123359" /><a name="IXT-12-123360" /><a name="IXT-12-123361" />This sections provides a brief overview of how to prepareinput for <tt class="literal">nroff</tt> and <tt class="literal">troff</tt>.It presents the following topics:</p><ul><li><p>Requests and macros</p></li><li><p>Common requests</p></li><li><p>Specifying measurements</p></li><li><p>Requests that cause a line break</p></li><li><p>Embedded formatting controls</p></li></ul><a name="unut-ch-12-sect-3.1" /><div class="sect2"><h3 class="sect2">12.3.1. Requests and Macros</h3><p>Formatting is specified by embedding brief codes(called <em class="emphasis">requests</em>)into the text source file.These codes act as directives to <tt class="literal">nroff</tt> and <tt class="literal">troff</tt>when they run. For example, to center a lineof text, type the following code in a file:</p><blockquote><pre class="code">.ceThis text should be centered.</pre></blockquote><p>When formatted, the output appears centered:</p><blockquote><pre class="code"> This text should be centered.</pre></blockquote><p>There are two types of formatting codes:</p><ul><li><p><em class="emphasis">Requests</em>, which provide the most elementary instructions</p></li><li><p><em class="emphasis">Macros</em>, which are predefined combinations of requests</p></li></ul><p>Requests, also known as <em class="emphasis">primitives</em>, allow direct control of almost any feature of page layout and formatting. Macros combine requests to create a total effect.In a sense, requests are like atoms, and macros are like molecules.</p><p>All <tt class="literal">nroff</tt>/<tt class="literal">troff</tt> requests are two-letterlowercase names. Macros are usually upper- or mixed-case names.</p><p>See <a href="ch13_01.htm">Chapter 13</a>, <a href="ch14_01.htm">Chapter 14</a>, <a href="ch15_01.htm">Chapter 15</a>, and <a href="ch16_01.htm">Chapter 16</a>, for more information on the standard macro packages.</p></div><a name="unut-ch-12-sect-3.2" /><div class="sect2"><h3 class="sect2">12.3.2. Common Requests</h3><p>The most commonly used requests are:</p><blockquote><pre class="code">.ad .ds .ll .nr .sp.br .fi .na .po .ta.bp .ft .ne .ps .ti.ce .in .nf .so .vs.de .ls</pre></blockquote><p>For example, a simple macro could be written as follows:</p><blockquote><pre class="code">. \" Ps macro - show literal text display.de Ps \" Define a macro named "Ps".sp .5 \" Space down half a line.in 1i \" Indent one inch.ta 10n +10n \" Set new tabstops.ps 8 \" Use 8-point type.vs 10 \" Use 10-point vertical spacing.ft CW \" Use constant width font.br \" Break line (.ne begins count on next line).ne 3 \" Keep 3 lines together.nf \" No-fill mode (output lines as is).. \" End macro definition</pre></blockquote></div><a name="unut-ch-12-sect-3.3" /><div class="sect2"><h3 class="sect2">12.3.3. Specifying Measurements</h3><p><a name="IXT-12-123362" /><a name="IXT-12-123363" />With some requests, the numeric argument can be followedby a scale indicator that specifies a unit of measurement.The valid indicators and their meanings are listed in the following table.Note that all measurements are internally converted to basic units(this conversion is shown in the last column).A basic unit is the smallest possible size on the printer device.The device resolution (e.g., 600 dots per inch) determines thesize of a basic unit. Also, <em class="emphasis">T</em> specifies the currentpoint size, and <em class="emphasis">R</em> specifies the device resolution.</p><table border="1" cellpadding="3"><tr><th><p><em class="emphasis">Scale Indicator</em></p></th><th><p><em class="emphasis">Meaning</em></p></th><th><p><em class="emphasis">Equivalent Unit</em></p></th><th><p><em class="emphasis"># of Basic Units</em></p></th></tr><tr><td><tt class="literal">c</tt></td><td>Centimeter</td><td>2.54 inches</td><td><em class="emphasis">R</em> / 2.54</td></tr><tr><td><tt class="literal">i</tt></td><td>Inch</td><td><p>6 picas or 72 points</p></td><td><em class="emphasis">R</em></td></tr><tr><td><tt class="literal">m</tt></td><td>Em</td><td><em class="emphasis">T</em> points</td><td><em class="emphasis">R</em> × <em class="emphasis">T</em> / 72</td></tr><tr><td><tt class="literal">n</tt></td><td>En</td><td>0.5 em</td><td><em class="emphasis">R</em> × <em class="emphasis">T</em> / 144</td></tr><tr><td><tt class="literal">p</tt></td><td>Point</td><td>1/72 inch</td><td><em class="emphasis">R</em> / 72</td></tr><tr><td><tt class="literal">P</tt></td><td>Pica</td><td>1/6 inch</td><td><em class="emphasis">R</em> / 6</td></tr><tr><td><tt class="literal">u</tt></td><td><p>Basic unit</p></td><td> </td><td>1</td></tr><tr><td><tt class="literal">v</tt></td><td><p>Vertical line space</p></td><td> </td><td><p>(Current value in basic units)</p></td></tr><tr><td>None</td><td>Default</td><td></td><td> </td></tr></table><p><p>It is worth noting that <em class="emphasis">all</em> numbersin <tt class="literal">nroff</tt>/<tt class="literal">troff</tt>are stored internally using integers.This applies even to apparently fractional values incommands such as:<blockquote><pre class="code">.sp .5</pre></blockquote>which spaces down one-half of the current vertical spacing.</p><p>An “em” is the width of the letter “m” in thecurrent font and point size.An “en” is the width of the letter “n” in thecurrent font and point size.Note that in <tt class="literal">nroff</tt>, an “em” and an “en”are the same--the width of one character.</p><p>You can specify a scale indicator for any of the requests in the following table,except for <tt class="literal">.ps</tt>, which always uses points.If no unit is given, the default unit is used.(The second column lists the scale indicators as described in the previous table.)For horizontally oriented requests, the default unit is ems.For vertically oriented requests, the default is usually verticallines.</p><table border="1" cellpadding="3"><tr><th><em class="emphasis">Request</em></th><th><em class="emphasis">Default Scale</em></th><th><em class="emphasis">Request</em></th><th><em class="emphasis">Default Scale</em></th></tr><tr><td><tt class="literal">.ch</tt></td><td><tt class="literal">v</tt></td><td><tt class="literal">.pl</tt></td><td><tt class="literal">v</tt></td></tr><tr><td><tt class="literal">.dt</tt></td><td><tt class="literal">v</tt></td><td><tt class="literal">.po</tt></td><td><tt class="literal">v</tt></td></tr><tr><td><tt class="literal">.ie</tt></td><td><tt class="literal">u</tt></td><td><tt class="literal">.ps</tt></td><td><tt class="literal">p</tt></td></tr><tr><td><tt class="literal">.if</tt></td><td><tt class="literal">u</tt></td><td><tt class="literal">.rt</tt></td><td><tt class="literal">v</tt></td></tr><tr><td><tt class="literal">.in</tt></td><td><tt class="literal">m</tt></td><td><tt class="literal">.sp</tt></td><td><tt class="literal">v</tt></td></tr><tr><td><tt class="literal">.ll</tt></td><td><tt class="literal">m</tt></td><td><tt class="literal">.sv</tt></td><td><tt class="literal">v</tt></td></tr><tr><td><tt class="literal">.lt</tt></td><td><tt class="literal">m</tt></td><td><tt class="literal">.ta</tt></td><td><tt class="literal">m</tt></td></tr><tr><td><tt class="literal">.mc</tt></td><td><tt class="literal">m</tt></td><td><tt class="literal">.ti</tt></td><td><tt class="literal">m</tt></td></tr><tr><td><tt class="literal">.ne</tt></td><td><tt class="literal">v</tt></td><td><tt class="literal">.vs</tt></td><td><tt class="literal">p</tt></td></tr><tr><td><tt class="literal">.nr</tt></td><td><tt class="literal">u</tt></td><td><tt class="literal">.wh</tt></td><td><tt class="literal">v</tt></td></tr></table><p></div><a name="unut-ch-12-sect-3.4" /><div class="sect2"><h3 class="sect2">12.3.4. Requests That Cause a Line Break</h3><p><a name="IXT-12-123364" />A <em class="emphasis">line break</em> occurs when <tt class="literal">nroff</tt>/<tt class="literal">troff</tt>writes the current output line, even if it is not completely filled.Most requests can be interspersed with text withoutcausing a line break in the output. The following requestscause a break:</p><blockquote><pre class="code">.bp .ce .fi .in .sp.br .cf .fl .nf .ti</pre></blockquote><p>If you need to prevent these requests from causing a break,begin them with the “no break” control character(normally <tt class="literal">'</tt>)instead of a dot (<tt class="literal">.</tt>).For example, <tt class="literal">.sp</tt> takes effect right away, but <tt class="literal">'sp</tt> waits until the output line is completely filled. Only thendoes it add a line space.</p></div><a name="unut-ch-12-sect-3.5" /><div class="sect2"><h3 class="sect2">12.3.5. Embedded Formatting Controls</h3><p>In addition to requests and macros, which are written on their own separatelines, you may also have formatting controls embedded within your textlines.These typically provide the following capabilities:</p><dl><dt><i><em class="emphasis">General formatting</em></tt></i></dt><dd>Considerable formatting control is available,such as switching fonts (<tt class="literal">\f</tt>),changing point sizes (<tt class="literal">\s</tt>),computing widths (<tt class="literal">\w</tt>),and many other things. For example:</p><blockquote><pre class="code">This text is in \fIitalic\fR, but this is in roman.This text is \s-2VERY SMALL\s0 but this text is not.</pre></blockquote></dd><dt><i><em class="emphasis">Special characters</em></tt></i></dt><dd>Predefined special typesetting characters, such asthe bullet symbol <tt class="literal">\(bu</tt> (<img src="figs/bull.gif" alt="Figure " />),the left hand <tt class="literal">\(lh</tt> (<img src="figs/lhand.gif" alt="Figure " />),and the right hand <tt class="literal">\(rh</tt> (<img src="figs/rhand.gif" alt="Figure " />).</p></dd><dt><i><em class="emphasis">Strings</em></tt></i></dt><dd>User-defined sequences of characters, like macros, but usableinline. For example:</p><blockquote><pre class="code">.\" define a shorthand for UNIX.ds UX the \s-1UNIX\s0 Operating System...Welcome to \*(UX.While \*(UX may appear daunting at first,it is immensely powerful. ...</pre></blockquote></dd><dt><i><em class="emphasis">Number registers</em></tt></i></dt><dd>Like variables in programming languages,number registers store numeric values that can be printed ina range of formats (decimal, roman, etc.).They can be set to auto-increment or auto-decrement,and are particularly useful when writing macro packages,for managing automatic numbering of headings, footnotes,figures, and so on. For example:</p><blockquote><pre class="code">.nr Cl 0 1 \" Chapter Level.de CH.bp\\n+(Cl. \\$1 \\$2 \\$3..</pre></blockquote><p>This creates a macro that uses register <tt class="literal">Cl</tt>as the “chapter level.”The first three arguments to the macro become the chapter title.The extra backslashes are needed inside the macro definition.</p></dd></dl><p>Later sections in this chapter describe the predefined specialcharacters, strings and number registers, and all of the escapesequences that are available.</p></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch12_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch12_04.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">12.2. Command-Line Invocation</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">12.4. Default Operation of Requests</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2003</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,88,96" href="../index.htm"><area shape="rect" coords="90,0,165,96" href="../upt/index.htm"><area shape="rect" coords="168,1,253,107" href="../mac/index.htm"><area shape="rect" coords="255,0,335,97" href="../korn/index.htm"><area shape="rect" coords="337,0,415,109" href="../unixnut/index.htm"><area shape="rect" coords="417,0,512,122" href="../sedawk/index.htm"><area shape="rect" coords="514,0,605,105" href="../lunix/index.htm"><area shape="rect" coords="611,2,694,121" href="../vi/index.htm"></map></body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -