1

Before you read on: This question refers to plain TeX only. Thanks!

I’m wondering how to add line numbers for lines broken off by TeX’s line-breaking mechanism. (My text does not contain any explicit/forced line breaks.)

Really, my question is more general: How can I insert a control sequence token for every line TeX has broken off in a paragraph?

4

To answer your more limited question about line numbers. The venerable EDMAC is usually good at these things.

\input edmac
\hsize=3in
\firstlinenum=1
\linenumincrement=1
\beginnumbering
\pstart
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\pend
\endnumbering
\end

lorem ipsum with line numbers

EDIT: EDMAC sources were very instructive. To answer your expanded question about control sequence token for every line. This is my understanding, please correct if I'm wrong:

Input files are first converted to lists of tokens in TEX’s “mouth,” ... [then] expandable tokens are converted to unexpandable ones in TEX’s “gullet” by a process similar to regurgitation. When unexpandable tokens finally reach TEX’s gastrointestinal tract, the real activity of typesetting begins. - TeXbook page 267

What this means is that unless one wants to process paragraphs into lines oneself (like EDMAC does), it is not possible to have something automatically expanded at each typeset line (except \endlinechar). That is, there is no easy way to do what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.