Using LaTeX

LaTeX (pronounced "lay-tek") is an unusual entry in this rundown of Linux office suites because LaTeX really isn't an office suite; rather, it's a document preparation language, similar in principle to the Hypertext Markup Language (HTML) that's commonly used for web pages. To use LaTeX, you create a document in a text editor—Emacs, NEdit, vi, or any other text editor you like. Certain symbols and strings within a LaTeX document carry special meaning. Most importantly, the backslash (\) character marks the beginning of most commands, and braces ({}) surround the text on which operations are to occur. For instance, the string \emph{strongly} emphasizes the string strongly in the output. To create output, you pass the LaTeX document file through one or more programs that convert your file into PostScript, which you can then print using Ipr.

Listing 7.1 presents a simple but complete LaTeX file. This file begins with a declaration of the class of document (an article), which defines various default settings, such as the default font. The \begin{document} line marks the start of the document, as opposed to the preamble, where global settings are defined. The \Huge line tells LaTeX to use an extra-large font. Ordinary text isn't marked out in any extraordinary way, so the next couple of lines print in the final document much as you would expect, with the exception of LaTeX keywords, which begin with a backslash. Therefore, \today is replaced in the final output by the current date, and the text delimited by \itshape{...} is printed in italic. Of course, this example is trivial. The true power of LaTeX emerges with its more complex options, including a very powerful syntax for handling mathematical equations. This facility makes LaTeX a favorite among mathematicians, scientists, and computer professionals. LaTeX is centered strongly around the use of predefined and extensible styles; you set up a style to handle some type of document element, such as bulleted lists or embedded graphics with their captions. Thereafter, you call the style to have LaTeX apply it, and you don't worry about the formatting details; LaTeX does that for you.

Listing 7.1: A Sample LaTeX Document

\documentclass{article}

\begin{document}

\Huge

Today, \today, I formally declare my candidacy for the position of \itshape{town dogcatcher.} \end{document}

In order to fully master LaTeX, you must invest some effort in learning its complexity. This effort may not be worthwhile if you write typical business documents and are already familiar with the GUI approach to writing; but if you need LaTeX's powerful layout features, you may want to pick up a book on the subject or browse the documentation available at http://www.latex-project.org.

If you type Listing 7.1, or some other LaTeX document, into a file, you can convert it into other formats by passing it through the latex program. This program converts the LaTeX document, which typically uses a .tex filename extension, into a device independent (DVI) file, which is actually an intermediate format. To produce a useful output file, you'd use a program such as dvips or dvipdf, which create PostScript or Portable Document Format (PDF) files as output, respectively. Other conversion programs are available to convert into other formats, as well. After creating announce.tex, you might type these commands to create a PDF:

$ latex announce.tex $ dvipdf announce.dvi

The result is a file called announce.pdf, which is shown in Figure 7.4 as displayed by Xpdf. This output file demonstrates the fact that LaTeX is free to reformat lines as it sees fit—note that indentation and line breaks in the output don't match those on the input. To control these details, you must use special LaTeX commands that set these options globally, or that set overrides in specific cases. One of LaTeX's strengths is that it handles these details, making consistent formatting more likely than would be the case if you were using a typical GUI word processor.

Figure 7.4: LaTeX output matches the description provided in the input, not the formatting of the raw text file.

If you like GUI word processors but want to take advantage of LaTeX's power, you should consider a compromise program: LyX (http://www.Iyx.org). This program, shown in Figure 7.5, is essentially a GUI text editor with direct links to call LaTeX and with the ability to parse a limited subset of LaTeX commands to present a GUI display. LyX is not a what-you-see-is-what-you-get (WYSIWYG) word processor, though. Although LyX displays some text attributes, such as italics, on-screen as they'll appear on the printed page, features such as line breaks, page breaks, and more advanced LaTeX features aren't displayed as they'll appear. In fact, even the on-screen font doesn't necessarily display as you might expect. Nonetheless, LyX can be a useful bridge if you want to obtain some of LaTeX's power without spending hours poring over LaTeX documentation.

Figure 7.5: LyX provides a GUI face to LaTeX.
0 0

Post a comment