Top Tips for New LaTeX Users

This article is aimed at relatively new \LaTeX users. It is written particularly for my own students, with the aim of helping them to avoid making common errors. The article exists in two forms: this WordPress blog post and a PDF file generated by \LaTeX, both produced from the same Emacs Org file. Since WordPress does not handle \LaTeX very well I recommend reading the PDF version.

1. New Paragraphs

In \LaTeX a new paragraph is started by leaving a blank line.

Do not start a new paragraph by using \\ (it merely terminates a line). Indeed you should almost never type \\, except within environments such as array, tabular, and so on.

2. Math Mode

Always type mathematics in math mode (as $..$ or \(..\)), to produce “y = f(x)” instead of “y = f(x)”, and “the dimension n” instead of “the dimension n”. For displayed equations use $$, \[..\], or one of the display environments (see Section 7).

Punctuation should appear outside math mode, for inline equations, otherwise the spacing will be incorrect. Here is an example.

  • Correct: The variables $x$, $y$, and $z$ satisfy $x^2 + y^2 = z^2$.
  • Incorrect: The variables $x,$ $y,$ and $z$ satisfy $x^2 + y^2 = z^2.$

For displayed equations, punctuation should appear as part of the display. All equations must be punctuated, as they are part of a sentence.

3. Mathematical Functions in Roman

Mathematical functions should be typeset in roman font. This is done automatically for the many standard mathematical functions that \LaTeX supports, such as \sin, \tan, \exp, \max, etc.

If the function you need is not built into \LaTeX, create your own. The easiest way to do this is to use the amsmath package and type, for example,

\usepackage{amsmath}
...
% In the preamble.
\DeclareMathOperator{\diag}{diag}  
\DeclareMathOperator{\inert}{Inertia}

Alternatively, if you are not using the amsmath package you can type

\def\diag{\mathop{\mathrm{diag}}}

4. Maths Expressions

Ellipses (dots) are never explicitly typed as “…”. Instead they are typed as \dots for baseline dots, as in $x_1,x_2,\dots,x_n$ (giving x_1,x_2,\dots,x_n) or as \cdots for vertically centered dots, as in $x_1 + x_2 + \cdots + x_n$ (giving x_1 + x_2 + \cdots + x_n).

Type $i$th instead of $i'th$ or $i^{th}$. (For some subtle aspects of the use of ellipses, see How To Typeset an Ellipsis in a Mathematical Expression.)

Avoid using \frac to produce stacked fractions in the text. Write n^3/3 flops instead of \frac{n^3}{3} flops.

For “much less than”, type \ll, giving \ll, not <<, which gives <<. Similarly, “much greater than” is typed as \gg, giving \gg. If you are using angle brackets to denote an inner product use \langle and \rangle:

  • incorrect: <x,y>, typed as $<x,y>$.
  • correct: \langle x,y \rangle, typed as $\langle x,y \rangle$

5. Text in Displayed Equations

When a displayed equation contains text such as “subject to x \ge 0”, instead of putting the text in \mathrm put the text in an \mbox, as in \mbox{subject to $x \ge 0$}. Note that \mbox switches out of math mode, and this has the advantage of ensuring the correct spacing between words. If you are using the amsmath package you can use the \text command instead of \mbox.

Example

$$
      \min\{\, \|A-X\|_F: \mbox{$X$ is a correlation matrix} \,\}.
$$

6. BibTeX

Produce your bibliographies using BibTeX, creating your own bib file. Note three important points.

  • “Export citation” options on journal websites rarely produce perfect bib entries. More often than not the entry has an improperly cased title, an incomplete or incorrectly accented author name, improperly typeset maths in the title, or some other error, so always check and improve the entry.
  • If you wish to cite one of my papers download the latest version of njhigham.bib (along with strings.bib supplied with it) and include it in your \bibliography command.
  • Decide on a consistent format for your bib entry keys and stick to it. In the format used in the Numerical Linear Algebra group at Manchester a 2010 paper by Smith and Jones has key smjo10, a 1974 book by Aho, Hopcroft, and Ullman has key ahu74, while a 1990 book by Smith has key smit90.

7. Spelling Errors and \LaTeX Errors

There is no excuse for your writing to contain spelling errors, given the wide availability of spell checkers. You’ll need a spell checker that understands \LaTeX syntax.

There are also tools for checking \LaTeX syntax. One that comes with TeX Live is lacheck, which describes itself as “a consistency checker for LaTeX documents”. Such a tool can point out possible syntax errors, or semantic errors such as unmatched parentheses, and warn of common mistakes.

8. Quotation Marks

\LaTeX has a left quotation mark, denoted here \lq, and a right quotation mark, denoted here \rq, typed as the single left and right quotes on the keyboard, respectively. A left or right double quotation mark is produced by typing two single quotes of the appropriate type. The double quotation mark always itself produces the same as two right quotation marks. Example: ``hello'' is typed as \lq\lq hello \rq\rq.

9. Captions

Captions go above tables but below figures. So put the caption command at the start of a table environment but at the end of a figure environment. The \label statement should go after the \caption statement (or it can be put inside it), otherwise references to that label will refer to the subsection in which the label appears rather than the figure or table.

10. Tables

\LaTeX makes it easy to put many rules, some of them double, in and around a table, using \cline, \hline, and the | column formatting symbol. However, it is good style to minimize the number of rules. A common task for journal copy editors is to remove rules from tables in submitted manuscripts.

11. Source Code

\LaTeX source code should be laid out so that it is readable, in order to aid editing and debugging, to help you to understand the code when you return to it after a break, and to aid collaborative writing. Readability means that logical structure should be apparent, in the same way as when indentation is used in writing a computer program. In particular, it is is a good idea to start new sentences on new lines, which makes it easier to cut and paste them during editing, and also makes a diff of two versions of the file more readable.

Example:

Good:

$$
U(\zbar) = U(-z) = 
            \begin{cases}
                -U(z),   & z\in D, \\ 
                -U(z)-1, & \mbox{otherwise}.
            \end{cases}
$$

Bad:

$$U(\zbar) = U(-z) = 
\begin{cases}-U(z),   & z\in D, \\ 
-U(z)-1, & \mbox{otherwise}.
\end{cases}$$

12. Multiline Displayed Equations

For displayed equations occupying more than one line it is best to use the environments provided by the amsmath package. Of these, align (and align* if equation numbers are not wanted) is the one I use almost all the time. Example:

\begin{align*}
  \cos(A) &= I - \frac{A^2}{2!} + \frac{A^4}{4!} + \cdots,\\
  \sin(A) &= A - \frac{A^3}{3!} + \frac{A^5}{5!} -  \cdots,
\end{align*}

Others, such as gather and aligned, are occasionally needed.

Avoid using the standard \LaTeX environment eqnarray, because it doesn’t produce as good results as the amsmath environments, nor is it as versatile. For more details see the article Avoid Eqnarray.

13. Synonyms

This final category concerns synonyms and is a matter of personal preference. I prefer \ge and \le to the equivalent \geq \leq\ (why type the extra characters?).

I also prefer to use $..$ for math mode instead of \(..\) and $$..$$ for display math mode instead of \[..\]. My preferences are the original \TeX syntax, while the alternatives were introduced by \LaTeX. The slashed forms are obviously easier to parse, but this is one case where I prefer to stick with tradition. If dollar signs are good enough for Don Knuth, they are good enough for me!

I don’t think many people use \LaTeX‘s verbose

\begin{math}..\end{math}

or

\begin{displaymath}..\end{displaymath}

Also note that \begin{equation*}..\end{equation*} (for unnumbered equations) exists in the amsmath package but not in in \LaTeX itself.

8 thoughts on “Top Tips for New LaTeX Users

  1. With amsmath, `\dots` actually gets a little smarter: `a_1 + \dots + a_n` will generate vertically centered dots and generally take the right decision. Using `\cdots` explicitly is actually discouraged.

    1. I’m skeptical about the reference you cite as it doesn’t give any evidence to support its claim. Kopka and Daly (2004, p. 122) say “The displaymath environment may be given with the shorthand forms \[…\] or $$…$$”. In any case, I’ve happily used the double dollar form for years without problem and from what I can tell professional journal/book typesetters have been happy to leave it in my LaTeX source.

        1. Thanks for the links. I see that in one of those, LaTeX guru (and my colleague in the 1990s) David Carlisle says “The main reason for using \[ is not for spacing issues. It is for better error checking and support for fleqn.” I mention the ease of parsing in the post. I didn’t mention fleqn because I’ve never come across a situation where it is used.

    1. The output of booktabs is impressive, but the journals I’m familiar with do not support this style. So I feel it’s of rather specialist interest, but worth considering if you’re writing a book and have freedom over such style matters.

  2. Great intro-summary! Something I find particularly useful is the extensive documentation of packages. It is available locally with the standard TeX Live/MiKTeX distribution (via command-line: texdoc) or online on http://ctan.org/pkg .

Leave a comment