Formatting and math style in LaTeX

LaTeX gives almost infinite control over formatting, and it is possible to spend hours making small adjustments to a document, forcing every character and every pixel to be in an optimal location.

A much easier solution is to trust LaTeX to format documents. Though it might not look exactly as you might envision, LaTeX’s standard document classes do a surprisingly good job at formatting. Of course, some manual adjustments might still be in order; you might want to change the default indent size (e.g. with \parindent=0in), force some space between paragraph breaks (e.g. with \parskip=5px), or change the margins (e.g. with the geometry package or using \usepackage{fullpage}). The general structure of a document, however, is best left up to LaTeX’s default styles.

LaTeX can fairly easily create a title heading. Here is an example:

\title{All of Mathematics}
\author{C.F. Gauss}
      This paper explains all of mathematics, in alphabetical order.

The final \maketitle command tells LaTeX to display the title, author, email, date, and abstract information in the style defined by your documentclass.

LaTeX can also handle section headings and section numbering. To start a new section, simply say \section{My new section}. Similarly, you can define new subsections and subsubsections with \subsection{My subsection} and \subsubsection{A subsubsection}. These sections (and subsections and subsubsections) are automatically numbered sequentially. (To disable automatic numbering in LaTeX, add an asterisk, i.e. \section*{Unnumbered section}.)

LaTeX is also often used with mathematical expressions, for which there are also some stylistic points to keep in mind. Firstly, it is a good idea to use displayed equations. These can be used for long or complicated expressions to make them easier to read. When surrounded by text, they also serve to break up long paragraphs into more manageable chunks. Even simple equations can be displayed to make them stand out, such as

\displaystyle  e^{i\pi}+1=0.

Something to keep in mind is that all punctuation following a displayed equation should be placed in math mode, immediately following the equation.

Make it a habit to use math mode for all mathematical symbols, regardless of length. For example, it looks ugly to say “Consider a function f with f'(x) = x+5“; instead, say “Consider a function f with f'(x) = x+5“. Doing this allows you to clearly differentiate between math symbols and text, and also eliminates confusion resulting from math mode letters looking different from text mode letters.

LaTeX also provides a number of math operators for easy formatting. For example, log x looks ugly, while \log x looks much better. It is easy to define new operators as well. For example, if you want to use “disc” to denote a discriminant, then you can use \def\disc{\operatorname{disc}} or \DeclareMathOperator{\disc}{disc} to define the \disc operator. This allows you to type \disc K to get \mathrm{disc}\, K.

You can also use expanding delimiters in large math expressions. For example, compare

\displaystyle  P(\frac1x) \qquad P\left(\frac1x\right).

The symbol on the right is achieved by writing $P\left(\frac{1}{x}\right)$. All other delimiters expand as well, via commands like \left[, \left\{, \left|.

For clarity, inline fractions in text can be typeset horizontally. That is, in a typical font size, the fraction 79/128 is easier to read than the fraction \frac{79}{128}. Of course, there are plenty of cases when you want to write fractions vertically, such as when they are part of a larger expression (e.g. \frac12 + \frac13 = \frac56).

Long equations can be broken up. It’s no good when an equation is too long and runs off the page, and it’s ugly to see an equation reach into the margin. Instead, break the equation up at binary operators and equals signs, such as + or =. Long calculations can be broken up at each equals sign, such as

\displaystyle  \begin{array}{rcl}  K_m(s) &=& \frac{1}{m+1} \frac{1}{1- e^{it}} \left( \frac{1 - e^{-i(m+1)s}}{1 - e^{-is}} - e^{is} \frac{1 - e^{i(m+1)s}}{1 - e^{is}}\right) \\ &=& \frac1{m+1} \frac1{e^{is/2} (e^{-is/2} - e^{is/2})} 	\left( 		\frac{1 - e^{-i(m+1)s}}{e^{-is/2} (e^{is/2} - e^{-is/2})} 		-\frac{e^{is} (1 - e^{i(m+1)s})}{e^{is/2} (e^{-is/2} - e^{is/2})} 	\right) \\ &=& \frac1{m+1} \frac1{e^{-is/2} - e^{is/2}} 	\left( 		\frac{1 - e^{-i(m+1)s}}{e^{is/2} - e^{-is/2}} 		-\frac{1 - e^{i(m+1)s}}{e^{-is/2} - e^{is/2}} 	\right) \\ &=& \frac1{m+1} 	\left( 		\frac{ e^{i(m+1)s} + e^{-i(m+1)s} - 2 }{(e^{is/2} - e^{-is/2})^2} 	\right) \\ &=& \frac1{m+1} 		\frac{ \sin^2 (\frac{m+1}2 s) }{\sin^2 \frac s2}. \end{array}

Similarly, it is a good idea to align lists of equations at equal signs, such as

\displaystyle  \begin{array}{rcl}  \sin\theta &=& y \\ \cos\theta &=& x \\ \tan\theta &=& \frac yx \end{array}

Such an effect can be achieved using a construction like

       \sin\theta &= y \\
       \cos\theta &= x \\
       \tan\theta &= \frac yx.

Integrals need extra space. Compare:

\displaystyle  \int x^2 dx \qquad \int x^2 \, dx.

The second integral separates the dx from the integrand, making the equation more clear. This was typeset using $\int x^2 \, dx$, where the \, serves to add a bit of space.


One response to “Formatting and math style in LaTeX

  1. Xamuel June 15, 2011 at 1:59 pm

    Re: Expanding delimiters: you can also use \left. and \right. (note the . after the \left and \right) for an “invisible” delimiter. Why is this important? Because it lets you have one-sided expanded delimiters. One example where this is used is in elementary calculus when an expression is “evaluated from a to b”:

    $\int_0^1 x^2 dx = \left. \frac{x^3}{3} \right]_0^1$

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: