This article is aimed at relatively new 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
, both produced from the same Emacs Org file. Since WordPress does not handle
very well I recommend reading the PDF version.
1. New Paragraphs
In 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 “” instead of “y = f(x)”, and “the dimension
” 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 supports, such as
\sin
, \tan
, \exp
, \max
, etc.
If the function you need is not built into , 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 ) or as
\cdots
for vertically centered dots, as in $x_1 + x_2 + \cdots + x_n$
(giving ).
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 flops instead of
flops.
For “much less than”, type \ll
, giving , not
<<
, which gives . Similarly, “much greater than” is typed as
\gg
, giving . If you are using angle brackets to denote an inner product use
\langle
and \rangle
:
- incorrect: <x,y>, typed as
$<x,y>$
. - correct:
, typed as
$\langle x,y \rangle$
5. Text in Displayed Equations
When a displayed equation contains text such as “subject to ”, 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 withstrings.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 keyahu74
, while a 1990 book by Smith has keysmit90
.
7. Spelling Errors and
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 syntax.
There are also tools for checking 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
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: 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
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
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 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 syntax, while the alternatives were introduced by
. 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 ‘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 itself.