I have a general question about the paragraph-forming mechanism, but provide an example of the application (skip down to the general question if you prefer):
I am looking at Skeat's edition of Piers the Plowman (published 1869) and want to automate the book's typesetter's approach to appending line number aids at the end of each line: print every fifth line number at the end of the line (flush right against the right margin), except that when the text comes right up to the right margin (or is even allowed to overflow it slightly), defer inserting the line number until the next available opportunity (as done below). It's not hard to simply correct the labeling by hand, but let's suppose there is no possibility of editing the
.texfile by hand between successive compilations.
The general question is whether there is a way of testing whether a line break has been previously inserted (i.e., an
\hbox has already been added to the current vertical list) in the current paragraph? And of testing whether a break is optimal at a particular word boundary within a paragraph? Could this be done in one compilation pass, or would it take two?
(I see what might be a similar situation at another question, but wonder whether this particular problem is tractable to a more elegant solution).