Math & ScienceFix for Error "Missing # Inserted in Alignment Preamble"

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

Fix for Error "Missing # Inserted in Alignment Preamble"

Post by Adam1215 »

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":

Code: Select all

Missing # inserted in alignment preamble.
<to be read again>
\crcr
1.232 \end{align}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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:

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
0 &= 0 \\
1 &= 1
\end{align}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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,

Adam

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Fix for Error "Missing # Inserted in Alignment Preamble"

Post by localghost »

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.

Code: Select all

\newcommand{\span}{}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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.

Code: Select all

\providecommand{\span}{\mathrm{span}}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
Adam1215
Posts: 2
Joined: Thu Oct 20, 2011 5:46 am

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

Post by Adam1215 »

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!

Adam
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Fix for Error "Missing # Inserted in Alignment Preamble"

Post by localghost »

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
amacfie
Posts: 1
Joined: Thu Apr 13, 2017 6:01 pm

Fix for Error "Missing # Inserted in Alignment Preamble"

Post by amacfie »

It helped.
Post Reply