Knowing how to send data to the printer is only half the battle; being able to produce professional-quality output is also essential in the modern world. At the command line, the process of producing high-quality output occurs in two steps: text editing, in which the textual content of your document is entered, and text formatting, in which the content is arranged in a pleasing manner for printing. This method for creating documents stands in contrast to the WYSIWYG method with which most users are familiar. WYSIWYG is an acronym that stands for What You See Is What You Get. This refers to the fact that in most word processors, which are usually graphics based, you see fonts, styles, and document layout on the screen as they appear when printed on paper. The WYSIWYG method of document editing has not always been the norm, however, and it has its limitations. Chief among them is the fact that it forces the user to be aware of formatting consistency at all times; you must keep track of the font size, style, spacing, and indentation of each piece of text yourself, which can interfere with your stream of thought as you write. When using a text formatter, on the other hand, you only need to specify that a certain piece of text is a chapter or a title, for example, and the text formatter will take care of the details of layout and appearance for you. For many types of documentsespecially lengthier onesthe text editing/formatting method of creating documents is more powerful and convenient. In Linux, you can use a simple text editor such as vi or emacs to create text documents, as you learned in Chapter 20, "Creating, Editing, and Saving Text Files." To use these editors, you input text in free form, without worrying too much about text formatting or consistency issues, such as centering, indentation, or typefaces. To control the appearance and layout of your text, you write the document to include formatting codes that will be used by a special formatting program to control the quality and layout of the output. Although using text editors sounds complex, with practice you can learn to use them to enter and format text quickly and easily. This document-editing paradigm is a powerful one that can be used to create professional-looking layouts for large-scale documents, such as books or manuals. Introducing the LaTeX-2e FormatterSeveral formatting systems are present on a typical Linux system, including the classic Unix formatter, TRoff. The most modern and widely used formatter today, however, is LaTeX-2e, which uses the TeX formatting engine as its core. Using LaTeX-2e, you can quickly produce high-quality output through a laser printer using a text editor such as vi or emacs. In fact, many professional writers, self-publishers, and educators swear by LaTeX rather than more common and widely understood WYSIWYG word processors, largely because LaTeX makes the production of high-quality output so easy.
Understanding LaTeX BasicsCreating a LaTeX document is easy: Start your editor of choice (usually vi or emacs) and enter text. All LaTeX documents begin as simple text files. Here are some of the important basics about the text you enter into a LaTeX document:
Now it's time to begin your first LaTeX document.
Creating an Empty LaTeX DocumentAny basic LaTeX document contains at least three commands: \documentclass{}, which tells LaTeX what sort of page layout you want to use, and then \begin{} and \end{}, which demarcate the beginning and end of the text body, in that order. Listing 21.1 is a simple article-style document for letter-size paper containing only one line of text. Start a text editor now and enter the listing yourself. Listing 21.1. A Short, Simple LaTeX Article Document\documentclass[letterpaper,12pt]{article} \begin{document} This is a very short document. Here is my one line of text. \end{document} The first line of this document, which calls the \documentclass command, contains information about the class to which this document belongs. The information on the right in the braces specifies that this example belongs to a class of documents called article. LaTeX uses classes to determine basic formatting, such as setting margins and indenting for new paragraphs. You assign a class to every LaTeX document you create. Table 21.1 lists the basic LaTeX document classes.
For most day-to-day usessuch as creating memos, small presentations, personal or business letters, and so forththe article class is the best choice. In addition to selecting a class for each LaTeX document, you may also specify several class options inside an optional pair of brackets to control additional aspects of formatting, such as paper size and column-based layouts for the entire document. Inside the brackets that follow the \documentclass command, you can specify multiple options by separating them with commas. Table 21.2 lists the common class options.
By carefully choosing a document class and document class options to suit your output medium and formatting needs, you enable LaTeX to manage automatically nearly all formatting concerns. That leaves you free to concentrate on typing your document into your favorite text editor. Here are some sample uses of options, with descriptions:
Formatting and Printing Your First DocumentPrinting a LaTeX document is a two-step process. You first must format the document and save the formatted text in a new file. Then you print the formatted text file. To format an existing document, you call the latex command, supplying the name of the LaTeX source file as an argument. Assuming that you've typed in the short document in Listing 21.1 and saved it as myfile.tex, you can cause LaTeX to read and format the document for printing by calling the latex command this way at the command line: [you@workstation20 ~]$ latex myfile.tex This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4) entering extended mode (./myfile.tex LaTeX2e <2003/12/01> Babel <v3.8d> and hyphenation patterns for american, french, german, ngerman, b ahasa, basque, bulgarian, catalan, croatian, czech, danish, dutch, esperanto, e stonian, finnish, greek, icelandic, irish, italian, latin, magyar, norsk, polis h, portuges, romanian, russian, serbian, slovak, slovene, spanish, swedish, tur kish, ukrainian, nohyphenation, loaded. (/usr/share/texmf/tex/latex/base/article.cls Document Class: article 2004/02/16 v1.4f Standard LaTeX document class (/usr/share/texmf/tex/latex/base/size12.clo)) (./myfile.aux) [1] (./myfile.aux) ) Output written on myfile.dvi (1 page, 288 bytes). Transcript written on myfile.log. [you@workstation20 ~]$
After processing the file and displaying some notes related to formatting, the latex command creates a file called myfile.dvi and then exits. The new file is called a device-independent file and contains the formatted output for myfile.txt. A device-independent file contains all the information necessary to create good-looking document output on any type of printing device. To print a device-independent file such as myfile.dvi, you must convert it into the correct type of file for the printing device you plan to use. For consumer-class laser or inkjet printers, you should use the dvips program for this conversion, supplying the name of the device-independent file as an argument: [you@workstation20 ~]$ dvips myfile.dvi The dvips command converts a device-independent file into Adobe PostScript data, which can then be used to create nicely printed output on a consumer-class printer. The dvips command generates varying amounts of output on the console display as it runs. Then dvips creates a print job for the formatted output and sends it to the print queue. Your printer then prints the document.
Selecting a Page StyleNow that you have printed a simple one-line document, it is time to begin creating more useful documents. Obviously, most documents contain more than a single line; generally, a great deal of content exists between the \begin{} and \end{} commands in a LaTeX document. LaTex uses page styles to determine the use and placement of page and chapter numbers on the printed page. Table 21.3 lists the three common page style options. The default LaTeX page style is plain. You can use the style{} command to choose an alternate page style.
Creating Title and Author InformationLaTeX provides an easy way to print an attractive title page for your documents: You supply title, author, and date information in your source document and then use the \maketitle command. To define the title and author information of your document, you include several title-specific commands after the \documentclass{} command and before \begin{}. These commands are
After you supply a title, author, and optional date, you can insert a title page in your document at any time by issuing the \maketitle command in the text. Controlling LaTeX Paragraphs, Line Breaks, and PagesIn LaTeX, paragraph formatting (indentation, blank space between paragraphs, and so on) is handled automatically. The only task left to the writer is to indicate when a new paragraph should begin. You do this by inserting a blank line in the LaTeX source file using your text editor's Enter key. The following text illustrates this technique: \documentclass[letterpaper,12pt]{article} \begin{document} \pagestyle{empty} This is some text in a latex document. This is some text in the same paragraph. This text will also appear in the first paragraph. But this text will begin a new paragraph, because there is a blank line before it. \end{document} Each time a blank line appears in the text file, LaTeX assumes that a new paragraph should begin. Within paragraphs, LaTeX automatically reflows text to fit the margins for the current page style. This means that the first paragraph in the example does not necessarily represent three lines of text in the final printed output; instead, LaTeX reformats and word wraps the text in these three lines as though they were typed without pressing the Enter key. Sometimes it is the writer's intent to insert a line break. You can think of a line break as being like pressing the Enter key in the middle of a paragraph in a plaintext file; the cursor moves to a new line without beginning a new paragraph, indenting, or leaving empty vertical spaces after the previous line. To move to a new line without beginning a new paragraph, add the \newline command where you want the break to occur: \documentclass[letterpaper,12pt]{article} \begin{document} \pagestyle{empty} This is the first sentence in a paragraph. This is the second sentence in the paragraph, and it doesn't begin on a new line but is instead reflowed with the first sentence.\newline This sentence, however, begins on a new line.\newline And this one.\newline And so does this one, illustrating that commands can appear at any place within the text. And this is a new paragraph, of course. \end{document} One sample of output generated by this source file is shown in Figure 21.1. Figure 21.1. An output page generated using a number of line breaks.If it's unclear to you just how the final printed output is affected by the \newline command and blank lines for new paragraphs, experiment by printing some LaTeX text files of your own. Organizing Larger TextsTo create a longer document with sections, section headers, a table of contents, or other similar structural elements, you use LaTeX sectioning commands. You insert these commands just like the other LaTeX commands you've encountered so farby preceding them with a backslash character anywhere in the body of your text. They are used to delineate blocks of text of the sorts you find in most larger documents. Table 21.4 lists the LaTex sectioning commands.
When you use these basic sectioning commands, it is a simple matter to create a well-structured document with an accurate table of contents just by adding a few extra commands. Consider the following excerpt from a LaTeX source file: \documentclass[letterpaper,12pt]{article} \begin{document} \pagestyle{empty} \section{Learning About Frogs} This is the first paragraph in a section about frogs. We will have two subsections, one about frog legs and one about frog sounds. \subsection{Frog Legs} Frogs often have legs. These are used for jumping, walking, and other types of amphibian fun. Often, frog legs are green. That is all you need to know about frog legs. \subsection{Frog Sounds} Frogs also make sounds. These sounds are often characterized as 'ribbits' but this word can sometimes sound silly, so we won't talk about them any more. That is all you need to know about frog sounds. \section{Learning About Birds} This is the first paragraph in a section about birds. Birds are really not very much like frogs at all. \end{document} One sample of output generated by this source file is shown in Figure 21.2. Figure 21.2. The section and subsection commands have been put to good use here.Notice in Figure 21.2 that LaTeX has automatically numbered the sections and subsections for you. If you insert a \tableofcontents command before the first \section command, LaTeX prints a nice table of contents on the first page containing the sections and subsections and the pages on which they appear. Formatting the Body of Your TextSometimes simple page and document structure is not enough to effectively communicate in written text. In many documents, you need to emphasize certain words or format them in a special font or size to indicate their use or meaning. LaTeX uses a number of commands to center text, emphasize text, insert text in quotations, and add other formatting to printed text. You enter these commands immediately before or on either side of the text you want to format. Here are some of the most common LaTeX text formatting commands and some examples of their use:
Figure 21.3 shows the output generated by all the commands we've just discussed. Figure 21.3. Using a simple selection of commands in a plaintext editor, you can add structure to printed documents using LaTeX.Although a wealth of other formatting commands exist, these are enough to produce most common types of documents using LaTeX. You can learn more about many of these commands by visiting the links provided in the section called "More Information About LaTeX" later in this chapter. Inserting Special CharactersPeople who work in the publishing industry are familiar with the special characters used in printing and typesetting to insert symbols such as dashes and ellipses into text. These symbols usually can't be entered directly from a keyboard. Luckily, they can be generated in LaTeX using commands or special strings. The most common among these characters are shown in Table 21.5.
To illustrate the use of these special characters, consider the following source line:I went to the store---the bookstore, and I was there for hours\ldots The printed output from this line would contain the indicated special characters instead: I went to the storethe bookstore, and I was there for hours… Putting It All TogetherWith the LaTeX commands you've just learned, you can produce a professional-quality printing of a novel from text written with a text editor such as emacs or vi. Listing 21.2 shows the text and formatting for a document that employs several of the commands presented in this chapter. In Listing 21.2, you do the following:
Listing 21.2. A LaTeX Document Using Numerous Commands\documentclass[letterpaper,openany,12pt]{book} \title{My Novel} \author{Aron Hsiao} \begin{document} \pagestyle{headings} \maketitle \chapter{Beginning My Novel} It is in \emph{this} chapter that I begin my novel. Unfortunately, this chapter is only two paragraphs long. Still, it promises to be a wonderful novel, because it illustrates the formatting prowess of LaTeX. Furthermore, it is the first of these paragraphs which is the longest, but not by much. Still, longest is longest, and to the victor go the spoils---at least, that is what my history teacher used to tell me. \chapter{Ending My Novel} My novel only consists of two chapters\footnote{Though a third is in the works} right now. The second chapter is just a mysterious shopping list\ldots \begin{itemize} \item Cabbages \item Red socks with yellow stripes \item A green rubber washbasin \item The latest issue of \emph{Time Magazine} \end{itemize} Perhaps someday, all of the items in this shopping list will be explained. But then I suppose we will leave that bit of mystery for the sequel. \end{document} Although this document is relatively short, you will find that if you type it, format it with the latex command, and print it with the dvips command, the final result is quite impressive, as shown in Figure 21.4. Figure 21.4. Our final impressive sample document, created and sent to the printer using the LaTeX text formatter.
More Information About LaTeXWe only scratched the surface of LaTeX and its capabilities in this brief introduction. To learn more about LaTeX or use LaTeX on serious projects, you should consult more in-depth documentation. These sources of online documentation are a good place to start:
|