## \def, \newcommand, \span and \align

I learnt something about TeX/LaTeX today.

I got the following cryptic error message:
! Missing # inserted in alignment preamble.

 

 \crcr l.38 \end{align*}

Now when I went to google “Missing # inserted in alignment preamble”, I immediately got a lovely website which was able to answer my question. But hey, information survives by being copied, so if you’ll kindly allow me to continue, I shall.

Stripped down to a minimal example, here is the problematic code.

\documentclass[11pt, reqno]{amsart}

 \usepackage{amsmath} \def\span{\,\mbox{span}\,} \begin{document} \begin{align*} u &= \arctan x & dv &= 1 \, dx \\ du &= \frac{1}{1 + x^2} dx & v &= x. \end{align*} 

\end{document}

Actually stripping down to a minimal example kind of makes it obvious where the error is – it must be somewhere in the \def\span line.


The problem in the above code is that \span is already defined to be something important needed to internally execute the \align command. By using \def, we’re redefining what \span means. If we used \newcommand instead, we wouldn’t be able to redefine \span and we’d get an instructive error message.

So the moral of the story is: \newcommand is safer.