From reading Knuth's TeX Book (Chapter 14 How TeX Breaks Paragraphs into Lines), I understand that entire paragraphs are read in and then "massaged" by the "line-breaking algorithm" in an optimal way (p 91):
One of typesetting system's chief duties is to take long sequences of words and to break it up into individual lines of the appropriate size. ... TeX chooses breakpoints in an interesting way that considers each paragraph in its entirety; the closing words of a paragraph can actually influence the appearance of the first line.
As a consequence, I assume that it flushes out the lines on-by-one after performing the optimization on a per-paragraph basis. Is it possible to interrupt this flushing of lines and say only output specific lines of the paragraph? I guess, almost similar to the way paragraphs are broken across pages.
For example, by means of defining an environment (say) showlines
that one can use in the following way:
\begin{showlines}[lines=2]
One of typesetting system's chief duties is to take long sequences
of words and to break it up into individual lines of the appropriate size.
\TeX\ chooses breakpoints in an interesting way that considers each paragraph
in its entirety; the closing words of a paragraph can actually influence
the appearance of the first line.
\end{showlines}
And TeX would only output the first two lines of the traditional output (possibly discarding the rest):
Note: Of interest here is to preserve the typesetting after line-breaking optimization has occurred, even in the case of hyphenation, since the tie should be with the shipout of lines. Of course, if there is another method of doing this (for example, possible sub-optimal line-breaking on a line-by-line basis), that would also work.
As a bonus, not just allowing to show the first n
lines as in the example above (via [lines=n]
), but allowing to show any combination of lines from the paragraph using notation like: [lines={1,4-5}]
or [lines={-2}]
for the last two lines.