# Mimic mathjax behavior on undefined control sequences

I recently posted something on math.stackexchange.com, and was astonished by the behavior of the auto-renderer on undefined sequences. Instead of stopping the compilation right here, it would display in the rendered text the name of the sequence in red, and just carry on processing the rest of the document.

Needless to say, such a feature could prove incredibly useful for some usages of *TeX. One simple example is live-texing lecture notes, where a lot of spelling mistakes are likely to appear, but where one will prefer a successfully-compiled, badly-rendered document to a perfect, but half-compiled document.

The --nonstopmode option of pdflatex already offers some kind of such behavior, but then that's the opposite problem : the document is too well compiled, and the only way to find the errors is to either carefully proof-read the document, or to search through the log file.

Hence the question: is there a way to get latex to replace "Undefined control sequence" errors with simple warnings, and in that case print the name of the faulty macro verbatim (with its arguments, expanded or not) in red (for example)?

Or is it something too deeply buried in the core features of *TeX or mathjax, which would require to build a brand new engine?

• basically the answer to the question at the end is "yes" (unless luatex offers a hook to trap that primitive error message) – David Carlisle Jun 10 '13 at 11:00
• A quick scan through the LuaTeX manual gave me the following idea. The undefineds that you'd be interested in would all be directly from the input token stream so you could interrupt that using the process_input_buffer callback and test for a command token, then look it up and if it isn't there insert an appropriate token list instead. – Loop Space Jun 10 '13 at 11:06
• @AndrewStacey A command might be undefined when the buffer is populated, but get defined as part of the action of another command. Some environments define commands only as part of the \begin action. – egreg Oct 5 '13 at 21:56
• @DavidCarlisle Care to write an answer? – egreg Nov 2 '13 at 22:42