# A “stacktrace” for errors

Is it possible to get some kind of "stacktrace" in TeX errors? I sometimes get errors which only show some deep LaTeX internals, but nothing about which LaTeX macro referenced it.

Thanks,

-

While "stacktracing" might not be possible since the state of macro expansion can be indeterminate (a priori and a posteriori). However, widening the context of your error reporting might provide some sense of where you are and what's going on. Try something like \setcounter{errorcontextlines}{999} for this. For myself, liberally sprinkling my code with lots of \typeout's or PackageWarning (et al.) lines provides most of what I need (write a routine that switches these on and off according to a global flag you set). Of course, many packages accept a debug or verbose option that dumps lots more state info to the .log file. Otherwise, the big gun is the trace package to give good control over \tracingall. The manual provided with it contains some worked examples and useful words of advice. Other words of wisdom can be found here (contains such pearls as: "The best advice to those faced with TeX errors is not to panic.").
You can't use \setcounter here: you need to use the plain TeX \errrocontextlines 999\relax. –  Joseph Wright Nov 2 '10 at 15:09