📄 unx24.htm
字号:
<HTML>
<HEAD>
<TITLE>UNIX Unleashed unx24.htm</TITLE>
<LINK REL="ToC" HREF="index.htm">
<LINK REL="Next" HREF="unx25.htm">
<LINK REL="Previous" HREF="unx23.htm"></HEAD>
<BODY TEXT="#000000" LINK="#0000FF" VLINK="#800080" bgcolor=white>
<P><A HREF="unx23.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index.htm"><IMG SRC="blutoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="unx25.htm"><IMG SRC="blunext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
<A HREF="index.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Home"></A>
</P><UL>
<LI>
<A HREF="#I1">24 — Formatting Equations with eqn</A></LI>
<UL>
<UL>
<UL>
<UL>
<LI>
<A HREF="#I3">By Susan Peppard</A></LI></UL></UL>
<LI>
<A HREF="#I4">eqn Macros and Delimiters</A></LI>
<UL>
<LI>
<A HREF="#I5">Choosing Delimiters and Placing the Definition</A></LI></UL>
<LI>
<A HREF="#I6">eqn Keywords</A></LI>
<LI>
<A HREF="#I7">eqn Operators</A></LI>
<LI>
<A HREF="#I8">Spaces and Braces</A></LI>
<UL>
<LI>
<A HREF="#I9">Grouping</A></LI></UL>
<LI>
<A HREF="#I10">Fractions</A></LI>
<LI>
<A HREF="#I11">Square Roots</A></LI>
<LI>
<A HREF="#I12">Sums, Integrals, and Limits</A></LI>
<LI>
<A HREF="#I13">Brackets, Braces, and Piles</A></LI>
<LI>
<A HREF="#I14">Arrays and Matrices</A></LI>
<LI>
<A HREF="#I15">Defines</A></LI>
<LI>
<A HREF="#I16">Precedence</A></LI>
<LI>
<A HREF="#I17">Finishing Touches</A></LI>
<LI>
<A HREF="#I18">Unconventional Uses for eqn</A></LI>
<LI>
<A HREF="#I19">Troubleshooting</A></LI>
<UL>
<LI>
<A HREF="#I20">Using checkeq</A></LI>
<LI>
<A HREF="#I21">Processing to /dev/null</A></LI>
<LI>
<A HREF="#I22">Additional Suggestions</A></LI></UL>
<LI>
<A HREF="#I23">eqn and the Preprocessors</A></LI>
<LI>
<A HREF="#I24">eqn and pic</A></LI>
<LI>
<A HREF="#I25">eqn and grap</A></LI>
<LI>
<A HREF="#I26">eqn and tbl</A></LI>
<LI>
<A HREF="#I27">Summary</A></LI></UL></UL></UL>
<H1 ALIGN="CENTER">
<CENTER><A ID="I1" NAME="I1">
<BR>
<FONT SIZE=5><A ID="I2" NAME="I2"></A><B>24 — Formatting Equations with </B><B><I>eqn</I></B>
<BR></FONT></A></CENTER></H1>
<H5 ALIGN="CENTER">
<CENTER><A ID="I3" NAME="I3">
<FONT SIZE=3><B>By Susan Peppard</B>
<BR></FONT></A></CENTER></H5>
<P>Suppose that you had to format an expression like this:
<BR></P>
<BR><IMG SRC="24unx01.gif"><BR>
<BR><P>You could format it with troff primitives, but it would take some time—probably a great deal of time. If you're writing a calculus text, you don't want to spend half of your day moving tiny numbers and letters up and down. You want to get on
with your writing.
<BR></P>
<P>There's good news. UNIX provides a tool, called eqn, that does all the formatting for you. There's more good news, too. Because the focus of eqn is limited—all it does is format equations—it is easier to learn and use than tbl or pic.
<BR></P>
<P>eqn is a troff preprocessor—like tbl, pic, and grap—that you use to format mathematical expressions. There is an nroff version. But let's face it: Formatting a complex equation with nroff is a bit like wearing double-bladed skates to the
Olympic trials.
<BR></P>
<P>Like the other preprocessor files, eqn files can't be sourced in (with .so). If you try this, troff formats your code neatly, but your code is left untouched by eqn. To source in code that has already been processed by eqn, run eqn on a file that
contains only your equation. First write the output to a file (eqn <I>filename</I> > <I>outputfile</I>), and then source in the output file. You can also read in the output file.
<BR></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> You can't source in an in-line equation.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>The devisers of eqn make a point of telling you that you don't have to know anything about mathematics (or typesetting) to use eqn. This is a bit misleading. If you don't know anything about math, you'll be surprised by the output of eqn: all the
letters are in italics. (If you don't know anything about typesetting you may not know what italics are, but I'm assuming you do.)
<BR></P>
<P>The italics are a mathematical convention. Letters representing constants or variables (a, b, c, x, y, z, etc.) are always set in italics. Numbers and special words (like "sin" and "cos") are set in roman type.
<BR></P>
<P>Besides selecting fonts for the characters in your equations, eqn provides you with a wide range of mathematical symbols, including the integral sign, upper- and lower-case Greek letters, plus, minus, equal sign, greater than, and less than.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I4" NAME="I4">
<FONT SIZE=4><B><I>eqn</I></B><B> Macros and Delimiters</B>
<BR></FONT></A></CENTER></H3>
<P>eqn processes your code before troff sees it. This means that you must send your file through eqn and pipe the output to troff. troff needs to know that you've used eqn. You tell it so by using two macros and one or two delimiters. A delimiter is a
character used to signal the beginning or the end—or both—of an equation. For example, # is a delimiter. To tell troff that you are using eqn with # as the beginning and ending delimiters, put these lines before the start of your equation:
<BR></P>
<PRE>.EQ
delim ##
.EN</PRE>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="imp.gif" WIDTH = 68 HEIGHT = 35><B>TIP: </B>It's usually a good idea to put delimiter identification lines near the top of your file.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>The eqn delimiters are used for in-line equations. (Even if you're sure you won't need in-line equations, it's a good idea to provide the delimiters. You never know.)
<BR></P>
<P>To define the delimiter, include the following lines in your file:
<BR></P>
<PRE>.EQ
delim ##
.EN</PRE>
<P>To turn the delimiters off:
<BR></P>
<PRE>.EQ
delim off
.EN</PRE>
<P>To use the delimiters, just surround your eqn code with them:
<BR></P>
<PRE># a + b = c #</PRE>
<P>Don't worry about the height of your in-line equation. troff automatically adjusts line spacings.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I5" NAME="I5">
<FONT SIZE=3><B>Choosing Delimiters and Placing the Definition</B>
<BR></FONT></A></CENTER></H4>
<P>The books suggest $$ and warn you to stay away from eqn symbols like { and ( and ~ and ^ and ". There is no default delimiter. They also suggest you put your delimiter definition at the top of your file. This is fine until you have to say that the
widget costs $5000.
<BR></P>
<PRE>.EQ
delim $$
.EN
The widget costs $5000.
.P
The enhanced widget costs $7500.
.P
Here's a formula for the cost of the widget:
$x sup 2 + x sup 2 =$ cost of widget.</PRE>
<P>The result is:
<BR></P>
<PRE>The widget costs 5000. . <I>PTheenhancedwidgetcosts7500</I>.
Here's a formula for the cost of the widget:x2+x2=cost of widget.</PRE>
<P>Not quite what you wanted. You can, of course, turn the delimiters off before you use the dollar sign as dollar sign.
<BR></P>
<P>Or you can choose a different delimiter. (There are drawbacks to all of them.) I prefer ##, but this choice can't be used with the other preprocessors. (See "eqn and the Preprocessors" later in the chapter.) Exclamation points are usually
safe, especially if you're doing technical writing. (Technical writing rarely rises to the level of excitement needed to justify exclamation points.)
<BR></P>
<P>The same might be said for placing the delimiter definition: There are drawbacks to any location. The traditional place for eqn delimiters is at the top of your file. That's where someone else would look for it. That's where you look for it six months
from now. If you're juggling text that's full of dollar signs and pound signs and exclamation points, then turn the delimiters off at the top of your file and invoke them as needed. Turn the delimiters off as soon as you're done with them.
<BR></P>
<P>If you really want to wreak havoc on a file, try this:
<BR></P>
<PRE>.EQ
delim ee
.EN</PRE>
<P>This is a wonderful April Fool's joke to play on your boss, if you have access to her files, and if you've already found another job.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I6" NAME="I6">
<FONT SIZE=4><B><I>eqn</I></B><B> Keywords</B>
<BR></FONT></A></CENTER></H3>
<P>eqn was designed to be easy for mathematicians to learn and use. It uses familiar words and abbreviations. For example, if you read a1=b2 aloud, you would say, "a sub one equals b sub two." That's what eqn says. The spaces here are important.
They are discussed later in this chapter.
<BR></P>
<PRE>#a sub 1 = b sub 2#</PRE>
<P>The opposite of sub is sup, for superscript. For example,
<BR></P>
<PRE>#a sup 2 > b sup 2</PRE>
<P>The eqn keywords are
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>above</P>
<TD>
<P>back</P>
<TD>
<P>bar</P>
<TD>
<P>bold</P>
<TD>
<P>ccol</P>
<TR>
<TD>
<P>copy</P>
<TD>
<P>cpile</P>
<TD>
<P>define</P>
<TD>
<P>delim</P>
<TD>
<P>dot</P>
<TR>
<TD>
<P>dotdot</P>
<TD>
<P>down</P>
<TD>
<P>dyad</P>
<TD>
<P>fat</P>
<TD>
<P>font</P>
<TR>
<TD>
<P>from</P>
<TD>
<P>fwd</P>
<TD>
<P>gfont</P>
<TD>
<P>gsize</P>
<TD>
<P>hat</P>
<TR>
<TD>
<P>highbar</P>
<TD>
<P>ifdef</P>
<TD>
<P>include</P>
<TD>
<P>int</P>
<TD>
<P>integral</P>
<TR>
<TD>
<P>inter</P>
<TD>
<P>italic</P>
<TD>
<P>lcol</P>
<TD>
<P>left</P>
<TD>
<P>lineup</P>
<TR>
<TD>
<P>lowbar</P>
<TD>
<P>lpile</P>
<TD>
<P>mark</P>
<TD>
<P>matrix</P>
<TD>
<P>over</P>
<TR>
<TD>
<P>pile</P>
<TD>
<P>prod</P>
<TD>
<P>rcol</P>
<TD>
<P>right</P>
<TD>
<P>roman</P>
<TR>
<TD>
<P>rpile</P>
<TD>
<P>size</P>
<TD>
<P>space</P>
<TD>
<P>sqrt</P>
<TD>
<P>sub</P>
<TR>
<TD>
<P>sumsup</P>
<TD>
<P>tilde</P>
<TD>
<P>to</P>
<TD>
<P>under</P>
<TD>
<P>union</P>
<TR>
<TD>
<P>uputilde</P>
<TD>
<P>vec</P>
<TD>
<P><BR></P>
<TD>
<P><BR></P>
<TD>
<P><BR></P></TABLE>
<P>Table 24.1 lists the keywords for Greek letters.
<BR></P>
<A HREF="tab2401.gif">Table 24.1. Keywords for Greek letters.</B></A>
<P>Note that there is no provision for the upper-case letters that are identical to their roman cousins (A, B, E, H, I, K, M, N, O, P, T, X, and Z). If you want an upper-case alpha, just type A.
<BR></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> If you want an upper-case alpha that is not italicized, you have to specify roman A.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>eqn also includes the following terms, which are printed in roman, not italic, type:
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>and</P>
<TD>
<P>arc</P>
<TD>
<P>cos</P>
<TD>
<P>cosh</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -