Edit: I have added a luatex solution as an answer to my question.
I have a \vbox
in which I plan to typeset long material (long poetry), the way it is typeset is slightly unique. There is a special highlight macro that puts 3 red colored asterisks at the end of some special stanzas (which end with \par
). Though if the end of a special stanza (each stanza can be different number of lines) falls at a multiple of some number (lets say 100) from the top of the poetry then we do something different (like add extra line break, or some other marker like a colored rule) instead of putting these asterisks.
The way I imagine this could work is if I can find, and pass the line number of the last line of previous paragraph to my macro that prints special marker. I have not come across any macro to know the line number within the text about to be typeset. From my fringe understanding of tex, given tex engine puts lines of paragraph on the vertical list at the end of processing a paragraph, it seems like there would be a way to know this at the beginning of next paragraph? Ideally I would like plain tex solution. If that is impossible to achieve in plain tex, then luatex solution based on line-break-filter would be great (assuming from the name it won't re-typeset the entire \vbox
again?)
Corollary-1: I guess in plain tex it is not possible to get line number of the line within the paragraph while the paragraph is being typeset, though is it possible using luatex's line break filter? If it is possible in luatex, then for luatex solution it would be nice to just have a macro that works on any line, not just to know the line number of the last line of previous paragraph.
% Macro that returns line number from top of vbox
\currentlineno
% Macro that consumes this line number
\myspecialasterisk{\currentlineno} % I can write this, am looking for the definition of \currentlineno
\obeylines
and a line counter. – Donald Arseneau Apr 14 '20 at 7:44\lastbox
or\vsplit
and choose content from each list based on the line count then. – Donald Arseneau Apr 14 '20 at 7:47\obeylines
fail? Like what content in\vbox
would mess up the count? Also in this example yes typesetting twice would not be performance issue, though I would prefer a generic solution as I think knowledge of line number can help in doing things dynamically. – reportaman Apr 14 '20 at 7:48