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.



1 Answer 1


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.").

  • 2
    You can't use \setcounter here: you need to use the plain TeX \errrocontextlines 999\relax.
    – Joseph Wright
    Nov 2, 2010 at 15:09
  • 8
    Actually you can use \setcounter: latex.ltx contains the line \let\c@errorcontextlines\errorcontextlines Nov 2, 2010 at 15:32
  • Now this I did not know: I always stick with the plain TeX approach to \errorcontextlines (as it's a primitive in any case)
    – Joseph Wright
    Nov 2, 2010 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .