Absolute Beginner's Guide to LaTeX on PCLinuxOS
By David Pardue (kalwisti)
Oct. 4, 2009
1. Introduction
Would you like to create polished, professional-looking documents? Thanks to Texstar’s packaging skills, we have a wonderful tool to do just that: LaTeX, which is part of the TeX Live implementation recently added to the PCLinuxOS repositories. This article has a twofold purpose: I would like to introduce LaTeX and encourage you to give it a try; I will also include a brief how-to which covers installing TeX Live on your system, a powerful yet user-friendly LaTeX editor (Kile) and a sample source file you can compile and preview.
In Part Two of the article (to be continued in a later issue), I will provide you with an annotated mini-bibliography of works on LaTeX that I found helpful when I began learning the program. It includes books and articles, some commercially published and some freely downloadable from the Web.
LaTeX suffers from a reputation of complexity which frightens some new users. Acquiring the fundamentals requires a time investment, but you do not have to delve into LaTeX's intricacies to produce straightforward documents.1 I am proof that the learning curve is not insurmountable because I have been using LaTeX since around 2006. I am self-taught with it; my background is in the humanities and I am not a programmer, mathematician nor a Linux guru. When Dr. Leslie Lamport, the creator of LaTeX, was asked if LaTeX is hard to use, he answered:
It’s easy to use — if you’re one of the 2% of the population who thinks logically and can read an instruction manual. The other 98% of the population would find it very hard or impossible to use.2
Although some might classify his statement as elitist, I would hope that as Linux users, we belong to that 2% of logical people who can — and will — RTFM.
Due to space limitations, I will only cover the highlights of LaTeX and some of the information will necessarily be incomplete. TeX and LaTeX have been used for a quarter-century; there is a vast body of published literature on them, so the problem I face as a presenter is not what to include but what to omit.
2. What is LaTeX?
LaTeX, usually pronounced "lay-teck", is a computer typesetting system. Although its original purpose was to typeset mathematics, it can be used to produce a wide range of documents — everything from class handouts, PowerPoint-style slides and letters to journal articles, reports, theses and even books.
LaTeX is a large set of macros built upon the TeX computer program. It was initially developed by Lamport in 1985 and is now maintained by a group of international experts — both mathematicians and computer scientists. TeX (composed of the Greek letters tau epsilon chi [τεχ] and usually pronounced "teck") is the basic typesetting engine, written by Dr. Donald E. Knuth of Stanford University. Lamport draws the analogy that LaTeX can be thought of as "a house built with the lumber and nails provided by TeX."3 LaTeX is the recommended system for all users except typographic programmers and computer scientists.
Knuth originally wrote TeX circa 1978 to produce Vol. 2 of his magnum opus, The Art of Computer Programming. He received the galleys from the publisher, and the quality of their mathematical typesetting was so poor that he decided he could create a better program himself. Ever the perfectionist, he set out to learn the traditional rules for typesetting math, what constituted good typography, and as much as he could about type design. He estimated this would take about 6 months; ultimately, it took nearly 10 years.4
In case you are curious about the unusual capitalization of "TeX" and "LaTeX," this is how their names are written in running text when it is not possible to precisely reproduce them with their logos.5 Knuth chose "TeX" in order to distinguish it from other system names such as TEX (the Text EXecutive processor, a scripting language developed by Honeywell in 1979).6 Lamport followed suit with "LaTeX" to avoid confusion with the word "latex."
3. LaTeX's Design Philosophy
We must keep in mind that LaTeX is not a word processor and does not behave like one. TeX and LaTeX are computer languages. We can compare them with other programming languages such as C or Java, in which source code is written with a text editor, then the code is converted to a binary executable. However, TeX is a typesetting language, so the source code is converted into a typeset document.7
Word processors adopt a visual design approach (WYSIWYG), which does not separate the tasks of composition (i.e., writing) and typesetting. Allin Cottrell argues that this needlessly distracts authors by tempting them to "fiddle with fonts and margins." To illustrate the flaws in this model, he asks us to imagine Jane Austen wondering what font and size to make the chapter headings of Pride and Prejudice: a foolish situation, of course, because Austen was a novelist, not a trained typesetter.8
LaTeX adopts a logical design approach to document creation by focusing on structure. It allows you to concentrate on writing and lets the program do the design / layout, with TeX as its typesetter. TeX handles typesetting admirably, so you do not have to know much about typesetting in order to use it. For instance, LaTeX has a command for a first-level section heading (\section{Your Section Title Here}), but in using this command you do not need to worry about the size and style of type (e.g., 16-point Roman, bold, upright typeface) that will be used to produce the heading in your output. All this is taken care of behind the scenes by LaTeX.
Lamport firmly believes that a writer's primary focus should be on content rather than visual layout. When asked about the three most frequent LaTeX mistakes that people should stop making, he replied:
- Worrying too much about formatting and not enough about content.
- Worrying too much about formatting and not enough about content.
- Worrying too much about formatting and not enough about content.9
LaTeX is a markup language (somewhat similar to HTML markup), not a page layout program. Users who want to control the placement of every single dot on the page will be unhappy with LaTeX. But if you trust LaTeX and TeX and let them perform their intended tasks, you will be rewarded with elegant documents. The output resembles something produced by a commercial book publisher. TeX’s output will contain ligatures if necessary (with letter combinations such as "fi" and "ff") and kerning (bringing letters such as "A" and "V" closer together for easy reading) will be done automatically. TeX will introduce an appropriate amount of inter-word spacing and it will not produce paragraphs with rivers of space running through them.
Hyphenation will be done sensibly and the traditional stock of printers' punctuation marks (such as em dashes and en dashes) will appear as they should.10 TeX measures with incredible accuracy: its unit of internal measurement is smaller than the wavelength of visible light!
For those of us accustomed to word processors, LaTeX's approach requires mentally shifting gears. But it does not have to be traumatic. The typical work cycle is discussed in Section 5.2 below.
4. Why Use LaTeX?
LaTeX has many advantages over word processors; I cannot list them all but I would like to mention the most important ones11:
- Completely free of charge.
- Proven, stable and virtually bug-free: TeX and LaTeX have been tried and tested for over 20 years.
The de facto standard in scientific publishing, especially in the fields of math, physics and engineering. Used by major publishers such as Elsevier, Springer-Verlag, John Wiley & Sons, Addison-Wesley, Oxford University Press and Cambridge University Press.
Extensively supported via the Internet and user groups (TeX Users Group [TUG], Dante e.V. [Germany], NTG [Netherlands]), etc.12
- The premiere typesetter for math (mathematical formulas).
- Produces industry-standard PostScript and Acrobat PDF files.
- Tables and figures follow the standard publishers’ practice of floating.
- The .tex file format is portable: plain text (ASCII or Unicode). It can be created with any text editor and moved between different operating systems with no information loss.
- The file format is more compact and more secure (less likely to be corrupted by viruses, etc.). Also, because it is plain text, your source files will still be readable 20 years from now.
- Internationalized: LaTeX and TeX support a wide range of fonts and languages, including non-Latin languages such as Japanese, Chinese, Hindi, Thai, Vietnamese, Coptic, Greek, Arabic, Hebrew, etc.
- Typefaces: Contrary to the popular misconception that "TeX only has the Computer Modern font," hundreds of typefaces are available — both free and commercial. It includes specialist fonts for technical matter, linguistics and mathematics.
- Platform-independent: TeX is guaranteed to produce identical results no matter on which system it is run.
For example, you may type the first version of your source file on your office PC running Microsoft Windows; your co-author may make improvements to the same file on a Macintosh running OS X; and the journal publishing your article may use a Linux machine to prepare the manuscript for printing.13
There are default styles for common document types, such as article, report, letter, beamer [similar to PowerPoint].
- Auto-formatting of chapters, sections, footnotes, etc.
- LaTeX can automate the handling of cross-references, bibliographic citations, tables of contents, indexes and glossaries. It takes the drudgery out of many of the necessary tasks that are involved in the composition of a large or complex document.
For example, if you need to alter the structure of your nearly completed report by moving chapters or sections, then LaTeX will automatically renumber all the chapters and sections appropriately and produce an updated and correct table of contents. If your book contains cross-references to chapters, sections or pages, then all this cross-referencing information will be updated as well.
- It’s great fun to use!
5. How-To
5. 1. Installing the Required Software
5. 1.1. Installing TeX Live
Thanks to Texstar, we are fortunate to now have TeX Live (TL) available in the repositories as a replacement for its outdated predecessor, teTeX.14 Your first step will be to install the necessary TL packages. It is a large download — over 200 MB in size — so it will take a while.
Start up the Synaptic Package Manager and install the following TL components:
- texlive 2007-21.r6295.1
- texlive-dvipdfm
- texlive-dvips
- texlive-fonts
- texlive-latex
- texlive-texmf
- texlive-texmf-common
- texlive-texmf-dvipdfm
- texlive-texmf-dvips
- texlive-texmf-fonts (This is by far the largest package — 183 MB)
- texlive-texmf-latex
- texlive-texmf-usrlocal
- texlive-xdvi (which will bring in texlive-mfwin withit)
Selecting these components will automatically pull in these packages also: bison, flex, libkpathsea4 and libteckit0.
5.1.2. Installing Kile
Although you can run LaTeX from the command line (Konsole) and edit .tex files with a text editor such as vi, Kwrite or Leafpad, it is much easier and more pleasant to use a dedicated LaTeX editor like Kile (KDE Integrated LaTeX Environment). Kile features niceties such as syntax highlighting, auto-completion of LaTeX commands, and it allows users to compile, convert and view a document with one click (the QuickBuild feature).15
Your next step is to install Kile via Synaptic. You do not need to install kile-doc or kile-extra. Be especially careful to avoid kile-extra because it will attempt to pull in six teTeX-related packages along with it.
Note: One oddity you will probably encounter is that Kile's menu entry will be under Start > Lost & Found > Kile, so you will have to use the Menu Editor to move it back with the Office applications.
Kile's icon is shown below:
5.2. The Typical Cycle for Running LaTeX
Before we try to run LaTeX on a quick-and-dirty sample file, it will be helpful to have a basic overview of the typical LaTeX production cycle, which goes like this:
- Create your file and give it the .tex extension. This file contains the text of your document, interspersed with commands (markup) that tell LaTeX how the file should be formatted.
- Compile the file by running LaTeX on it. This will produce an output file with the extension .dvi (it stands for 'device independent') which you can view or send to a printer.
- View your output to see if it is correct. This step is called previewing.
- If something is incorrect or you are unhappy with the result, return to the first step and edit your file.
If you run the variant pdfTeX on your file, the output will be a PDF file. (As an aside, LaTeX will also generate files with the extensions .aux, .log, and may also include .toc, .idx and .bbl files. However, we do not need to worry about those files right now.)
The figure below illustrates this typical cycle16:
5.3. Your First Document
Now that you have installed TeX Live, Kile and understand the basic stages of LaTeX document production, you are ready to create your first document. I will help you by providing a ready-made .tex file which will compile without errors.
Note: You will not see a LaTeX entry in your menu structure; instead, you will use Kile to create your .tex file, compile it with LaTeX and view it (both as a .dvi file and a .pdf file).
Follow these steps:
Start up Kile. If you moved Kile, as mentioned in Section 5.1.2 above, it can be found under Start > Office > Kile. If you chose not to move it, Kile will be under Start > Lost & Found > Kile.
Kile's main screen is shown below.
We will focus in a moment on four buttons in Kile's toolbar, which are illustrated in this screenshot:
Copy (or retype) the source file in Section 5.4 below, and create a new file in Kile (File > New > [Template] Empty Document). Then paste the source file from your clipboard into the new document.
Save your file (File > Save) with a meaningful name, such as latex-test.tex
- Use the button in Kile's toolbar (a blue KDE-style gear shown below) to run LaTeX on your source file. It should compile without any errors.
You will see text output scrolling by in the Log and Messages window at the bottom of Kile's main screen. It should end with the message [LaTeX] Done!
To view the resulting DVI file, press the View DVI button (the TeX lion's head superimposed on a sheet of paper, as seen below) in Kile. KDVI should pop up with a display of a one-page document.
Note: Although LaTeX's typographic display is asynchronous with the editor's window — i.e., there is not the immediate feedback you receive with a word processor — the DVI and PDF preview is more accurate than any word processor’s WYSIWYG. Considering the speed of modern CPUs and monitors, it takes only a few seconds to compile your source file and preview the result.
If all goes well, you should see a one-page document that looks like this, set in 10-point Computer Modern typeface:
- If you want to generate and view a PDF file, there are two buttons in Kile: one for running pdfLaTeX (a blue KDE gear with a PDF logo, shown below) and another for automatically viewing the created file (the button with the PDF logo). (You can hold your cursor's tooltip over the buttons and see their functions).
Note: If you plan on sharing your finished document with non-LaTeX users, PDF — rather than DVI — is the format of choice today, and pdfLaTeX can produce it directly. Another advantage of using pdfTeX is that in conjunction with Sebastian Rahtz's ingenious hyperref package, you can create hyperlinked PDFs.
When you finish working, close your .tex file by selecting File > Close from Kile's menu. You will see a message in the Log area that Kile is auto-cleaning the .log and .aux files.
5.4. A Sample LaTeX Source File
Below is a sample file containing the appropriate LaTeX markup; it has been verified to compile without errors. If you copy it exactly as is and follow the instructions in Section 5.3, you will successfully produce your first LaTeX document. (The document contains a mathematical formula, some foreign-language accents, an itemized list and a haiku. It also illustrates how a document can be divided into sections and subsections).
\documentclass{article} \begin{document} \title{My First \LaTeX{} Document} \author{Yours Truly} \date{\today} \maketitle \section{Introduction}
This is a short document to illustrate the basic use of \LaTeX. Whether it's math, funny foreign accents, grocery lists, or haiku.
\ldots \LaTeX{} can typeset it! \section{A Math Example} \LaTeX{} is especially good at typesetting math. Here's a restatement of the Pythagorean theorem: \bigskip $c = \sqrt{a^{2} + b^{2}}$ \subsection{A Sample Subsection}
Does \AE schylus have a soup\c{c}on of suspicion about \OE dipus? Isn't he the fellow from K\o benhavn with the impressive r\'{e}sum\'{e} who measures in \aa ngstrom units?
Here's a short itemized grocery list:
\begin{itemize} \item Milk \item Eggs \item Loaf of bread \item Cat food! \end{itemize} \section{A Poem}
After that head-splitting theorem, let's close with a haiku by Matsuo Bash\={o}:
\begin{verse} Temple bells die out. \\ The fragrant blossoms remain. \\ A perfect evening! \end{verse} \end{document}
5.5. Additional Source Files
If you would like more practice typesetting readymade .tex files, there are two standard test files written by Dr. Lamport himself to illustrate basic LaTeX usage: sample2e.tex and small2e.tex.
They are located in the following directory:
/usr/share/texmf-texlive/tex/latex/base
Navigate there, make a copy of the files and save them in your /home directory or your Documents folder. Follow the steps in Section 5.3 to compile and preview them, and you will be the proud creator of three LaTeX documents.
Wishing you happy TeXing!
Bibliography
- In his introductory tutorial, Tobias Oetiker claims that LaTeX's essentials can be learned in 141 minutes. See his The Not So Short Introduction to LaTeX, ver. 4.26 (25 Sept. 2008). http://bit.ly/DtFwX
- Leslie Lamport, interview with Günter Ziegler, "How (La)TeX Changed the Face of Mathematics: An E-interview with Leslie Lamport," TUGboat 22 (2001): 21. http://www.tug.org/interviews/
- Leslie Lamport, LaTeX: A Document Preparation System: User’s Guide and Reference Manual, 2nd ed. (Boston: Addison-Wesley, 1994) 5.
- "Just What Is TeX?" http://www.tug.org/whatis.html. To learn more about Knuth's personal side, see Kara Platoni, "Love at First Byte," Stanford Magazine May/June 2006. http://www.stanfordalumni.org/news/magazine/2006/mayjun/features/knuth.html Despite his brilliance, Knuth is well known for his modesty, kindness and devout Lutheran faith. NPR's Morning Edition broadcast a fascinating interview with him in 2005, titled "Donald Knuth, Founding Artist of Computer Science"; it can be heard at: http://www.npr.org/templates/story/story.php?storyId=4532247.
- The official "TeX" logo is properly typeset with the "E" below the baseline and reduced spacing between the letters; it is produced by the command \TeX. The command \LaTeX produces the logo "LaTeX."
- Donald E. Knuth, The TeXbook (Boston: Addison-Wesley, 1986) 1.
- Nicola Talbot, "What Is TeX?," comp. David Walden, PracTeX Journal 2005.3. http://www.tug.org/pracjourn/2005-3/walden-whatis/
- Allin Cottrell, "Word Processors: Stupid and Inefficient" 29 June 1999. http://ricardo.ecn.wfu.edu/~cottrell/wp.html
- Lamport, "How (La)TeX Changed" 22.
- Antoni Diller, LaTeX Line by Line: Tips and Techniques for Document Processing, 2nd ed. (New York: John Wiley & Sons, 1999) 2.
- Most of these points are taken from Peter Flynn’s "The LaTeX Brochure". http://silmaril.ie/downloads/
- For a complete list, see "TeX User Groups around the World." http://www.tug.org/usergroups.html TUG publishes the journal TUGboat three times per year, covering a range of topics in digital typography.
- George Grätzer, First Steps in LaTeX (Boston: Birkhauser; New York: Springer-Verlag, 1999) xv.
- teTeX is a TeX implementation for Unix-like systems which was maintained by Thomas Esser (hence his initials te in the prefix) from 1994 until May 2006. Esser stopped maintaing teTeX at that time and recommended that his users switch to TeX Live as a replacement.
- There are other LaTeX-capable text editors available in the PCLOS repositories: Emacs-AUCTeX, Geany, Gedit and AmyEdit. AUCTeX is probably the most powerful; it is an extensible package for handling .tex files in Emacs. (AUC is the initialism for Aalborg University Center [Denmark], where it was first developed). Gedit has a LaTeX plugin and Geany has a LaTeX mode. Some other Linux distributions, e.g., Fedora and Ubuntu, have Texmaker, the Vim-LaTeX suite and Winefish available.
- Eric Schechter, "Beginners' Introduction to TeX and its Use." 13 Oct. 2005. http://bit.ly/15cMZP