Fine-Tuning Spacing in LaTeX Equations

For several years I’ve been fine-tuning the spacing in LaTeX equations using a tip from Donald Knuth (the same tip works with TeX). He mentioned it in a question and answer session that he gave in 1996 in Holland and which is written up in Digital Typography (1999, p. 641). The idea, which he uses in The Art of Computer Programming, is to write

% Make @ behave as per catcode 13 (active).  TeXbook p. 155.
\mathcode`@="8000 
{\catcode`\@=\active\gdef@{\mkern1mu}}

Then within a formula the @ symbol acts as a macro that inserts 1mu of space. A mu is a math unit. For comparison, a thinspace,

\,

represents 3mu and a \quad 8mu.

Knuth gives the example \sqrt{@\log n} to produce the right amount of space before the l of log.

Some examples of my use of @ from my Functions of Matrices book are

\|@@|A^{-1}|@@\|_F
\sqrt{A}^{@@\pm 1}f(\sqrt{A})
f(uv^*) = f(0)I + f[v^*u,0] @@ uv^*
p_{km}(x) = \sum_{j=0}^k \frac{ (k+m-j)!@@ k! }{ (k+m)!@@ (k-j)! }

There aren’t really any rules; the use of @ is largely a matter of taste as to what looks right.

This level of fine-tuning is not something I do as a matter of course in drafts, or with any rigour in papers, but for a book I think it is well worth the effort.

Knuth also points out that $n^2/3$ looks better with a negative thin space, as $n^2\!/3$, so that there is less space between the superscript and the slash. On checking the LaTeX source I notice that I did this in my book, but had forgotten about it until I wrote this post!

This entry was posted in LaTeX. Bookmark the permalink.

2 Responses to Fine-Tuning Spacing in LaTeX Equations

  1. great – that’s what I was looking for a since ever.

  2. awesome! Works like a charm

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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