8

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?

  • 4
    This answer seems appropriate, especially the part about 'the olden days of computing'. – jon May 14 '13 at 2:49
  • Attempting at error recovery is usual in software. – egreg May 14 '13 at 7:40
  • @egreg I can agree to that to a point, but TeX seems to be the type of software where things are expected to be exact and as the user intended -- much like the philosophy of C -- "only requiring that [we] state [our] intentions explicitly." It's obvious that error recovery is being attempted here, however, so there must be some realization (success) of this purpose somewhere. – Sean Allred May 14 '13 at 21:09
  • The answer linked above is basically the answer to this question. See also The TeXbook chapter 6 (“Running TeX”), especially page 31 onwards, which show what an interactive session with TeX would be like, and also the last chapter (Chapter 27, “Recovery from Errors”). The very first page of this last chapter is illustrative; the chapter also gets to “Missing $ inserted” and the like. – ShreevatsaR Feb 7 '18 at 21:33
9

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.

  • You also have to consider the computers TeX was written for: Program runs could take hours and had to arranged well in advance. – Martin Schröder May 14 '13 at 22:40
  • @MartinSchröder That's what I meant when referring to "batch jobs". But probably you're right: many people never heard about this. ;-) – egreg May 14 '13 at 22:42
4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.