Re: Counting in TeX

Karl Berry <[email protected]> Sat, 7 Mar 2026 14:56:54 -0700
Newsgroups gmane.comp.tex.texhax
Message-ID <[email protected]>
Hi Walt,

    I would like to keep a running count of the number of lines as TeX
    processes a list of lines.  Can I do this using the \count register?

If you mean input lines, for truly simple documents you could make
^^M active and then
  \def^^M{\space \global\advance\mycount by 1 }

But of course there are many instances where this will break TeX's
processing. Any kind of verbatim mode, just for starters.

There's no low-level hook in classical TeX to do this, on either the
input or the output side. Maybe it could be implemented more feasible in
LuaTeX, since that has so many hooks for different stages of processing.
Good luck! --best, karl.