# When one should use spacing line \quad or \,

In general, in most places, it is said that using TeX defaults is the best. However, TeX does provide things like \, and \quad etc. When one should use them? Both in general and in math mode in particular.

-
Although this does not answer the question, this post gives some insight into the respective whitespace distances (both positive and negative) which may shed light on some of their uses - thanks @Herbert. –  Werner Aug 16 '11 at 15:45

The classic Mathematics into Type, by Ellen Swanson (the AMS has made a PDF copy available here), gives a good explanation (Section 3.1 SPACING BETWEEN SYMBOLS IN MATHEMATICS) of when to use no space, thin space, thick space, em quad and two-em quad in math mode. A brief summary:

# No space

• Between two symbols and between a number and the symbol it multiplies.

• Before and after subscripts, superscripts, parentheses, braces, brackets, and vertical rules.

• In expressions in the subscript or superscript.

# Thin space

• Before and after symbols used as verbs.

• Before and after symbols used as conjunctions.

• After, but not before +, -, \pm, \mp used as an adjective.

• After the commas in sets of symbols, sequences of fractions, and coordinates of points.

• Before and after the symbols of integration, summation, product, and union.

• Before and after functions set in roman type. Exceptions: If any of these functions are preceded or followed by parentheses, braces, brackets, or bars, then the space is eliminated.

• Before and after vertical rules appearing singly rather than in pairs; the same rule holds for a colon that is used as a mathematical symbol rather than as punctuation.

• Before back subscripts.

• Before and after ds, dx, and similar combinations of d and another symbol following.

# Thick space

• Before the parenthesis in congruences in text.

• Before a mathematical condition in text.

• Between a symbolic statement and a verbal expression in displayed expressions.

• Around conjunctions.

• Between two separate equations or inequalities in the same line.

• Between a symbolic statement and a condition on the statement.

TeX has built-in spacing, and most of the times it does an excellent job, so (most of the times) you don't need to add space manually.

The following document contains the summary of the rules given by Swanson and some examples; these examples also contain some cases which are not built-in and which require manual attention.

\documentclass{article}
\usepackage{amsmath}

\setlength\parindent{0pt}
\begin{document}

\textbf{No space}\    Between two symbols and between a number and the symbol it multiplies:
$ab\qquad xy\qquad 2a\qquad 2xz\qquad 4aC$

Before and after subscripts, superscripts, parentheses, braces, brackets,
and vertical rules:
$2x^2y_3z (x)y\qquad a\{b\}\qquad y[a]\qquad a\lvert x\rvert\qquad b\lVert y\rVert$

In expressions in the subscript or superscript:
$\lim_{0\to a}\qquad a^{n-1}$

\textbf{Thin space}\    Before and after symbols used as verbs:
$a \subseteq 2$

Before and after symbols used as conjunctions:
$a +2$

After, but not before $+$, $-$, $\pm$, $\mp$ used as an adjective
$a= -2$

After the commas in sets of symbols, sequences of fractions, and coordi-
coordinates of points:
$(a,b,c)$

Before and after the symbols of integration, summation, product, and
union:
$a\int x\,\mathrm{d}y$
The thin space between $x$ and $\mathrm{d}y$ in the expression above is \emph{not} built
into \TeX.

Before and after functions set in roman type:
$a \sin x \qquad \log 2.$
Exceptions: If any of these functions are preceded or followed by parentheses, braces, brackets, or bars, then the space is eliminated:
$a \sin \lvert x \rvert.$

Before and after vertical rules appearing singly rather than in pairs; the
same rule holds for a colon that is used as a mathematical symbol rather
than as punctuation:
$a \mid b$

Before back subscripts:
$a\,_2T_3$
The thin space between $a$ and the following back subscript on $T$ in this example is not built into \TeX.

Before and after $\mathrm{d}s$, $\mathrm{d}x$, and similar combinations of $d$ and another
symbol following:
$\int f(x)\,\mathrm{d}x\qquad \iiint f(x)\,\mathrm{d}r\,\mathrm{d}\theta\,\mathrm{d}\phi$

\textbf{Thick space}\    Before the parenthesis in congruences in text: $z= a\pmod x$

Before a mathematical condition in text: $t_n\ (n=1,2,\ldots, p)$

\textbf{Em quad}\    Between a symbolic statement and a verbal expression in displayed expressions
$E_n(t) \to e^{-t}\quad\text{as }t\to\infty.$

Around conjunctions:
$x(a+b)\quad\text{or}\quad y(a-b).$

\textbf{Two-em quad}\    Between two separate equations or inequalities in the same line
$x^2 + y^2 = a^2,\qquad x-y=b.$

Between a symbolic statement and a condition on the statement
$x^n + y^n = a^n\qquad (n = 1,2,\ldots p).$

\end{document}

The compiled code looks like :

-
For those interested, two more books dealing with math spacing: [1] Chaundy, Barrett and Batey, The Printing of Mathematics, Oxford University Press, 1957, p. 86-91 (more complete than Swanson); [2] Wick, Rules for Type-setting Mathematics, 1965, p. 52-59 (not as interesting). –  Philippe Goutet Aug 16 '11 at 20:21
@Gonzalo: At the end of your answer as well as in the example, you mentioned that sometimes manual spacing should be done. Is there a complete list of the two cases, namely when thin space is need and implemented in TeX, and when it has to be added manually? –  Dror Aug 17 '11 at 7:30
TeX spaces symbols more exactly than some of Ellen Swanson's rules above would imply. For instance, in $a=b$ it puts a thick space (created manually with \;) on either side of the = (a verb symbol), in $a+b$ it puts a medium space (created manually with \>) on either side of the + (a conjunction symbol), and in $a\sin b$ it puts a thin space (created manually with \,) on either side of "sin" (a function set in roman type). –  MSC Apr 14 '12 at 19:47
@Gonzalo -- a pdf copy of "math into type" has just been posted on-line at ams. this edition isn't perfect, but the consensus here is that it's more useful to post it now than to wait for it to be updated. (it's still under copyright. redistribution is discouraged, but linking is okay.) –  barbara beeton Nov 29 '12 at 18:21
@barbarabeeton those are good news! I've updated my answer providing the link. Thank you! –  Gonzalo Medina Dec 10 '12 at 23:15

Addressing why, the table in the AMS' Short Math Guide for LaTeX, discussing spacing in math mode, provides a helpful approach. If we use the elements as intended then TeX will provide good (arguably, best) spacing. However, if the elements are used like an member of another class then adjustments to spacing may be needed:

Class     Mnemonic    Description                Examples
number             (Parts of speech)
0         Ord      simple / ordinary ("noun")    A 0 Φ ∞
1         Op       prefix operator               \sum
2         Bin      binary operator (conjunction) + ∪ ∧
3         Rel      relation/comparison (verb)    = < ⊂
4         Open     left/opening delimiter        ( [ {
5         Close    right/closing delimiter       ) ] }
6         Pun      postfix/punctuation           . , ; !

symbols of class Bin, notably the minus sign −, are automatically coerced to class 0 (no space) if they do not have a suitable left operand.

The spacing for a few symbols follows tradition instead of the general rule: although / is (semantically speaking) of class 2, we write k/2 with no space around the slash rather than k / 2. And compare p|q p|q (no space) with p\mid q p | q (class-3 spacing).

As others have pointed out, there are views on what changes to spacing improve the look, or ease of comprehension, of a document. Often an author will have to follow a house style but changes to the default should be considered carefully when a symbol is being used as TeX would expect. It should be noted, too, that best typographic practice varies between languages and over time.

-
• in math mode never, except for very special cases. For a differential operator like dx it is better to define \newcommand*\diff{\mathop{}\!\mathrm{d}} and then use \diff x in math
• in text mode for e.\,g. or in german z.\,B. or titles like Dr.\,med.
• \quad can be used whenever you need some space in text mode, same for \qquad
-
I use  after every acronym that has . at the end, this way the .won't be followed by a larger space (which is what TeX dos because it thinks the . is the end of a sentence). e.g.: the e.m.k.\ for this chain is... –  romeovs Aug 16 '11 at 9:43
Is \,, as in e.\,g., the canonical way of handling spacing in abbreviations? –  N.N. Aug 16 '11 at 9:56
from typographers view it is the canonical way –  Herbert Aug 16 '11 at 10:04

One common case (in math mode) is with integrals:

\int f(x)\,dx

is much better with \, (even better is \int f(x)\,\textup{d}x, by the way).

Another common case is with factorials: compare 2!3!4! to 2!\,3!\,4!.

Also, some people might argue that \sqrt{\,\log 2} look better than without a \,.

Another interesting case is with : - \{x:x^2-1>0\}, but f\colon X\to Y. Formally, you don't use \, or similar macros, but \colon is similar: it is hand-made tuning of spacing.

On the other hand, sometimes \! (a negative thin space) is also needed, although I can't recall the exact example.

(These examples are what I remember from The TeXbook, which I don't have at home; as far as I remember there are more of them there.)

In general, since both semantics and typesetting of math is so complex, it is actually quite often that you need fine-tuning like that.

And \quad and \qquad is another story – e.g., spacing between two formulas in display mode.

-
Knuth gives, inter alia, the following two examples for using negative thin spaces to fine-tune TeX's output: (\ \int!\int dx\,dy ) and [ \int\!\!\!\int dx\,dy ] , i.e., double integrals in text- and display-style math. –  Mico Aug 16 '11 at 10:22
@Mico: more on \! in tex.stackexchange.com/q/9091 –  Philippe Goutet Aug 16 '11 at 20:04