Online Book Reader

Home Category

Running Linux, 5th Edition - Matthias Kalle Dalheimer [367]

By Root 1069 0
ado, let's dive in and see how to write a simple document and format it, from start to finish. As a demonstration, we'll show how to use LATEX to write a short business letter. Sit down at your favorite text editor, and enter the following text into a file (without the line numbers, of course). Call it letter.tex:

1 \documentclass{letter}

2 \address{755 Chmod Way \\ Apt 0x7F \\

3 Pipeline, N.M. 09915}

4 \signature{Boomer Petway}

5

6 \begin{document}

7 \begin{letter}{O'Reilly and Associates, Inc. \\

8 1005 Gravenstein Highway North \\

9 Sebastopol, C.A. 95472}

10

11 \opening{Dear Mr. O'Reilly,}

12

13 I would like to comment on the \LaTeX\ example as presented in

14 Chapter~20 of {\em Running Linux}. Although it was a valiant effort,

15 I find that the example falls somewhat short of what

16 one might expect in a discussion of text-formatting systems.

17 In a future edition of the book, I suggest that you replace

18 the example with one that is more instructive.

19

20 \closing{Thank you,}

21

22 \end{letter}

23 \end{document}

This is a complete LATEX document for the business letter that we wish to send. As you can see, it contains the actual text of the letter, with a number of commands (using backslashes and braces) thrown in. Let's walk through it.

Line 1 uses the documentclass command to specify the class of document that we're producing (which is a letter). Commands in LATEX begin with a backslash and are followed by the actual command name, which in this case is documentclass. Following the command name are any arguments, enclosed in braces. LATEX supports several document classes, such as article, report, and book, and you can define your own. Specifying the document class defines global macros for use within the TEX document, such as the address and signature commands used on lines 2 to 4. As you might guess, the address and signature commands specify your own address and name in the letter. The double backslashes (\\) that appear in the address command generate line breaks in the resulting output of the address.

A word about how LATEX processes input: as with most text-formatting systems, whitespace, line breaks, and other such features in the input source are not passed literally into the output. Therefore, you can break lines more or less wherever you please; when formatting paragraphs, LATEX will fit the lines back together again. Of course, there are exceptions: blank lines in the input begin new paragraphs, and there are commands to force LATEX to treat the source text literally.

On line 6, the command \begin{document} signifies the beginning of the document as a whole. Everything enclosed within the \begin{document} and \end{document} on line 22 is considered part of the text to be formatted; anything before \begin{document} is called the preamble and defines formatting parameters before the actual body.

On lines 7 to 9, \begin{letter} begins the actual letter. This is required because you may have many letters within a single source file, and a \begin{letter} command is needed for each. This command takes as an argument the address of the intended recipient; as with the address command, double backslashes signify line breaks in the address.

Line 11 uses the opening command to open the letter. Following on lines 12 to 18 is the actual body of the letter. As straightforward as it may seem, there are a few tricks hidden in the body as well. On line 13 the \LaTeX\ command generates the logo. You'll notice that a backslash follows as well as precedes the \LaTeX\ command; the trailing backslash is used to force a space after the word "LATEX." This is because TEX ignores spaces after command invocations; the command must be followed by a backslash and a space. Thus, \LaTeX example would print as LATEXexample.

There are two quirks of note on line 14. First of all, a tilde (~) is present between Chapter and 9, which causes a space to appear between the two words, but prevents a line break between them in the output (that is, to prevent Chapter from being on the end of a line, and 9 from

Return Main Page Previous Page Next Page

®Online Book Reader