LaTeX forum ⇒ Math & ScienceFix 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).
Adam1215
Posts: 2
Joined: Thu Oct 20, 2011 5:46 am

Fix for Error "Missing # Inserted in Alignment Preamble"

Postby Adam1215 » Thu Oct 20, 2011 6:29 am

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.
  2. <to be read again>
  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,

Adam

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Thu Oct 20, 2011 9:41 am

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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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

Adam1215
Posts: 2
Joined: Thu Oct 20, 2011 5:46 am

Postby Adam1215 » Thu Oct 20, 2011 2:37 pm

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: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Sun Oct 23, 2011 11:41 am

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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ 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

Postby amacfie » Thu Apr 13, 2017 6:03 pm

It helped.


Return to “Math & Science”

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 4 guests