## LaTeX forum ⇒ Math & Science ⇒ Fix for Error "Missing # Inserted in Alignment Preamble" Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Posts: 2
Joined: Thu Oct 20, 2011 5:46 am

### Fix for Error "Missing # Inserted in Alignment Preamble"

Hi,

I'm not sure if this is a proper use of this board, but I just spent a considerable amount of time trying to solve a problem that the Internet was no help for, and I figured that if anyone else ever has this problem, this post might save them some time. (The problem was in align, and the Internet's only suggestion was "use eqnarray instead".) I'm still just a n00b, though, so if this should go elsewhere or nowhere, or if the solution is obvious and I just need more experience, let me know.

Anyway, I was getting the following error when using "align":
1. Missing # inserted in alignment preamble.
3. \crcr
4. 1.232 \end{align}

It turned out that I was doing this:
\def\span{\mathrm{span}}

Redefining \span (which LaTeX apparently uses for something completely different) screwed up the compiling of the align environment. Switching \span to \spn (or anything else the LaTeX didn't already use) immediately fixed the problem.

The big issue was that there was no indication of \def\span being a problem. On further testing after finding the problem, switching to \DeclareMathOperator{\span}{span} gave an illuminating error.

So, to anyone with this error, start with the simplest possible file:
1. \documentclass{article}
2. \usepackage{amsmath}
3.
4. \begin{document}
5.
6. \begin{align}
7. 0 &= 0 \\
8. 1 &= 1
9. \end{align}
10.
11. \end{document}

Does that compile? Good. (If not, sorry and good luck.)
Now, start adding your "\def"s from the offending document. Keep doing so until the file won't compile anymore. That last one is your culprit.

Hope that helps,

localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany
You can evade this trouble by defining a command not with TeX commands, but with LaTeX commands. At first you could check that by a simple line in the preamble.
1. \newcommand{\span}{}

If the command is defined, you will get an error. That's the usual way to define commands and to make sure not to overwrite something. There is another method to make sure that existing commands are not simply overwritten.
1. \providecommand{\span}{\mathrm{span}}

This will cause no error but only define the command if it doesn't already exist. Otherwise the definition is ignored.

Since you consider yourself a noob, you should not tinker around with stuff from which you don't know for sure what it really does. And TeX's \def command is certainly nothing for beginners. It overwrites commands without checking if the defined command already exists. So, hands off!

Best regards and welcome to the board
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

Posts: 2
Joined: Thu Oct 20, 2011 5:46 am
Thanks! When I started learning LaTeX, \def was the first command I found that let me make shortcuts for equations, and so that's been what I've been using. From now on, only \newcommand!

localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany
Adam1215 wrote:[…] When I started learning LaTeX, \def was the first command I found that let me make shortcuts for equations, and so that's been what I've been using. […]

You are well advised with only reading appropriate stuff for beginners [1]. Manuals or papers that suggest \def for the definition of new commands are definitely not for newcomers.

[1] View topic: LaTeX Resources for Beginners
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

amacfie
Posts: 1
Joined: Thu Apr 13, 2017 6:01 pm
It helped.