Rouben Rostamian

LaTeX Tips and Tricks for Math 481

In this page I will collect comments, suggestions, observation, and advice regarding LaTeX markup mostly in response to what I see in the submitted projects. I will expand this page as we go along. You may want to have a look here once in a while to make yourself aware of these common mistakes and pitfalls.

Note: To see the LaTeX code underlying a mathematical expression on this page, right-click on the expression then select “Show math as TeX commands”.

Contents

  1. Logical versus visual markup
  2. Don't fight the documentclass
  3. Blank line? What do you mean by that blank line?
  4. An asterisk is not a multiplication symbol
  5. The tilde connector
  6. Arrange math in a presentable way
  7. Don't waste space
  8. Quotation marks
  9. Managing displayed equations
  10. Fractions and exponents
  11. Three kinds of dashes
  12. Floating figures

Logical versus visual markup

LaTeX is what is called a logical markup system. As such, it separates layout decisions from the document's contents. This is very different from the typical word processor's visual markup system where text entry and layout decisions are intertwined.

For instance, when you enter \section{The main result} in LaTeX, you signal the beginning of a section titled “The main result”. In doing so, you are providing a part of the document's logic. You don't decide on the placement, font, size, and numbering of the section's title, and the amount of vertical space before and after it; LaTeX decides those.

Similarly, when you leave a blank line in the LaTeX source, you signal a paragraph break. You don't decide on the size of the gap between the paragraphs or whether a paraphraph's first word should be indented; LaTeX does that.

The proper use of LaTeX depends in a most critical way on recognizing the difference between the logical and visual markup philosophies.

Don't fight the documentclass

LaTeX's layout decisions are embedded in the documentclass. It determines, for instance, the width and height of the text area, the space above and below a displayed equation, and the separation between paragraphs.

Standard layouts are designed by layout experts to maximize the document's readability, to provide a consistent and harmonious presentation, and to conform to the publisher's house rules. Don't fight the documentclass! Your job is to enter the document's logic, not the layout! Leave the latter to LaTeX.

Blank line? What do you mean by that blank line?

A blank line in LaTeX signals a paragraph break! Stray blank lines insert paragraph breaks where there shouldn't be one. A common beginner's mistake is to insert blank lines above and below a displayed equation. A displayed equations is not a paragraph on its own; it is a part of the surrounding text. A blank line before a displayed equation is almost surely a mistake. A blank like after a displayed equation is warranted if you really mean to start a new paragraph there.

An asterisk is not a multiplication symbol

In programming languages such as Fortran, C, and Maple, an asterisk indicates the multiplication operator, as in $\mathtt{\scriptsize y = a*x + b}$. That's not so in mathematics where adjacency indicates multiplication, as in $y = ax + b$. Don't put asterisks in mathematical equations in LaTeX.

If you have to indicate multiplication explicitly, use \times which produces the multiplication symbol “$\times$”, as in $3\times4 = 12$, or $\tau_u = 4.5\times 10^9$.

Observe that the multiplication symbol $\times$ is not at all the same as the letter x! Don't write x where you mean \times.

The tilde connector

According to Murphy's Law, if something can go wrong, it will! An unfortunate case of something going wrong is when an expression like “section 3” is split at the line boundary: the “section” falls at the end of one line and the “3” goes to the beginning of the next line, or even worse, to the top of the next page!

To prevent such an infelicitous split, fill the gap between the parts with a tilde, as in section~\ref{whatever}. The tilde stands for an unbreakable interword space.

Other places where you would want to insert unbreakable spaces are in references to equations, figures, and bibliographical citations. Thus, you will do:

Figure~\ref{fig:parabola} shows the graph of equation~\eqref{eq:parab} of section~\ref{sec:intro}. This agrees with the prediction on page~341 of~\cite{nostradamus}.

Get in the habit of putting the tilde connector before every \ref, \eqref, and \cite, as well as between a Mr., Mrs., Dr., and the name that follows, as in Mr.~Smith.

A very common beginner's mistake is to put a space next to the tilde, as in equation ~\eqref. That's very bad! It puts not one, but two spaces between the words. And to add insult to injury, one of the two spaces is breakable! That's definitely not what you want.

A line-break next to the tilde, as in equation
~\eqref, is just as bad. Watch for those misuses of the tilde connector!

Arrange math in a presentable way

Maple is darn good in doing algebra and calculus, however it has no clue what the calculations are all about. But you do! Rearrange/reinterpret Maple's results in a way that best express your ideas. For instance, in Project 1 we derive a differential equation for the height $h(t)$ of the water in the funnel: \begin{equation} \label{eq:de-for-h} \pi \Big( a + \frac{b-a}{H} h \Big)^2 \frac{dh}{dt} = Q - \pi a^2 \sqrt{2 g h}. \end{equation} The outflow rate $q$ and the water level $h$ are related through Torricelli's Law, $q = \pi a^2 \sqrt{2gh}$, or equivalently, $h = q^2/(2\pi^2 g a^4)$. We substitute this in equation \eqref{eq:de-for-h}, apply the chain rule, and arrive at a differential equation for $q(t)$: \begin{equation} \label{eq:de-for-q} \frac{1}{\pi ga^4} \Big( a + \frac{b-a}{2\pi^2 ga^4 H} q^2 \Big)^2 q \frac{dq}{dt} = Q-q. \end{equation} The same substitution in Maple produces \[ \pi \Big( \frac12 \frac{(b-a)q(t)^2}{Hg\pi^2a^4} + a \Big)^2 \Big( \frac{\partial}{\partial t} \Big( \frac12 \frac{q(t)^2}{g\pi^2a^4} \Big) \Big) = Q - \pi a^2 \sqrt{\frac{q(t)^2}{\pi^2a^4}}, \] which is correct, but pretty ugly. Applying “simplify(...) assuming a>0, q(t)>0” changes that to \[ \frac14 \frac{ (q(t)^2 b - q(t)^2 a + 2Hg\pi^2a^5)^2 q(t) \big( \frac{d}{dt} q(t) \big)} {\pi^5 H^2 g^3 a^{12} } = Q - q(t), \] which is no great shakes either. Neither of these is as simple, or as expressive, as the hand-crafted equation \eqref{eq:de-for-q}.

The moral of the story? Don't copy blindly from the Maple worksheet. Put in the human touch!

Don't waste space

Space on printed page is precious. Publishers (and readers too!) don't like seeing wasted space. Thus, don't do things like \begin{align*} \bar{R} &=\frac{\lambda_u \bar{U}}{\lambda_r}, \\ \bar{P} &=\frac{\lambda_r \bar{R}}{\lambda_p} \end{align*} when the equivalent one-liner \[ \bar{R} =\frac{\lambda_u \bar{U}}{\lambda_r}, \quad \bar{P} =\frac{\lambda_r \bar{R}}{\lambda_p} \] is just as good, saves space, and is more pleasant to the eye. Here is how I typed that:

\[
	\bar{R} =\frac{\lambda_u \bar{U}}{\lambda_r},
	\quad
	\bar{P} =\frac{\lambda_r \bar{R}}{\lambda_p}
\]

The “\quad”, seen above, is a standard horizontal space which roughly equals the width of an uppercase letter “M” in the current font. There is also \qquad, which is twice a \quad, but it's used less often.

Quotation marks

Quotation marks in a typeset document come in opening/closing pairs, just like parentheses do. Observe the quotes in:

[`quotes' and ``quotes'']

Do you see that the opening and closing quotes are different?

The standard keyboard's double-quote key is inadequate for producing these and should never be used for that purpose in LaTeX. Use the backward and forward apostrophe keys instead, as in: `quotes' to produce single-quoted material, or double them up, as in ``quotes'' to produce double-quoted material.

Managing displayed equations

LaTeX (specifically, the American Mathematical Society's amsart documentclass,) provides various environments for formatting and displaying your equations. Here I will give an overview of the most common ones. The a complete documentation of the facilities provided by the amsart documentclass, consult User's Guide for the amsmath Package.

Note 1: This page shows the formatted result of the LaTeX code. To see the code that produced it, right-click on the displayed mathematics, then select “Show Math As”, then “TeX Commands”.

Note 2: Each of the equation, align, multline environment has an associated asterisked version, as in equation*, align*, multline*. The former results in numbered equation. The latter produces unnumbered equations.

The align environment
The align environment initiates the math mode and typesets a set of equations with vertical alignment: \begin{align} \frac{dx}{dt} &= f(x,y), \\ \frac{dy}{dt} &= g(x,y). \end{align}
The aligned environment
The aligned environment is like align but it does not initiate a math mode; you have to do that yourself. In the following example I use the equation environment to initiate the math, then use the aligned environment to do the alignment. Note that we get a single equation number because that's what the equation environment does: \begin{equation} \begin{aligned} \frac{dx}{dt} &= f(x,y), \\ \frac{dy}{dt} &= g(x,y), \end{aligned} \label{eq:system-with-one-number} \end{equation}

The align and aligned environments may be used for multiple vertical alignments. The general structure of such alignments is:

	x &= whatever       &           y &= whatever
	\\
	x &= whatever       &           y &= whatever

Note the middle ampersand. It separates the individually aligned left and right columns. Here is an application: \begin{align} \frac{dx}{dt} &= f(x,y), & x(0) &= x_0, \label{eq:align-part1} \\ \frac{dy}{dt} &= g(x,y), & y(0) &= y_0. \label{eq:align-part2} \end{align}

While you are at it, make a note of how this system of differential equations is punctuated with three commas and a period.

Another use for the aligned environment is to put a brace on the left-hand side of a set of equations: \begin{equation} \left\{ \begin{aligned} \frac{dx}{dt} &= f(x,y), & x(0) &= x_0, \\ \frac{dy}{dt} &= g(x,y), & y(0) &= y_0. \end{aligned} \right. \end{equation}

You should know, however, that such use of a brace gives a somewhat old-fashioned look to your document. The variants in \eqref{eq:system-with-one-number} and in \eqref{eq:align-part1}, \eqref{eq:align-part2} are more common nowadays.

The multline environment
If a mathematical expression is too long to fit in a single line, use multline to break it in two. The first half is pushed toward the left margin, the second half is pushed toward the right margin. There is no alignment involved. Here is an example: \begin{multline} P(t) = \frac{\lambda_u}{\lambda_p} \bar{U} + \frac{\lambda_u \bar{U} - \lambda_r r_0}{\lambda_r - \lambda_p} e^{-\lambda_r t} \\ - \frac{1}{\lambda_p (\lambda_r - \lambda_p)} \big( \lambda_r \lambda_u \bar{U} -\lambda_p \lambda_r r_0 -\lambda_p (\lambda_r - \lambda_p) p_0 \big) e^{-\lambda_p t}. \label{eq:multline} \end{multline} Remark: If you are going to break an equation into two lines, the comman practice is to do it at a binaory operator, such as a $+$, $-$, $/$, $=$, etc. In all cases the binary operator itself goes in the second line as you see in \eqref{eq:multline}.

Fractions and exponents

Fractions may be written in two equivalent ways either as $a/b$ or as $\frac{a}{b}$. The $a/b$ form is particularly good inside a sentence since it does not take up much vertical space, while the $\frac{a}{b}$ form is good in a displayed formula.

However, if the fraction appears in an exponent, then consider using the $a/b$ form regardless of sentence mode or display mode, as in: \[ c_1(t) = c_{1,0} e^{-t/T_1} + c_{1,\text{in}} (1 - e^{-t/T_1}). \] You might say that the exponents shown above don't look very good. And you would be right. This is because the positioning of characters in a web browser is not as precise as what you get in a printed document or in a PDF. The exponents will look much better in PDF.

Three kinds of dashes

Dashes are punctuation marks with quite well-defined meanings and usage in the English writing. Proper writing calls for a keen awareness of the different uses and meanings of dashes.

As far as LaTeX is concerned, dashes are of three kinds:

The hyphen
This separates parts of a compound word, such as “part-time”, “year-round”, “right-hand side”, “well-known”, “mother-in-law”, etc.

The computer keyboard's “minus sign” key, usually found next to the 0 key, is interpreted as a hyphen in LaTeX.

The en-dash
This is used to express a range, such as “years 2011–2015”, “pages 23–47”, “the June–July report”. It also works well in phone numbers: “410–455–2458”.

Another use of the en-dash is in the typesetting of paired names, such as “the Lotka–Volterra equations”, “the Hartman–Grobman theorem”, “the Cauchy–Schwarz inequality”, etc.

To appreciate the difference between a hyphen and an en-dash, compare:

with hyphens Lotka-Volterra2011-2015
with en-dashes Lotka–Volterra2011–2015

Two back-to-back hyphens are interpreted as an en-dash in LaTeX. Thus, you enter “years 2011--2015” and “the Hartman--Grobman theorem” in your LaTeX source.

Note that the object generated by “--” in LaTeX is emphatically not the same as two back-to-back hyphens. The “--” is a LaTeX code for the en-dash in the same way that \int is a LaTeX code for the integral sign.

The em-dash
This is used to interject a thought into a sentence. Here is a fragment from Alice's conversation with the Caterpillar in Alice in Wonderland:

“Well, perhaps you haven't found it so yet,” said Alice; “but when you have to turn into a chrysalis—you will some day, you know—and then after that into a butterfly, I should think you'll feel it a little queer, won't you?”

Three back-to-back hyphens are interpreted as an em-dash in LaTeX. Thus, you type the above as:

into a chrysalis---you will some day, you know---and then

Here is another example, taken from Strunk & White's The Elements of Style:

His first thought on getting out of bed—if he had any thought at all—was to get back in again.

You code that in LaTeX as:

getting out of bed---if he had any thought at all---was to
Attention!
Don't leave a space before or after a dash. This applies to all three kinds of dashes!

Floating figures

We insert figures in a LaTeX document through

\begin{figure}
    \centering
    \includegraphics[width=0.3\textwidth]{myfig.pdf}
    \caption{This is what the figure is about}
    \label{fig:myfig}
\end{figure}
The order of the items is very important! In particular, it is essential that \label comes after \caption, otherwise references to the figure number will be wrong!

We know that figures generally don't stay where you insert them in the LaTeX document; they float to some convenient place. Therefore, never say “this figure” or “the figure below” or “the figure above” because you don't know where in the document that figure will end up. Always refer to a figure through its label, as in “Figure~\ref{fig:myfig}”.

Just because a figure floats, it does not mean that you may stick it in a random place in your LaTeX document. You want a figure to appear reasonably close to the point in the text where you refer to it, but definitely not in a previous page. Use the following rule of thumb:

In your LaTeX file, insert the figure in the first paragraph-break after the first reference to the figure.