2

When I compile the following code everything runs with no issues:

$$
\left[ \begin{matrix}
2 & 3
\end{matrix} \right]
\quad
\left[ \begin{matrix}
2 & 3
\end{matrix} \right]
$$

However, when I add a blank line to improve readability, the compiler outputs an error about some missing $:

$$
\left[ \begin{matrix}
2 & 3
\end{matrix} \right]

\quad

\left[ \begin{matrix}
2 & 3
\end{matrix} \right]
$$

What can be causing this error? It seems to me there is nothing wrong with the syntax.

By the way, in case it might be useful, I am compiling with the command pdflatex beamer.tex.

Bernard
  • 271,350
  • 3
    You already know that an empty line in LaTeX means the end/beginning of a new paragraph... But what about math mode? Do you expect there to start a new math environment in its own line? Then just break the environment into two environments... by closing the previous and opening the next... (This is what compiler understood and was looking for the missing $) Display math doesn't have paragraphs... Inline math also doesn't have paragraphs... Also... what the \quad supposed to do there ... (You may comment out the empty lines if you need them for some reason) – koleygr Aug 11 '19 at 02:40
  • I think the two matrices are supposed to appear on the same line with a quad-space in between. – Davislor Aug 11 '19 at 02:46
  • @koleygr To be quite honest, I was testing the different matrix environments. But I imagine using it, for example, to display matrices side by side after you apply row operations on them. And the spaces were added to visually separate each matrix. – Max Toro Aug 11 '19 at 02:49
  • 7
    If you want to add empty lines for readability, put % at the beginning of the empty line. TeX will completely ignore it then. Unrelated to the problem, have a look at Why is [ … ] preferable to $$ … $$? – siracusa Aug 11 '19 at 02:50
  • 2
    This is by design and built in to tex-the-program to stop a missing math delimiter destroying the rest of the document. – David Carlisle Aug 11 '19 at 07:31
  • Unrelated, but amsmath defines a bmatrix environment, which results in a shorter code. – Bernard Aug 11 '19 at 09:40

1 Answers1

2

(too long for a comment, hence posted as an answer)

You wrote,

It seems to me there is nothing wrong with the syntax.

Actually, something is wrong with the syntax: All-blank lines are not allowed in math mode -- both inline math mode and display math mode.

For more on this subject, please see the earlier postings Blank lines in align environment and Error in align environment - runaway argument. Aside: The align environment is a displaymath-mode environment.

A separate plea: Don't use $$ in a LaTeX document to initiate and terminate display-math mode. For more information on this subjecct, please see the postings Why is \[ ... \] preferable to $$ ... $$ and What are the differences between $$, \[, align, equation and displaymath?

Mico
  • 506,678
  • Actually, blank lines are not allowed in any math environment, whether display or in-line. As @DavidCarlisle said in a comment, this is by design: since math cannot extend across paragraphs, the error is reported if any paragraph break occurs while a math expression is incomplete. – barbara beeton Aug 13 '19 at 01:15
  • @barbarabeeton - Many thanks for this comment. I've updated my answer accordingly. – Mico Aug 13 '19 at 13:17