Tips and tools for managing LaTeX
Powerful Format
LaTeX has a reputation for being difficult to use, but mainly it just requires patience. We provide a quick overview to get you up and running.
Lamport TeXt (LaTeX) is one of free software's legendary applications [1]. Before LibreOffice or AbiWord, it was the most advanced tool on Linux for formatting text. Even today, it is widely used in the academic sciences and in some publishing houses. Users speak of compiling their first lengthy document in LaTeX in the same way others talk of compiling their first Linux kernel, and several professors tell me that students regularly have to be prevented from obsessing over LaTeX at the expense of their research.
LaTeX has a reputation for being difficult, but not because of its complexity. Instead, the difficulty lies in the size of the project. Adding to the difficulty is the number of editors designed for it, including extensions for both Vim and Emacs [2], as well as LyX, a graphical interface [3]. The difficulty in learning LaTeX does not lie in the concepts, as much as in finding the right tools.
At its heart, though, LaTeX is actually simple. Basically, it is a combination of a markup language similar to HTML and a collection of formatting macros. Creating a document in LaTeX consists of three steps:
- Using Tex or some other editor to write the markup.
- Compiling the LaTeX document.
- Exporting to a usable file format with another script
Despite the many tools available for working with LaTeX, all these steps can be done using applications that are part of the default installation for most distributions. What follows is a quick overview to get you up and running.
Basic Structure of a LaTeX Document
To create a LaTeX document, you begin by opening any text editor. Figure 1 shows the structure of a simple TeX document. The first thing to notice is that the percentage sign (%) at the start of a line indicates a comment that is not printed. A backslash (\) at the start indicates a piece of markup. Often, the markup is a reference to a formatting macro and which formatting choice(s) are being used, with the macro coming first and the choice following in curly braces. For instance, \documentclass{article}
defines the type of document as an article.
The next thing to notice is that the document is divided into sections, with the beginning and end of each section clearly marked. Everything above \begin{document}
is known as the preamble or the top matter.
The preamble is the place for meta-information – not only introductory comments, but also information like the author, title, and the date, such as \author{Bruce Byfield}
. The preamble also includes high-level formatting for the entire document (except where overridden by a section), including the default font size and the paper size, such as \documentclass[12pt,letterpaper,oneside,draft]{report}
, the formatting being added in square brackets after the macro. For convenience, you can divide this information into stanzas with a space between each one. The average preamble then would probably look more like Figure 2.
You can start adding content below \begin{document}
. It can be further subdivided by other section types. For the most part, the content is simply typed, with a blank line indicating a new paragraph. None of the content, of course, will be formatted until you compile. And, if you actually want to print a backslash, you must add another backslash (\\) so that it is not interpreted as markup. That covers most of the mechanics of writing markup that you need to know.
Basic Formatting
The rest of using LaTeX is almost entirely looking up which macros you need to get the results you want. Fortunately, LaTeX is exhaustively documented and, with some patience, you should be able to find the information you need. All the same, when drafting, you should compile frequently and be prepared, if necessary, to continually tweak your markup. If you do the same type of document repeatedly, save satisfactory results as templates so you don't need to test more than once.
You can usually save time by defining a document type and its formatting options (see Table 1) in the preamble and letting the macro do most of the work for you. For general purposes, use article as the document type. Other common classes include book, letter, report (including thesis), and beamer (presentations).
Table 1
Common Options for Most Document Classes
Formatting | Markup | Comments |
---|---|---|
Paper size |
\usepackage[a4paper]{geometry} |
Paper sizes include letterpaper & legalpaper |
Orientation |
\usepackage[landscape]{geometry} |
Values are landscape & portrait |
Margins |
\usepackage[top=length, bottom=length, left=length, right=length]{geometry} |
Length is in centimeters or inches |
Headers and footers |
\pagestyle{style} |
Applies to current and subsequent pages. Choices are empty (no header or footer), plain (foot includes page number), or headings (header contains information defined by document class) |
Headers and footers |
\this pagestyle{style} |
Same as \pagestyle, but only for current page |
For more control over page appearance, you can also add some non-standard document classes [4] by hunting down their packages on the Internet and placing those packages in the same directory as the Tex file. If some sections define their own pages, you can override them by placing \pagestyle{empty}
in the preamble and defining the pagestyle as need throughout the document.
Another way to reduce the amount of formatting is to define a section, such as \chapter{''TITLE''}
or \section{''TITLE''}
. But, using sections can become complicated, especially if you want to repress the numbering that many sections automatically add.
For the equivalent of word processor character styles, you can use \textit
for italics, \textbf
for bold, and \underline
for underlining. In each case, follow the basic command with the text to format in curly braces. In other words, to place "equivalent" in the first sentence of this paragraph in italics, you would enter:
For the \textit{equivalent} of word processor character styles
Ordered lists start with \begin{enumerate}
and end with \end{enumerate}
, whereas unordered lists are marked by \begin{itemize}
and \end{itemize}
. Both types of list can have as many entries as required, but each item must begin on a separate line that begins with \item
.
To use graphics, place \usepackage{graphicx}
and \graphicspath/{ {FOLDER} }
in the preamble, being careful to end the graphics path with a forward slash. At the position where you want to place the graphic, add \include[FILE]
.
Modern LaTex supports both EPS and PNG files, but you do not need to include any extension when adding the image to the document. You can change the size of the graphic with \includegraphics[scale = RaTIO]
, where 1.0 is the original size or change the dimensions with \includegraphics[width=SIZE height=SIZE]
.
These are far from the only formatting options you are likely to want to use with LaTeX, and they do not address challenges such as positioning a page break where you want it. However, they should be enough for many documents.
Compiling and Outputting
When you are finished creating the file, save it and then run the command latex FILE
. The result is a file of the same name, except with a DVI extension. A logfile of the same name is also created, allowing you help with troubleshooting the markup. You can also find various viewers, such as advi, to inspect the file visually.
If there are no errors, you can use the DVI file to export to four formats: postscript (PS), PDF, RTF, and HTML. There are many scripts for these exports, but div2ps, ps2pdf, latext2rtf, and latext2html should do for most purposes.
Although many instructions warn of a possible loss of formatting when exporting to RTF or HTML, I have personally never encountered any. If you do, however, a postscript or PDF export should be more reliable.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.