Chapter Twenty-Two

LATEX for Text: Scientific Document Processing, Markup Language

22.1 WHY image

In the 1980’s Donald Knuth created a revolutionary computer program called image (“tech”) for producing book-quality technical documents [Knuth 86] that rivaled the documents produced by a professional human typesetter. In 1985 Leslie Lamport combined a number of image commands into a set of higher-level macros known as image [Lap 85] that has fewer details to worry about than image. At present image is widely used for scientific journals, books, and reports, and for good reason. image automatically generates tables of contents, lists of figures, cross-references, equations, section and figure numbers, indexes, and bibliographies. Nevertheless, it is the mathematics that image does better than any other electronic system. This chapter describes enough of the basic elements of image for you to produce your own beautiful-looking scientific documents [Wilk 95].

To produce a image document, all you have to do is prepare a source file E with some image commands embedded at the correct places, and then compile the E source. Because the source file is an ASCII file, it is possible to write and read it on any computer system with no special programs. Of course one needs a copy of the image program to typeset this ASCII file, but the program is free and readily E available.

The basic steps for using image are shown in Figure 22.1. It is seen to be quite similar to compiling and running a code, and so makes a useful last part for this book. By convention, the image source file has a .tex extender and the compiled version of the source has a .dvi extender. We have called our source file Paper.tex and the compiler has produced the device-independent file Paper.dvi from it. A .dvi file is independent of any specific computer system or hardware, and is viewed on a computer screen with a program known as a viewer, or converted to a PostScript (.ps) or Portable Document Format (.pdf) file to be sent to a printer or posted on the Web.

image

Figure 22.1 The steps followed and utilities used in preparing a document with image. The source file is Paper.tex, the device-independent file is Paper.dvi, and the file ready for printing/posting is Paper.ps or Paper.pdf.

The theory behind image is that authors should worry about the contents of a document and leave the format up to the computer. In practice there are a number of steps to follow before authors see their documents typeset. This is in contrast to WYSIWYG (what you see is what you get), in which the formulas appear on the computer screen as you enter them. We personally prefer a markup-language approach for complicated documents, especially if that document is to be placed in a digital library. We find that not having to concentrate on how things look until after the writing is over lets us get the hard part of creation done first. However, there are a number of image commands to learn, and debugging complicated equations can be challenging. Nevertheless, a thing of beauty is a joy forever.

22.2 STRUCTURE OF A image DOCUMENT

image is a member of a class of languages known as markup languages.1 The E term “markup” comes from the printing trade, where an editor would “markup” a document by inserting symbols to indicate properties such as font size and spacing. This same purpose is served by the imagecommands, only in this case they are not for a human typesetter to follow, but for a computer. Inasmuch as image is a compiled, in contrast to an interpreted, language, when you are done with the writing, the compiler will read your entire document, place the tables, figures, and so forth, in the best places throughout your document, and then cross-reference the whole thing. Like other compilers, you may have to remove all errors before the compiler produces anything, and the compiler may need to make several passes through the document to get it all right.

22.3 SAMPLE INPUT FILE (SAMPLE.TEX)

A image source file has two basic parts:

image

The first part is the preamble, and it starts with a statement of the type of document your document is to be. The choices, classname = article, report, book, slides, or letter, seem to cover most everything. Older versions of image started with a documenttype command, but the newer image uses the documentclass command. The [options] argument might include the font sizes (in points)— 10 pt (default), 11 pt, or 12 pt—as well as onecolumn (default), or twocolumn, oneside or twoside, or landscape. With documentclass{article} you obtain a document in 10 pt font. The preamble might also include macros (commands) that you have defined for your own use, and commands for including special packages, for example, for dealing with graphics.

To give you a real example, here, and on the CD is Sample.tex, an edited version of a problem set with a comment following the %:

image

image

When we apply image to these paragraphs we produce the text: E

22.4 SAMPLE image OUTPUT

This document consists of bits and pieces of a final examination given at Oregon State University. The material is from the text Computational Physics [CP 05], which does not cost much $$.

We have left off anything fancy, like title page, from the preamble and used an enumerated list environment (enumerate), with mathematics environment inserted as needed. An Environment usually begins with egin{name}and ends with end{name}.

image

22.4.1 Brief Look at Input File

Most of the characters in our input file Sample.tex are the same as in the output. However, mathematical symbols, Greek, and some special characters are entered with commands: the math symbols and Greek, because they do not appear on the keyboard, the special characters because image uses them within its own commands.

Look at the commands in Sample.tex. You will notice that image commands usually consist of a backslash followed by a word. As an instance, we use item,egin{equation}, and emph{Computation Physics} respectively The Greek letter ψ was produced with psi, and the mathematical symbol image with sqrtN. As we also see in these examples, the special characters { and } are used to enclose the argument to a image command. To illustrate, the image is applied to N via sqrtN, and both the words Computational and Physics are emphasized by emph{Computational Physics}. Of special importance in this file is the dollar sign $. When used as part of the text to indicate a dollar sign, it is entered as $. When used as part of image command to switch between text and math modes, it is entered as $, for example:

coupled wave functions $psi_1$ and $psi_2$ coupled wave functions ψ1 and ψ2

Although we talk more about this in a separate section, we produced mathematical equations that were separated off from the text (“displayed”) by placing them between the commands [and ], or between egin{equation} and end{equation}, or between egin{eqnarray} and end{eqnarray}.

22.4.2 Special Characters

The characters

image

are called “special characters” because image uses them for its own purposes. This means that you cannot use them unless you do something special. If you simply want the special character to be printed just as any other letter, include a in front of the character:

image

There are two exceptions to this rule. You cannot produce via \, because image uses \ to indicate the end of a line. So produce it by typing $ackslash$:

image

The second exception is the tilde. Seeing that ˜ means “place a tilde accent over the following letter,” a ˜ is produced by ˜{}, that is, having nothing there (empty braces) for the tilde to go over:

image

22.4.3 Paragraphs, Spaces, and Breaks

Look now at the two short paragraphs below the headings in Sample.tex. A new paragraph is indicated by one (or more) skipped lines. image then automatically indents the paragraph as appropriate for its place in the document, for example, it does not indent at the beginning of a new section. To ensure that our first paragraph after the table is not indented, we placed a oindent command there.

Ordinary text is entered with no special commands. In general you do not even have to worry about the spacing between words and lines, or where lines begin and end. image treats any number of spaces as equivalent to a single space, and views the carriage return ( Enter) at the end of a line as though it were just another space. If you want to insist on an extra blank space being inserted at some point, then you insert a command, that is, a blank space preceded by a backslash. This means that you do not have to worry about spaces in your input, although you should give it some structure with spaces and new lines to make the content clear, as you would with any coding.

Though you should not have to do this for most of your work, sometimes you do need to insert a horizontal or vertical blank space in your document. You request that imagedoes that (a “request” because imagehas its own ideas about spacing, and it gets the last word) with the hspace{} and vspace{} commands. You become more insistent by using the hspace*{} and vspace*{} forms. These commands take the length of the space as an argument in the braces. The length is specified with a number of dimensional units that include:

image

Here, ex and em are the sizes of a typeset x and m, pt and pc are the typesetting measures of points and picas, and the others are obvious.

image

If you want to insist on a line ending someplace and a new paragraph beginning, then you insert a double backslash \ to end the line. In addition, you add some extra blank space after the line by including an argument to \. To illustrate, we place here, \*[3ex]

and you see that it skips three ex’s of space before printing this line.

Usually image decides where to start a new page according to its own internal rules. As an example, it tries not to split up tables or place the last line of a paragraph on a new page. If you disagree with image’s decision and wish to force a page break, use:

image

Though you would never “double-space” a book or journal article, there are occasions when you want to double-space a draft, or to make a business letter fill the page. If you want to vary the interline spacing, you need to change the LT Xenvironmental variable from its default value of 1. Generally you do this in the preamble with:

image

where we have set the spacing to one and three-quarter lines. The command then holds for the entire document. (You may try to reset the spacing locally, but that may mess up the length of the page.)

22.4.4 Quotation Marks and Dashes

Despite most of us never worrying about such things, image is fairly serious when it comes to quotation marks and dashes. This is a consequence of its being a typesetting program, and typesetters are very serious about such things. When writing in image, we usually place a word in quotation by placing two left quotes on the left side and two right quotes on the right. As a case in point, the quotes in

“golfballs appear to ‘drop out of the sky’ near the end of their trajectories”

is produced from the input

image

Scrutinize how the left double quote “ is entered as two left single quotes in succession, ‘ and ‘, and the right double quote is entered as two right single quotes, ‘ and ‘. As a general rule, one should not use the (undirected) ‘double quote’ character “ on the keyboard. (Some text editors, like emacs, automatically substitute either “ or “ when you enter “ if they know you are entering a image document.)

image and typesetters deal with dashes of three lengths:

image

22.5 FONTS FOR TEXT

The basic theory behind image is that the user should worry about content and let the program worry about presentation. So it follows that you should tell image whether you want some material to be emphasized, or emboldened, or presented as mathematics, but you should not have to worry about the name or size of the actual font being used. To give an instance, you emphasize text, and image usually reacts by placing that text in italic font. However, image uses a different italic font for text than it does for mathematics; for example, this (math) is different from this (text).

By default, image uses the Computer Modern fonts, which give a character-istic look to image documents. If you really want some material to have a certain presentation that differs from image’s standard, then you may have to change some things “by hand” or develop some macros. However, those occasions should be rare and should be done only at the last minute before final presentation. The words you wish to have in a specific format are usually given as the arguments, for example:

Emphasized text

emph{Emphasized text}

Bold text

extbf{Bold text}

Teletype (monospaced) text

exttt{Teletype (monospaced) text}

SMALL CAPITAL LETTERS

extsc{small capital letters}

f = md2x/dt2 (math)

$f = m dˆ2 x/dtˆ2$ (math)

Explicit fonts are obtained with commands of the sort:

Roman font

extrm{Roman font}

Italic font

extit{Italic font}

Sans serif font

extsf{small Sans serif font}

Slanted, but not italics

extsl{Slanted, but not italics}

If you are working with someone else’s document, you may run into some old style commands for font changes. Though not strictly image 2e, these still work:

Emphasized

{em Emphasized}

Bold

{f Bold}

Teletype

{ t Teletype}

22.5.1 Type Sizes

image

22.5.2 Fancy Text Accents

English appears to be an underachiever when it comes to accents. However, if you wish to include some foreign text in your documents, then you may well need some of the accents image provides:

image

If you want to accent mathematics, then different commands are needed yet, and we will get to that.

22.5.3 Math Symbols in Text

Placing mathematics in text, such as ∫ f(x)dx, is done by placing the mathematics between dollar signs, for example, $int f(x)dx$. Other symbols are created in math mode with the commands:

image

22.6 ENVIRONMENTS

A image Environment usually begins with egin{name} and ends with end{name} . Indeed, since a image document begins and ends as egin{document}end{document}, the entire source file is in a document environment. Other environments include:

array

math arrays

center

centered text or tables

description

definition list

document

the full image document E

enumerate

numbered and lettered list

eqnarray

aligned equations

figure

floating figure

itemize

bullet list

list

custom list

minipage

page within a page

picture

basic diagram drawn by image

quotation

long quotation

quote

short quotation

tabbing

define and use tabs

table

floating and referenced table

tabular

in-place table

verbatim

set as entered in exttt

verb|text

in-line verbatim

22.7 LISTS

image supports three types of lists:

enumerate: for numbered lists;

itemize: for bullet lists;

description: for definition lists like this;

list: custom lists.

image

The numbers or bullets are provided automatically by image, so all the user has to do is separate items by an item command:

1.  This is a numbered list, but you need not enter numbers.

2.  This second item contains math sin2 x + cos2 x = 1.

image

Sublists are created just by starting another list within an existing list. image generates yet different symbols for sublists:

1.  First item in list

a.  First item in sublist

b.  Second item in sublist

2.  Second item in list

image

22.7.1 Text Tables

Tables are produced in the image text mode by entering the tabular environment. It is entered via egin{tabular}{}, and exited via end{tabular}. The table is placed in the text at the location in which it is entered. If you want a table that is numbered, that has a caption, and that can be referenced, then you insert your abular commands between a set of able commands. We describe that later.

Here is a table from one of our Java chapters:

image

It is the result of:

image

The argument in braces after the egin{tabular} command specifies the format for the columns in the table. The l indicates that the first column is left-justified. The two c’s indicates that the next two columns are centered, and the last r indicates that the fourth column is right-justified. The vertical bars | are optional and instruct LAT E X to place vertical bars in the columns indicated. The fact that we have bars before the first column and after the last means that we want bars on the outsides of the table.

Peer at how we have two hline commands before we enter the data, a single hline command after we enter the column headings, and a single hline command after we have entered all the data. These commands cause the horizontal lines in the table to be drawn. They too are optional and must be placed after a row separator \ or before the rows begin.

Data are entered into the table one row at a time. Each row ends with a double backslash \, and the columns are separated by an ampersand character &. Mathematical symbols or equations are placed in the table by switching to math mode, which we did with < and >.

You do not have to specify the number of rows in your tables; image will know when you are done from the end{tabular} command. In the present example we end the last row with a \. Normally that is not necessary, but we include it because we have a hline command to follow. If you need some more vertical space between two rows, include a space option such as \* [2ex] to end a row. We did that after the heading.

22.7.2 Floating Tables

In published books and journals, tables and figures often “float” on the page. This means that they are placed where they fit in best, which is often not at the place where they are first mentioned. Clearly, this becomes more important as your table or figure gets larger and harder to fit in someplace. Table 22.1 is an example of a floating table. It is produced with the commands:

image

Table 22.1 A sample floating table with a number and a caption.

Binary abc

= a × 22

+b × 21

+c × 20

= Decimal

000

0

0

00

001

0

0

11

010

0

1

02

111

1

1

17

Inspect how the table is made by inserting the standard egin{tabular} and end{tabular} pair within a egin{table} and end{table} pair. In addition, there are caption{} and label{} commands within the table environment but outside of the tabular environment. The argument to caption contains the caption that appears under the table. (If the caption command appears before the tabular command, the caption will be above the table.) The argument to label is a tag that is used to reference the table with the ef command (the numbering is done automatically):

Table 22.1 is referenced         Table˜ ef{tab.binary2} is referenced

This same scheme of labeling and referencing is used with equations.

22.8 SECTIONS

and

22.8.1 Subsections

and

22.8.1.1 Subsubsections

image permits you to have sections, subsections, and subsubsections in your documents. You give each a title, and E gives each a sequential number, which changes automatically as other sections are inserted or removed, and a different sized heading. By way of example, the section, subsection, and subsubsection right above this paragraph were produced with the commands:

image

Placing an asterisk before the title of the section or subsection will suppress image ‘s automatic numbering, as in section*{A Section without a Number}.

22.8.2 Quotations and Footnotes

image contains two commands for setting off text from its surroundings. The quote environment is used for short quotations, while the quotation environment is appropriate for longer ones. They differ in indentation:

This is a quote. Look at how this first paragraph is indented. The quote environment is used for short quotations.

This is still the quote Observe how this second paragraph is indented. To repeat, a quote environment is for short quotations.

This is a quotation. Observe how this first paragraph is indented. The quotation environment is appropriate for longer quotations.

This is still the quotation. Check how this second paragraph is indented and spaced. A quotation environment is for longer quotations.

image

Footnotes are created with the footnote{text} command. You place the command where you want a reference to the footnote, and image automatically places a reference there and sets the note at the bottom of the page. For instance, we place a footnote here2 with footnote{Sample note with its own period.}. You should find it below and below a horizontal line.

1  Others include HTML, XML, GML, and MATHML.

2  Sample note with its own period.

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

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