Creating High-Quality Documents at the Command Line


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 Formatter

Several 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.

How Is It Really Pronounced?

For reasons that have faded into the obscurity of history, TeX and LaTeX are most correctly pronounced "teck" and "layteck," respectively, not "tecks" and "laytecks," although in the past few years, this distinction has become less important.


Understanding LaTeX Basics

Creating 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:

  • Some characters are reserved for use as formatting codes. The backslash character (\) is reserved in LaTeX because it marks the beginning of a command; it does not show up in formatted output.

    Other special characters include the hash (#), dollar sign ($), percent sign (%), caret (^), ampersand (&), underscore (_), left and right braces ({}), and tilde (~). To insert any of these characters in your final document, you must prefix them with a backslash, or they will not appear properly. For example, to insert the text "50% of $35.00," you type 50\% of \$35.00 in your text editor document.

  • LaTeX automatically formats spacing. LaTex always inserts a single space between words, a given amount of space between paragraphs, and so on. This means that unneeded extra spaces between words or multiple blank lines don't appear in final output unless you tell LaTeX explicitly to include them.

  • LaTeX commands begin with a backslash and then are typically followed by a single word of text. The following is an example:

     \command 

    Some commands require options or arguments, and in such cases you might see commands with more complex structures, usually using brackets or braces:

     \command[option] \command[option]{argument} 

    Remember, the command and the options or arguments passed to it will not appear in the final output of the document; LaTeX uses the command instead to change some aspect of the document's text layout, such as a typeface or page style.

  • LaTeX commands are case sensitive. Uppercase and lowercase letters matter.

Now it's time to begin your first LaTeX document.

Identifying a LaTeX File

In the computer world, identifying a file's type using a three-letter extension to the filename has become common. For example, .gif denotes a Graphical Interchange Format file, and .doc indicates a Microsoft Word file.

When you save a LaTeX document in vi or emacs, convention says that you should name it with a .tex extension to indicate that it contains TeX/LaTeX formatting commands.


Creating an Empty LaTeX Document

Any 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.

Table 21.1. Basic LaTeX-2e Document Classes

Class

Description

article

This is the smallest, most basic document type and performs formatting appropriate to articles and papers just a few pages in length.

report

This is a slightly more detailed, structured document class intended to be used for papers and reports that might contain sections or chapters.

book

This is the most structured document class, intended to be used for works that will be broken into multiple chapters and might need a table of contents or index generation.


How Do You Preview a Font or Class?

To preview the appearance of any font or other LaTeX item, type and print a small amount of text. Doing so saves you the trouble of finding that you prefer another choice after you've printed your entire final document.


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.

Table 21.2. Common LaTeX-2e Class Options

Option

Description

a4paper

Formats output for printing on A4-sized paper

b5paper

Formats output for printing on B5-sized paper

letterpaper

Formats output for printing on letter-sized paper

legalpaper

Formats output for printing on legal-sized paper

onecolumn

Specifies that the document should be formatted into a single column as wide as the page (default)

twocolumn

Specifies that the document should be formatted into two vertical columns

oneside

Specifies that margins should be set assuming that only one side of each printed page will be used

twoside

Specifies that margins should be set assuming that two sides of each printed page will be used (different margins for even and odd pages)

openright

Specifies that for two-sided output, chapters should begin on right-side pages only

openany

Specifies that for two-sided output, chapters may begin either on left-side or right-side pages

npt

Specifies that the basic font size for text in the document should be set to n points (the default is 10)


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:

  • \documentclass[a4paper,twocolumn,12pt]{article} Your document will be formatted as an article for A4-size paper. The text will be arranged into two vertical columns on each page. The body of the text will appear in a 12-point font.

  • \documentclass[letterpaper,twoside]{article} Your document will be formatted as an article for letter-size paper. The formatter will assume that you are printing on both sides of the page; the margins for even- and odd-numbered pages will therefore be different to enable easy binding at one edge of each page.

  • \documentclass[legalpaper,14pt]{book} Your document will be formatted as a book for legal-size paper. The body of the text will appear in a 14-point font.

Formatting and Printing Your First Document

Printing 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 ~]$  

Why Do You Get an Error When You Run LaTeX?

If you receive a command not found error when trying to run the latex command, LaTeX has not been installed on your computer system. As noted earlier, refer to Chapter 31 for instructions on how to install the "Authoring and Publishing" package group that is needed to use LaTeX.


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.

Now You Can Create Your Own PDF Documents

You can also use a LaTeX file to generate your own Acrobat (.pdf) documents by using the pdflatex command instead of the latex command.


Selecting a Page Style

Now 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.

Table 21.3. Common Page Styles in LaTeX-2e

Style

Description

empty

LaTeX will not decorate pages at all; even page numbers will be omitted.

plain

LaTeX will print the page number at the bottom center of each page.

headings

LaTeX will decorate the top of each page with the page number and current chapter name.


Creating Title and Author Information

LaTeX 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

  • \title{text} to specify text as the title of the document you are creating

  • \author{text} to name yourself as the author of the document you are creating

  • \date{text} to specify text as the creation date of the document (optional)

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 Pages

In 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 Texts

To 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.

Table 21.4. Common LaTeX Sectioning Commands

Command

Description

\section{text}

Creates a new section using the title text as a section header and table of contents entry

\subsection{text}

Creates a new subsection using the title text as a subsection header and table of contents entry

\subsubsection{text}

Creates a new sub-subsection using the title text as a sub-subsection header and table of contents entry

\chapter{text}

Starts a new chapter, using the title text as a chapter title and table of contents entry (report and book document classes only)

\part{text}

Starts a new part, using the title text as a part title and table of contents entry (report and book document classes only)

\appendix

Starts a new appendix using lettering rather than numbering for sequence, and makes the necessary table of contents entry

\tableofcontents

Inserts a nicely formatted table of contents at the place in the text where the command appears; the table of contents is generated automatically from information supplied by using the other commands in this table


Is Your Table of Contents Empty?

Current versions of LaTeX contain a small bug that affects the table of contents functionality. If you find that you format a .tex file only to end up with an empty table of contents, simply run LaTeX on the file a second time, and the table of contents will be generated correctly.


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 Text

Sometimes 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:

  • To emphasize a particular piece of text, usually in italics, use the \emph{} command:

     Inserting \emph{emphasized text} with LaTeX is quite easy, especially In the middle of a paragraph like this one, which was designed for \emph{your} enjoyment. 

  • To insert a footnote to a particular piece of text, use the \footnote{} command:

     I played football\footnote{Football is a physical contact sport and should only be played by well-qualified personnel with the proper equipment.} yesterday. 

  • To center text, use the \begin{center} and \end{center} commands:

     \begin{center}This is centered text.\end{center} 

  • To insert a quoted passage, indenting from right and left on both sides, use the \begin{quote} and \end{quote} commands:

     \begin{quote}Ladies and gentlemen, start your engines. I shall not warn you again; the race is about to begin! If you don't pull toward the line now, you will miss the gun!\end{quote} 

  • To create ordered (numbered) or unordered (bulleted) lists in your text, use the \begin{enumerate} and \end{enumerate} or \begin{itemize} and \end{itemize} commandes, respectively, along with \item to mark the beginning of each new item:

     \begin{enumerate} \item This is the first numbered item. \item This is the second numbered item. \item This is the third numbered item. \end{enumerate} \begin{itemize} \item This is an un-numbered, bulleted item. \item This is another un-numbered, bulleted item. \end{itemize} 

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 Characters

People 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.

Table 21.5. Commonly Used Special Characters in LaTeX

Command or Sequence

Description

\ldots

Inserts a properly spaced ellipsis

--

Inserts an en dash

---

Inserts an em dash

``

Inserts an opening quotation mark

''

Inserts a closing quotation mark


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 Together

With 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:

  • Create a new book document intended for letter-sized paper with a 12-point font, using the \documentclass command.

  • Output a nice title page containing title and author information with the \maketitle command.

  • Output a table of contents with the \tableofcontents command.

  • Begin chapters called "Beginning My Novel" and "Ending My Novel" using the \chapter command.

  • Create a bulleted shopping list using the \begin{itemize} and \end{itemize} commands, marking each item in the list with the \item command.

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.


Don't Forget How to Format and Print

Remember how to format and print? The commands, in order, are

 latex myfile.txt dvips myfile.dvi 


More Information About LaTeX

We 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:

  • http://www.giss.nasa.gov/latex/ contains a hypertext guide to using the LaTeX formatter written by Sheldon Green.

  • http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/Index.html contains a hypertext primer for using the LaTeX formatter written by David R. Wilkins.

  • A nice, printable guide called The Not So Short Introduction to LaTeX 2e in portable document (.pdf) format can be downloaded from http://people.ee.ethz.ch/~oetiker/lshort/lshort.pdf.

  • More reference material of various kinds can be found at the catchall LaTeX website at http://www.latex-project.org.



    SAMS Teach Yourself Red Hat(r) Fedora(tm) 4 Linux(r) All in One
    Cisco ASA and PIX Firewall Handbook
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 311
    Authors: David Hucaby

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net