1

Here's a line of erroneous code.

\documentclass{standalone}
\begin{document}
\frac{a}{M}
\end{document}

As we expect, the compiler throws a "missing $" error.

! Missing $ inserted.
<inserted text> 
                $
l.91 \frac{a}{M}

I've inserted a begin-math/end-math symbol since I think you left one out. Proceed, with fingers crossed.

My question is: how are the missing $ inserted?

I expect that the system would insert $ at both the start and the end of line, so that the compiler would give

enter image description here

However, the compiler actually gave me this.

enter image description here

I dont't understand why the first token list {a} of the \frac command was interpreted as text.

When I try math mode only commands, the first token list would be interpreted in math mode. For example, frac{\sqrt2}{M} gives this.

enter image description here

  • First, the class should be standalonE not standalon – JeT Oct 25 '22 at 21:04
  • nice catch my bad. lemme fix that. – GNUSupporter 8964民主女神 地下教會 Oct 25 '22 at 21:05
  • 1
    My explanation: \frac expands to \begingroup #1\endgroup \over #2. The a (in #1) doesn't need math-mode so it doesn't trigger the error but \over does → a $\over M $. But with \sqrt this gets triggered twice: at the \sqrt and then at the \over. Compare \begingroup \sqrt{2} \endgroup a vs \sqrt{2} a. But I'm sure there is more to say about whatever TeX is doing deep down. – Qrrbrbirlbel Oct 25 '22 at 21:20
  • I've explained in some detail a very similar issue in an answer to https://tex.stackexchange.com/q/575988/82917 – campa Oct 25 '22 at 21:25
  • @campa re-open that one? (closed as solved in comments is never a good reason) – David Carlisle Oct 25 '22 at 21:38
  • 1
    The difference with the question marked as duplicate is that a is legal in text mode, but \sqrt{2} isn't. – egreg Oct 25 '22 at 21:51

0 Answers0