1

I got some fatal error from my code:

\begin{align}

a_{n+1}-a_{n} &= \frac{1}{n+2}\left(1+\frac{1}{2} + \cdots + \frac{1}{n+1} \right) - \frac{1}{n+1} \left(1+\frac{1}{2} + \cdots + \frac{1}{n} \right) \ & = \left(\frac{1}{n+2} - \frac{1}{n+1} \right) \left( 1+\frac{1}{2} +\cdots+ \frac{1}{n}\right) + \left(\frac{1}{n+1} - \frac{1}{n+2} \right)

\end{align}

I looked through every possible reasons that make error, but still couldn't figure them out. I have tried to find out the function available in math mode but there were none. The first error message I am confronted with is

Runaway argument?

! Paragraph ended before \align was complete. <to be read again> \par

followed by further error messages if I tell LaTeX to keep stepping through the compilation process. Could you help me to figure those errors out? Appreciate with this.

\begin{align}
a_{n+1}-a_{n} &amp;= \frac{1}{n+2}\left(1+\frac{1}{2} + \cdots + \frac{1}{n+1} \right) - \frac{1}{n+1} \left(1+\frac{1}{2} + \cdots + \frac{1}{n} \right) \\
&amp; = \left(\frac{1}{n+2} - \frac{1}{n+1} \right) \left( 1+\frac{1}{2} +\cdots+ \frac{1}{n}\right) + \left(\frac{1}{n+1} - \frac{1}{n+2} \right)

\end{align}

Mico
  • 506,678
ToBY
  • 113
  • 5

1 Answers1

3

The code seems fine but I had to remove the empty lines.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align} a_{n+1}-a_{n} &= \frac{1}{n+2}\left(1+\frac{1}{2} + \cdots + \frac{1}{n+1} \right) - \frac{1}{n+1} \left(1+\frac{1}{2} + \cdots + \frac{1}{n} \right) \ & = \left(\frac{1}{n+2} - \frac{1}{n+1} \right) \left( 1+\frac{1}{2} +\cdots+ \frac{1}{n}\right) + \left(\frac{1}{n+1} - \frac{1}{n+2} \right) \end{align}

\end{document}

enter image description here

  • Didn't know that empty line would take a quite important role. Thanks, sir. – ToBY Mar 23 '22 at 03:51
  • 1
    @ToBY Especially in math stuff this is important! – Dr. Manuel Kuehner Mar 23 '22 at 03:53
  • 1
    @ToBY - The prohibition against empty lines actually comes (mostly) from the amsmath package. The amsmath package performs a lot of useful background work to optimize the placement of equation numbers. (E.g., if a line is too long, LaTeX will move the equation number down and out of the way, which is much better than to overprint it with math stuff.) It turns out that this background work cannot be performed successfully if LaTeX encounters empty lines while in displaymath mode. This is because empty lines trigger something that's quite analogous to paragraph breaks in text mode. – Mico Mar 23 '22 at 05:58
  • 1
    The macro \align should be defined as \long\def but it doesn't. If it were \long\defed then no such error occurs. Moreover, LuaTeX has \suppressmathparerror register: when it is positive then \par are ignored in math mode. And the problem discussed here exists because LaTeX users mostly does not know TeX features. Especially: empty lines are transformed to \par by tokenizer: if you doesn't know about this feature then you are unable to understand the TeX error message given here. – wipet Mar 23 '22 at 06:52
  • @wipet - I don't think the correct diagnosis is as simple as the one you provide. (If it were so simple, then wouldn't the creators/maintainers of the amsmath package have taken your suggested remedy on board a long, long time ago?) AFAICT (and I admit that I might be wrong on this...) the root cause for amsmath not being able to handle the equivalent of paragraph breaks lies in the fact that it performs a two-step optimization process (first measure widths, then typeset). The facile claim that "LaTeX users mostly don't know about TeX features" seems rather specious to me. – Mico Mar 23 '22 at 07:59
  • The amsmath maintainers cannot do this long time ago because the \par is interpreted as error by TeX itself in display mode and they were inspired by this behavior. Only LuaTeX is able to ignore \par in display math (which is much more intuitive behavior, OpTeX does the same). But amsmath can be used in other TeX engines too. – wipet Mar 23 '22 at 09:59
  • Hi guys, I assume that this is an information overload for a beginner :). – Dr. Manuel Kuehner Mar 23 '22 at 13:47