Reading errors & debugging

When a compile fails, LaTeX prints a cryptic ! … message and a line number l.NN, then stops at a ? prompt. Learning to read that — plus the .log and a few debugging commands — turns “it broke” into “here’s the fix.” This page covers reading errors, the log, and debugging.

How to read errors

Errors have a fixed shape — ! then the message (e.g. ! Undefined control sequence), then l.NN showing the line where TeX stumbled, split at the point it had read to. Important: l.NN is where LaTeX *noticed* the trouble, not necessarily where it is — a missing } can surface lines later, so if that line looks fine, suspect above it. At the ? prompt: Return = try to continue, h = help, x = exit, q = run quietly to the end (collect all errors), r = run without stopping. (In practice latexmk and friends run nonstop, so you usually read errors from the .log afterward.)

  • Undefined control sequence — a typo, or a forgotten \usepackage.
  • Missing $ inserted — a math symbol used outside math mode.
  • File x.sty not found — package not installed (add it with tlmgr).
  • Runaway argument — unbalanced { } (usually a missing }).

Reading the log — .log / texfot

The .log file records the whole run — every error and warning (Overfull/Underfull \hbox, undefined references, font substitutions). Since the log is noisy, texfot trims it to the “interesting” lines (see “texdoc / texfot …”). Even when a build “succeeds,” check the warnings here.

Debugging commands

\show\foo prints the meaning/definition of \foo (and stops at ?); \showthe\textwidth prints the value of a register or length. \typeout{...} (LaTeX) and \message{...} (TeX) print your own messages to the log/terminal — handy printf-style debugging. The heavy artillery, \tracingall, dumps everything TeX does into the log (very verbose; the trace package tidies it). Use it to find where an expansion goes wrong.

latex
\show\section          % \section の定義を表示 / show its meaning
\showthe\textwidth      % 長さの値を表示 / show a length’s value
\typeout{ここまで来た}    % 自分のメッセージ / your own message
\tracingall             % すべてをログへ(非常に冗長)/ trace everything (very verbose)