Why does TeX attempt to insert missing tokens? Why doesn't it simply throw up and die?
More importantly, is there any case where this insertion in fact does go unnoticed?
Why does TeX attempt to insert missing tokens? Why doesn't it simply throw up and die?
More importantly, is there any case where this insertion in fact does go unnoticed?
Many syntax errors in a (La)TeX document are simple mistakes due to forgetting a $ or a backslash, say a & or $ instead of \& and \$ in text. Other common errors are due to mistyping a command or forgetting a brace.
TeX is quite good in getting back in sync when such errors happen: a misplaced $ or a missing one can be catched and most of the times this suffices to go on in processing the document. Sometimes, though, a missing brace can be disastrous.
Why did Knuth chose to attempt error recovery? You have to remember when TeX was designed: computers were very different at the time and most TeX runs were done as batch jobs: the job was sent to a queue and run when the mainframe computer allocated some time for it. Stopping the run at the first error would have meant ruin the job, while error recovery may catch several typing errors in a single run. Error recovery can be beneficial also in interactive runs: you see the error and the recovery attempt, but in this case you can also insert tokens or delete those that TeX wants to insert.
When processing MWE for questions on the site this can be very beneficial.
;-)
– egreg
May 14 '13 at 22:42
In some situations TeX assumes, that some text is misspelled. Sometimes the expected way of a correction is removing problematic command, sometimes -- adding additional expressions. E.g. if you type only \sin(x), TeX assumes, that you lost a dollar sign, because \sin must appear inside math.