Chapter Twenty-Three

image for Mathematics

23.1 ENTERING MATHEMATICS: MATH MODE

Typesetting mathematics properly is a challenge for humans and their computer counterparts. In order for mathematical symbols to convey their meanings properly, their size and vertical and horizontal placements must adhere exactly to accepted mathematical notation. image does a beautiful job at mathematical typesetting, better than any other program, in our opinion, and is almost as good as a human typesetter.

To input an equation or mathematical symbol you enter math mode, and then leave math mode when you want to enter text again. The equations or symbols may be embedded in text or displayed (set off) between lines of text. In-text mathematics, such as image, is surrounded by dollar signs $R = sqrt{N}$, the first one indicating a switch from text to math mode, the second one indicating a switch back from math to text:

image

In addition to dollar signs, you may also use (and ) to mark the beginning and the end of a mathematical formula or symbol embedded in text:

image

Though probably just a matter of taste, we find it easier to read and edit a image source file when there are dollar signs in the text; to us, the (and ) look too much like part of the equation.

Mathematics that is displayed (separated from the text) looks like:

image

Check that this equation has a number on the extreme right (automatically assigned by image) and a period for punctuation (put there because we prefer equations with punctuation). This equation was obtained with the LATnX input:

image

The egin{equation} and end{equation} commands define the environment for numbered mathematical equations. If you do not want the equation to be numbered, that is, so it appears as:

image

then use [and ] to begin and end the displayed equation environment:

image

23.2 MATHEMATICAL SYMBOLS AND GREEK

Most characters have their standard meaning in math mode. However, letters used as symbols appear in a special mode of italic, and function names and subscripts appear in Roman. The special characters, already discussed in §22.4.2, are entered in math mode as:

image

The spacings between math symbols will be different than the spacings in text mode and are designed to make the mathematics clearer. As always, image ignores extra spaces or carriage returns in the your source file, unless you force the issue. This means that you may insert extra spaces in your source file for clarity, or distribute your equations over several lines. image will put it all together and make it look nice. If you insist on inserting spaces (not worth the trouble unless you are publishing the document). For example, if you enter $xy$you get xy, otherwise:

image

23.2.1 Greek Letters

Greek letters are produced in math mode by preceding the full name of the letter by a backslash . For example, C = 2πr is input as $C = 2 pi r$. The lowercase Greek letters are obtained as:

image

For those that are different from their Roman counterparts, uppercase Greek letters are obtained by capitalizing the first character of their names:

image

23.2.2 Relations

image

23.2.3 Negative Relations

Most negative relations are formed by including a ot command in front of the normal relation:

image

This is just ot placed in front of leq and equiv. In addition, the symbol ≠ may be formed in a number of ways:

image

23.2.4 Binary (and Other) Operators

image

23.2.5 Arrows

image

23.2.6 Math Parentheses

image

23.2.7 Miscellaneous Math Symbols

image

23.2.8 “Big” Operators

image

23.3 MATH ACCENTS

image

23.4 SUPERSCRIPTS AND SUBSCRIPTS

A subscript is created by adding an underscore _ to a symbol and following that with the subscript, as in I_x. A superscript is created by adding a caret ˆ to a symbol and following that with the superscript, as in xˆ2. And by doing both, a symbol may contain both a superscript and subscript:

image

is obtained with either order of super- and subscripts:

image

Inasmuch as the sub- and superscripts here are above each other, the two ways of inputting are equivalent. If the sub- or superscript contains more than one character, then the characters must be placed together within braces:

image

is obtained by with either order of super- and subscripts:

image

23.5 CALCULUS AND SUMS

image

23.6 CHANGING MATH FONTS

We have seen that image sets mathematics in an italic font that is different from the italics of text mode. You obtain Roman and bold fonts within math mode with the commands mathrm and mathbf:

image

If you start running out of letters, why not try the uppercase calligraphic letters in math mode: ,cal{A}:

image

Sometimes you need to include text in an equation. You do that by making a box with mbox{text} and placing the text in the box:

image

In view of the fact that image removes single blank spaces in math mode but not in text mode, the two single spaces we placed within the box above will remain. Alternatively, we could have inserted spaces with as x = 3, mbox{for} y > 12} .

23.7 MATH FUNCTIONS

The basic mathematical functions are obtained by entering a backlash before the name. To cite an instance, x3 sin y2 is obtained from xˆ3 sin yˆ2. Look at how you need to leave a space after the function name as a separator, unless another backslash follows. Available functions include:

image

Other mathematical function names are obtained by switching to Roman math font, and then writing the function name; for example, cosec(A) as $mathrm{cosec}(A)$.

23.8 FRACTIONS

To make a fraction with num over denom, use the frac{num}{denom} command:

image

Even though this image command works fine, we prefer the simpler over image command:

image

23.9 ROOTS

The square root symbol image is obtained with the sqrt{N} command. image automatically adjusts the height and lengths of root symbols to fit into the equation and to span the argument:

image

Higher roots are obtained by including an optional order parameter in square brackets to sqrt[n]{}:

image

23.10 BRACKETS (DELIMITERS)

Except for braces, which are used for commands, most normal-sized brackets or delimiters are entered into mathematics as typed:

image

Just as it does for roots, image scales the size of these delimiters to match the size of the rest of the equation. However, since an equation may have a number of nested brackets, image needs some help in deciding just which brackets you want to match. Thus, you give it help by tacking on the commands left and ight to the delimiters that you wish to match up:

image

In order for image to do all the work for you in sizing and placing these limiters, it demands that all the ights be balanced by an equal number of lefts. image does not demand that the types match up, just the number of rights and lefts. So, for example, left (may be paired off with ight]. Although this all makes sense, it introduces a problem if you try to create something like

image

where there is no delimiter to match the left |. For this purpose, image contains the null delimiters left. and ight. that count as delimiters but do not show up when typeset. As an instance, the above formula was obtained with:

image

23.11 MULTILINE EQUATIONS

Having image arrange multiline equations is essentially the same as working with the tabular environment for text. You place each equation on a separate line (row), and then align the equal signs in each equation by placing them in the same column. To cite an instance, Sample.tex on the CD creates

image

Observe here that we display these equations with the equation-array environment eqnarray rather than the equation environment that we used for single-line equations. We begin with egin{eqnarray} and end with end{eqnarry}. These commands produce numbered equations. If unnumbered, multiline equations are desired, they are produced with the egin{eqnarray*} and end{eqnarry*} forms. The equations are entered into an eqnarray environment in the same way as they would be with {equation}, except that the equal signs are enclosed by ampersands &=&, and each line of the equation ends with a double backslash \. As also occurs in the tabular environment, this produces a column with all the equal signs aligned, and permits there to be as many lines with equations as you enter.

Because eqnarray is just a tabular environment, it is possible to align symbols other than the equal sign, or to use this environment to split a very long equation onto two lines, with the continuation being indented:

image

image

23.12 MATRICES AND MATH ARRAYS

The array environment is used to produce matrices and mathematical arrays:

image

This is essentially identical to how tables are constructed for text. All that is new is the use of large right and left delimiters to produce a matrix symbol that fits the array. The alignment characters {ccc} are the same as with tabular.

Another approach to matrices, which we personally find easier and more compact than the image standard, is the image command pmatrix:

image

We see that pmatrix takes care of its own delimiters and uses the carriage return command cr to end the rows.

The array environment is also used to produce an equation containing cases:

image

Here too, our preference is the image command cases, which we find simpler:

23.13 INCLUDING GRAPHICS

Most drawing and graphing programs have a number of options to determine the file format in which to save graphics. Because image is used to produce publication quality typesetting, if you include graphics, then they too should be publication quality. PostScript (.ps) and Encapsulated PostScript (.eps) figures are of publication quality, so it should not be a surprise that there are nice packages to include these formats in image documents.

We will discuss how to include .eps figures, with the same commands used for .ps figures. Given a choice, use encapsulated figures, since it may be easier to adjust their size to fit the document. If your figure is of a different type, you should be able to open it in a drawing program and save it as an .eps figure. In addition, we recommend that you embed the fonts used in your figure with the figure; this does make for a larger file, but also avoids the possibility of some inappropriate local font being substituted when the document is printed (especially likely if you scale the figure).

We recommend the graphics package for including figures, although we have also had success with the psfig package, especially for placing figures at desired points on the page. If a package is not part of your image installation, it may be added. Before you use a package, you must include it in your document’s preamble (the part before the egin{document}command):

image

On the CD is the sample graphics file image_Compile.eps used to create Figure 22.1. It is redrawn on this page as Figure 23.1 with the commands

image

Figure 23.1 A scaled-down and rotated Figure 9.1.

image

The figure environment is standard image. It is also used to draw pictures with image, or to leave room for and label figures to be pasted in later (use vspace to make the room). The includegraphics command is placed within the figure environment. To ensure that the figure is centered on the page, we place the figure in a center environment. The angle=45, scale=0.25 specification in square brackets is optional and leads to a figure that is slanted and scaled to 25% of its original size.1 The name of the figure image_Compile.eps is given in curly braces, with a path indication if it is not in current directory. Scrutinize how after the name of the figure we issue the caption command containing the caption as its argument. Within the caption’s argument (still within the curly braces) we have placed the label command label{sample.fig}. We then refer to this figure as ef{sample.fig}, as we do in the sample includegraphics command above, and let image take care of its actual number.

As an example of psfig, examine Figure 15.1 (p. 310) with its multiple

image

23.14 EXERCISE: PUTTING IT ALL TOGETHER

1.  Enter Sample.tex as given in §22.3. Use a text editor and save the file as Sample.tex. We recommend WinEdt and MikTex for Windows, and gnu xemacs for Unix/Linux.

2.  Compile the file by pressing the LAT X button or by issuing a command from a shell:

image

If there are no errors in your file, you should get a fairly verbose response with statements of the sort

image

3.  The warnings that there is No file Sample.aux and that Reference ‘eq.1’ (‘eq.2’) undefined are to be expected on first compilation. The Sample.aux file contains the information image needs to cross-reference the source Sample.tex. Yet image does not write it until the end of compilation, and, consequently, it does not yet know that you have defined references eq.1 and eq.2.

4.  Compile the source file again. This time the compiler should find a Sample.aux file to use for cross-references and not warn you about undefined references.

5.  The last part of image’s message tells you that the files sample.aux and sample.dvi were written, and that the typeset document is one page long. If you have changed some labels or references, then image may request that you compile the source file again in order to incorporate the updated .aux file.

6.  If there were no errors, your working directory should now contain the files

Sample.tex source file

sample.aux auxiliary working file with reference numbers and such

sample.log log of image messages; similar to messages flashed on screen

sample.dvi device-independent, viewable version of typeset document

7.  If you are lucky enough to get a sample.dvi file, then look at it to admire your work. On Unix you do this with:

image

On Windows use Yap (yet another previewer) or the DVI button.

8.  If you get complaints that image was not happy with the way a line fits on the page, just ignore them unless you are really going to publish the paper. If there are real errors, correct them one at a time and proceed. If you cannot figure out where the error is, try forcing image to skip it by continually entering Enter. Alternatively, you isolate the location of an error by moving the %end{document} up in your document until image compiles with no errors. Then move it down gradually, recompiling at each stage until the error is uncovered.

9.  To see how image responds to errors, make these mistakes:

image

The first error should illicit the response

image

This error message indicates with a carriage return where image notices something is wrong, in this case, that it has never heard of iten. Below that, image indicates that it thinks you meant to write item. In the second case where a $ is left off, image responds with

image

We see that image knows something is wrong in the math environment (we left off the second $, but it does not know it until the next math environment begins with a [on line 17. Consequently, you need to look at line 17 in the source file, and work back from there to see where there is a missing math delimiter.

10. Once you have produced a complete .dvi file, you convert it into the PostScript file sample.ps for printing with the dvips command:

image

Here the -o option places the output into the file whose name follows. If you leave off the -o option, then the .ps file might well be sent directly to some printer. In WinEdt, the dvips command is issued by pushing the dvi ”—* ps button. You should get an output statement showing you all the page numbers that have been converted, and indicating that the output is placed in the file sample.ps. There is also the psimage version of image that uses PostScript fonts in place of image’s standard Computer Modern fonts. This does produce a smaller .ps file in the end.

11.  If you want a .pdf file, you may issue the pdfimage command in the first place, or use the dvipdf command to convert your .div file. However, if the .eps figures in your file do not get placed in the .pdf file properly, we recommend the use of Adobe Distiller to convert the entire .ps file to a .pdf one.

12.  If your document does not contain any embedded PostScript figures, then you may be able to print it successfully from the .dvi previewer. Otherwise, we have found it best to create a .ps file of your document and to print that.

13.  Now print your sample.ps file. You do that from a GhostScript viewer, such as GSview, or with Unix printer commands:

image

14.  Now let us go back and add some more features to Sample.tex:

a.  Include the sample PostScript figure image_Compile.eps from the disk or Web into your document.

b.  Include Table 22.1 into your document (the commands are all given in the text). First keep the table in one place by using just the tabular environment, and then let it float by placing the tabular environment within a table environment.

c.  Include a line in your document that uses the ef command to refer to the floating table by its label.

d.  Create a title page by placing your personalized versions of these commands into the preamble:

image

After placing these commands in the preamble, you need to create the title in the body of the document with:

image

1  We are able to scale and rotate with no loss in quality because PostScript figures are not bit maps, but instead contain a text description of the figure and the fonts.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.30.162