4

Why blank lines between equation makes error? there are a lot of commands in latex and almost for all of them these blank lines are not important, but why in this case is important and is there any similar function?

  • A blank line tells LaTeX to start a new paragraph, but that's not allowed in math mode. – Null Jun 17 '16 at 4:16
  • Just to clarify: In text mode, the first blank line is actually very important, as it induces a paragraph break. It's only from the second consecutive blank line onward that further blank lines aren't important. – Mico Jun 17 '16 at 5:54
  • 1
    @Nasser it is by design so that a single mistake doesn't eat your whol edocument and allows TeX to recover. – David Carlisle Jun 17 '16 at 6:46
  • 1
    The statement in the question that in most other contexts a blank line is not important is not really true, a blank line is equivalent to the command \par and in almost all contexts this has some effect which may or may not be important, depending where it is used. – David Carlisle Jun 17 '16 at 6:47
  • 2
    If you like visual space in your input document, I normally just place a line by itself, with a % in column 1. This looks almost like a blank line, but is not considered one by LaTeX. – Steven B. Segletes Jun 17 '16 at 10:43
5

An excerpt from page 135 of the TeXbook:

... [A] blank line or \par is not permitted in math mode. This gives TeX another way to recover from a missing $; such errors will be confined to the paragraph in which they occur.

Knuth provides the following example to motivate this syntax rule:

For example, suppose you were to write

   The smallest $n such that $2^n>1000$ is~10.

TeX doesn't know that you forgot a $ after the first n, because it doesn't understand English; so it finds a "formula" between the first two $ signs: enter image description here after which it thinks that 2 is part of the text. But then the ^ reveals an inconsistency; TeX will automatically insert a $ before the ^, and you will get an error message. In this way the computer has gotten back into synch, and the rest of the document can be typeset as if nothing had happened.

So, while it may seem like a nuisance at first not be be allowed to have blank lines in (inline or display) math mode, there's actually a very good reason for this syntax rule: It helps confine the error to the paragraph in which it occurs and lets you compile the rest of the document (assuming you want to do so).

Of course, if we could absolutely guarantee that we'd never ever have any missing $ symbols in our inputs, the prohibition against blank lines wouldn't be needed to begin with. However, which of us is fully able and willing to provide such a guarantee?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.