Archive for the ‘latex’ Category

\def, \newcommand, \span and \align

March 9, 2014

I learnt something about TeX/LaTeX today.

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

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}




u &= \arctan x & dv &= 1 \, dx
\\ du &= \frac{1}{1 + x^2} dx & v &= x.


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.

It turns out that \def and \newcommand act differently. I’d always just assumed that \def and \newcommand were synonymous, and used the former since it involved less typing. And it’s true, most of the time you don’t notice the difference.

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.


Best Blogpost Ever

August 3, 2012

There should also be an entry (I haven’t checked to see if it exists)

pdflatex: comment.sty not found

sudo apt-get install texlive-latex-extra