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
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.