3

Compiling the following document will raise the errors

Paragraph ended before \align was complete

and

Displaymath should end with $$

because par-breaks are not allowed in math environments/displaymath.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
Empty 

are not allowed.
\end{align}
$$
Empty lines

are not allowed
$$
\end{document}

While editing however, I frequently accidentially compile after hitting enter (creating a new line) and before adding any content, hence I am searching for a method to allow paragraph breaks in math mode, ideally ignoring them.

Just for comparison, if I needed only display-math without AMS environments, a viable solution would be

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\begin{document}
\everydisplay{\def\par{\mathbf{\color{red}-forgotten-par-}}}
$$ 
Empty\,lines

are\,now\,allowed

but\,you\,get\,a\,reminder
$$
\end{document}

Is there some solution that works across all common math environments?

kdb
  • 1,889
  • If a well understand you want to enforce line breaks (newline) inside math mode ? – Cfun Jul 01 '16 at 15:21
  • 1
    Don't use $$ in LaTeX to begin with. See Why is \[ … \] preferable to $$? – egreg Jul 01 '16 at 15:31
  • Related: http://tex.stackexchange.com/questions/230338/syntax-of-using-math-mode-empty-lines-beginner-question – egreg Jul 01 '16 at 15:34
  • @SAM No, I really only want to avoid compilation failure when I start a new (source code) line in math mode and haven't typed anything yet. – kdb Jul 04 '16 at 08:53
  • @egrep I mostly used $$ only to demonstrate, that the "problem" occurs across multiple macros. Thanks for the link though; Using almost exclusively AMS environments, I never heard of that. – kdb Jul 04 '16 at 08:55

2 Answers2

2

I wouldn't recommend it, but if luatex is an option, it allows both these errors to be disabled without making any changes to the macros.

\suppressmathparerror = 1
\suppresslongerror = 1
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
Empty 

are not allowed.
\end{align}
$$
Empty lines

are not allowed
$$
\end{document}
David Carlisle
  • 757,742
1

This is an answer for first version of the question.

You are seeking problems. Partial solution, working for $$, but not amsmath-based environments is below. Check it, please and never use it.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\let\normalpar=\par
\def\par{\ifmmode \else\normalpar \fi}
\begin{align}
Empty 
%
are not allowed.
\end{align}
$$
Empty lines

are not allowed
$$
\end{document}