Let's say we have a lot of text to be typeset contained in a single macro, let's call it
This is some really long text: \blindtext.
And it continues even more: \blindtext.
For simplicity, let's say there is no sectioning/ newpage command in
\myverylongtext, but it can have line-breaking commands, and multiple paragraphs (paragraph-breaking commands?). Also, assume that font size & leading remain constant throughout, though all other LaTeX typesetting commands (\textbf, etc) are allowed within the text & should take effect.
Is it possible to define an efficient* macro that (when encountered) gets the next chunk of text of specified dimension? For example:
% #1 is name of macro (in our case \myverylongtext)
% #2 width of text box
% #3 height of text box in lines
% #4 draftmode: optional boolean argument that, when set, instead of typesetting contents returns the actual height (in lines), and width (in length units) of the chunk. (useful in making dynamic layout decisions)
% returns/typesets a box of shape width * height
New calls to this macro
\getnextchunk should get next chunk of text, as if the text contained in
\myverylongtext reflowed from previous chunk to this chunk.
\myverylongtext can be very long, and there can be numerous such chunks, so efficiency is needed. You cannot typeset remaining portion of
\myverylongtext multiple times. One vision I have of solution for such problem is that a box of size 0 is filled iteratively till it grows to the specified metric: width (in length dimension), height (in lines), and required justification; though I lack understanding of low-level tex/luatex/expl3 to write it myself.
Also, either justification commands like raggedright/raggedleft/full-justified specified in
\myverylongtext should magically take effect, or we can set a restriction that we won't have such commands in the
\myverylongtext & instead pass it as a 4th argument to
\getnextchunk (I think latter is preferable, and would make it either easier and/or cleaner to code/use).
Another way to visualize the problem is imagine that we have multiple rectangular text boxes (of different width and height) that flow into each other sequentially as we encounter them in our document (don't worry about placement of these text boxes, *tex already has multiple elegant solutions for that). Also, we don't know when and how many such text boxes will be encountered in the document upfront. In my opinion, from years of using *tex, solving just this one problem will open tons of possibilities, and make tex unbeatable (against InDesign, etc) in value as a typographic tool for design-oriented layouts. Tools like InDesign, and Affinity Publisher allow linking text boxes that eventually flow into each other as a stream, and is something indispensable for a typographic system that envisions to cater to modern expressive typography, and plurality of designs. That can open up *tex as a typesetter to a much broader typesetting/design community.