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

📄 319-322.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:groff</TITLE>

<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Sams//-->

<!--CHAPTER=17//-->

<!--PAGES=319-322//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch16/317-318.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="323-325.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 17<BR>groff

</FONT></H2>

<P><I>by Tim Parker</I></P>

<DL>

<DT><B>In This Chapter</B>

<DT>&#149;&nbsp;&nbsp; Embedding Commands

<DT>&#149;&nbsp;&nbsp; Controlling Character Appearance

<DT>&#149;&nbsp;&nbsp; Macros

<DT>&#149;&nbsp;&nbsp; Using mm

</DL>

<P>The <TT>groff</TT> program is the GNU version of <TT>nroff</TT> and <TT>troff</TT>, text-formatting languages that have been used in UNIX for many years. The <TT>groff</TT> system includes versions of <TT>troff</TT>, <TT>nroff</TT>, <TT>eqn</TT>, <TT>tbl</TT>, and other UNIX text-formatting utilities. The <TT>groff</TT> language is used primarily to compile man pages written and stored in <TT>groff</TT>/<TT>nroff</TT> format into a form that can be printed or displayed onscreen.</P>

<P>The <TT>nroff</TT> language was designed to provide text formatting in lineprinters, whereas <TT>troff</TT> was developed for phototypesetters. The commands in the two languages are identical, although some commands that cannot be processed by a lineprinter are ignored by <TT>nroff</TT>. In most cases, you don&#146;t use <TT>nroff</TT> or <TT>troff</TT> directly, but use a macro package to access them.</P>

<P>For the most part, <TT>nroff</TT> and <TT>troff</TT> have fallen into disuse with the development of powerful word processors and desktop publishing packages. Their sole remaining use is for formatting man pages, which continue to be used widely.</P>

<P>Both <TT>nroff</TT> and <TT>troff</TT> have many commands that you will never require. Therefore, in this chapter we will look at the basic command set necessary for you to use the <TT>groff</TT> version of the two languages, and how they can be used for man page-specific applications. If you really want to use <TT>groff</TT> for advanced text formatting, you should pick up a dedicated book on the subject.</P>

<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Embedding Commands</FONT></H3>

<P>One aspect of <TT>groff</TT> that may take a little getting used to is that the way you type lines in the file isn&#146;t necessarily the way they will be displayed in the finished output. The <TT>groff</TT> system runs text lines together as much as possible. For example, the source file</P>

<!-- CODE SNIP //-->

<PRE>

This is fine stuff.

It is really interesting and

could keep me busy for hours.

</PRE>

<!-- END CODE SNIP //-->

<P>covers three lines in the source, but when formatted, it runs together by <TT>groff</TT> to look like this:</P>

<!-- CODE SNIP //-->

<PRE>

This is fine stuff. It is really interesting and could keep me busy for

 hours.

</PRE>

<!-- END CODE SNIP //-->

<P>with line breaks wherever necessary because of the page layout. This has an advantage in that you don&#146;t have to worry about making everything look properly formatted within the source. However, the disadvantage is that you don&#146;t have an accurate idea of what the output will look like until you see it.

</P>

<P>A look at a <TT>groff</TT> source file shows that it is all ASCII characters which contain the usual text of the displayed output and a set of commands starting with a period, like this:</P>

<!-- CODE SNIP //-->

<PRE>

This is a bunch of text that will be displayed.

Here is even more text.

.ps 14

The line above is a groff command, identified by the

period in the first column of the line.

</PRE>

<!-- END CODE SNIP //-->

<P>Most <TT>groff</TT> commands are on a line by themselves, although a few can be embedded anywhere on a line. These commands are usually prefaced by a backslash, much as the shell uses the backslash as an escape character. An example of a line with embedded commands is</P>

<!-- CODE SNIP //-->

<PRE>

This \fBline\fR has two embedded \fIgroff\fR commands.

</PRE>

<!-- END CODE SNIP //-->

<P>Although there will be times when you want to use embedded commands, the majority of the commands used will be on a single line, starting with a period.

</P>

<H3><A NAME="Heading3"></A><FONT COLOR="#000077">Controlling Character Appearance</FONT></H3>

<P>The <TT>groff</TT> language has a few commands for controlling the way characters look when printed or displayed. These include changing the size and line spacing of characters, as well as controlling fonts.</P>

<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">Sizes and Line Spacing</FONT></H4>

<P>Character size and line spacing are not usually useful when displaying text onscreen, unless you are using a bitmapped terminal. They are used for printed documents, though. You can change the size of text with the <TT>.ps</TT> (point size) command:</P>

<!-- CODE SNIP //-->

<PRE>

This is the default 10-point size.

.ps 14

This is now in fourteen-point size.

.ps 20

This is a point size of twenty.

.ps 6

And this is a really small point size of six.

</PRE>

<!-- END CODE SNIP //-->

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Note:&nbsp;&nbsp;</B><BR>A point is 1/72 of an inch, so a 36-point character size is half an inch high. The 12-point size used most commonly is 1/6-inch high. Different versions of <TT>groff</TT> support different point sizes, but most versions support 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 24, 28, and 36 points. If you set a value that is not supported, it is rounded up to the next highest value (to a maximum of 36). The default point size is 10. If you use the <TT>.ps</TT> command without a value, <TT>groff</TT> reverts to the previous value.

<HR></FONT>

</BLOCKQUOTE>

<P>Within a sentence, the point size can be changed with the line-embedded command <TT>\s</TT> followed by the point size. For example:</P>

<!-- CODE SNIP //-->

<PRE>

This is in 10-point, while \s20this is in twenty,\s10 and back to 10

 again.

</PRE>

<!-- END CODE SNIP //-->

<P>The <TT>\s</TT> command should be followed by a legal point size. The special command <TT>\s0</TT> causes <TT>groff</TT> to revert to its previous value. Relative changes are also supported, so you can embed commands such as \<TT>s&#43;2</TT> and <TT>\s-2</TT>, although only a single digit can be specified (so you can&#146;t change by more than 9 points).</P>

<I>Line spacing</I> is the vertical spacing between lines. Vertical spacing is not tied to point size, so it needs to be adjusted manually. As a general rule, use a vertical spacing about 20 percent larger than the point size. The default vertical spacing is 11.

<P>Line spacing is controlled by the <TT>.vs</TT> (vertical space) command. In the next example, we change the point size and the vertical spacing to permit the characters to be printed clearly without overlap:</P>

<!-- CODE SNIP //-->

<PRE>

This is in normal 10-point, 11 vertical space size.

.ps 12

.vs 14

This is in 12-point with 14 vertical spacing.

</PRE>

<!-- END CODE SNIP //-->

<P>If you use the <TT>.vs</TT> command without a value, <TT>groff</TT> reverts to the previous value.</P>

<P>If you want to force spacing for some reason, such as to separate sections of text, use the <TT>.sp</TT> (space) command. Used with no argument, <TT>.sp</TT> gives one blank line. It can also take arguments of <TT>i</TT> for inches and <TT>p</TT> for points:</P>

<!-- CODE SNIP //-->

<PRE>

This is default 10-point 11 vertical spaced text.

.sp

We have a blank line above this because of the command.

.sp 3.5i

This is three and a half inches below the previous line.

</PRE>

<!-- END CODE SNIP //-->

<P>You can use fractions in most <TT>groff</TT> commands, as this example shows.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch16/317-318.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="323-325.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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