4

When you try to compile the following code:

\begin{equation}
   \phi = \psi

\end{equation}

The compilation fails with this error message:

! Missing $ inserted.

I know how to fix this. But still, I want to understand what the heck is the compiler trying to do and why it cannot compile this seemingly correct code. I am not asking how to insert a newline in the output file.

By the way, I only tried this using the pdftex compiler. I am not sure if this happens in every compiler.

6
  • 2
    Math mode has its own set of rules. Embrace it! ... um, I didn't mean with { } ...and welcome to the site. Commented Jun 7, 2018 at 18:08
  • 3
    rather than asking why tex gives an error, it could be asked why you would want to start an equation in one paragraph and end it in the next without that being flagged as an error? Commented Jun 7, 2018 at 18:27
  • 1
    Just place a single % at the beginning of those desired blank lines. You get the visual look that you seek, without actually introducing a \par in the environment. Commented Jun 7, 2018 at 18:33
  • 1
    Hahaha, that is indeed a simple solution. I don't know why it didn't occurred to me. Thanks! :) Commented Jun 7, 2018 at 18:36
  • 2
    remember that the latex \begin...\end syntax by design makes it clear the extent of the equation but the error is designed to trap the tex primitive syntax where you start the math with $ (or $$ for display) and then if you forget the closing $ all the spaces in your paragraph go and all the text becomes italic, without this error trap , one mssing $ would make your whole document on one line with no space in math italic Commented Jun 7, 2018 at 18:36

1 Answer 1

9

It is an error check built in to TeX (not latex) at its lowest level, similar to the runaway argument check that by default if you omit a closing brace to a macro \zz{.... It does not eat your entire document, the error is trapped at the end of the paragraph.

Similarly if you start math but end the paragraph before the math ends, that is an error that is flagged at the end of the paragraph,

Note that it is not latex or two newlines (which are reported as the token \par) but an occurrence of the par primitive that triggers the error, so this plain Tex document gives the same error

$$a\endgraf$$


\bye

Conversely this latex document generates no error, despite having a blank line in an equation:

\documentclass{article}

\begin{document}

\begin{equation}\let\par\relax
   \phi = \psi

\end{equation}


\end{document}
7
  • So is it TeX's mouth or its stomach that chokes on a \par? Sounds like the mouth, the way you describe it. Commented Jun 7, 2018 at 18:12
  • 1
    the digestion system is largely an artefact of the texbook, but stomach, I'll add a note @StevenB.Segletes Commented Jun 7, 2018 at 18:16
  • 1
    @StevenB.Segletes: See The TeXbook, p. 293, under “None of the above”: “…For example, if a \par command appears…”.
    – GuM
    Commented Jun 7, 2018 at 18:17
  • @StevenB.Segletes added a couple of examples, Commented Jun 7, 2018 at 18:22
  • 2
    @FranciscoTrucco: Maybe I’m a bit pedantic, but do not forget that D.C. warned you: the trick \let\par=\relax might look appealing, but entails disabling an error-checking feature deliberately programmed by Knuth.
    – GuM
    Commented Jun 7, 2018 at 18:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .