In any system (I'm open to LaTeX, ConTeXt, plain TeX, OPmac, whatever works), I'd like to typeset four running streams of text—source text, commentary A, commentary B, commentary C—and break them into pages, such that they occur one below the other on a typical page (see image below). The catch is that the texts can greatly vary in length:
- sometimes several pages in source text may not have any commentary, and
- sometimes a single sentence in the source text may have several pages of commentary.
So the main task is that of automatic page-breaking, by tracking the accumulated lengths of the four (or however many) streams, breaking whenever needed, and continuing across pages. Existing LaTeX packages like reledmac are not designed for this use-case, and cannot handle this (example).
I'm tagging this with ConTeXt and OPmac even though I'm open to any system, simply because I think LuaTeX may be helpful here.
Background: For Sanskrit books, it is traditional to typeset a text along with its commentaries, as in the page below. (Some more examples of the desired page layout, found by searching at archive.org for "three commentaries" etc: here, here, here, here)
Here is a MWE of the desired result (with a source text and two commentaries A and B), but with page breaks chosen manually. We would like to achieve the same result without having to manually choose the location of each break.
\documentclass{article}
\usepackage[papersize={4in,4in}, total={3in,3in}]{geometry}
% A "\Repeat" command: https://tex.stackexchange.com/a/16192
\usepackage{expl3}
\ExplSyntaxOn
\cs_new_eq:NN \Repeat \prg_replicate:nn
\ExplSyntaxOff
\begin{document}
\parindent=0pt
\parskip=0.5\baselineskip
% Start: 5 sentences of commentary for each source sentence.
Source text sentence number 1.
Source text sentence number 2.
Source text sentence number 3.
\medskip \hrule
{\footnotesize
\Repeat{5}{Commentary A on sentence 1. }
\Repeat{5}{Commentary A on sentence 2. }
\Repeat{4}{Commentary A on sentence 3. } Commentary A on senten-
}
\medskip \hrule
{\footnotesize
\Repeat{5}{Commentary B on sentence 1. }
\Repeat{5}{Commentary B on sentence 2. }
\Repeat{3}{Commentary B on sentence 3. } Co-
}
\newpage
% Continued. Long lengths:
% 10 lines of commentary each on sentence 4.
% 15 lines of commentary each on sentence 5 (partly fits here).
Source text sentence 4.
Source text sentence 5.
S-
\medskip \hrule
{\footnotesize
ce 3.
\Repeat{10}{Commentary A on sentence 4. }
\Repeat{4}{Commentary A on sentence 5. } Commentary
}
\medskip \hrule
{\footnotesize
mmentary B on sentence 3. Commentary B on sentence 3.
\Repeat{10}{Commentary B on sentence 4. }
\Repeat{3}{Commentary B on sentence 5. } Co-
}
\newpage
% Continued: note only commentary on this page.
\hrule
{\footnotesize
A on sentence 5. \Repeat{15}{Commentary A on sentence 5. }
}
\medskip \hrule
{\footnotesize
mmentary B on sentence 5. \Repeat{12}{Commentary B on sentence 5. } Commen-
}
\newpage
% Continued: source text continues.
% Sentences 6 to 10 have no commentary.
ource text sentence 6.
Source text sentence 7.
Source text sentence 8.
Source text sentence 9.
Source text sentence 10.
\medskip \hrule
\medskip \hrule
{\footnotesize
tary B on sentence 5. \Repeat{3}{Commentary B on sentence 5. }
}
\end{document}
Result:
Attempt with bigfoot: sort of works, but text runs off the bottom of the page and is lost.
\documentclass{article}
\usepackage[papersize={4in,4in}, total={3in,3in}]{geometry}
\usepackage{lipsum}
\usepackage{bigfoot}
\DeclareNewFootnote[para]{A}
\DeclareNewFootnote[para]{B}[alph]
\begin{document}
% Several paragraphs of commentary that occur before the first word of the text.
\footnoteA{\lipsum[1-4]}
firstword\footnoteA{\lipsum[5-8]}
secondword\footnoteA{\lipsum[9-12]} (1)\footnoteB{a few words}
thirdword\footnoteA{\lipsum[13]}
fourthword\footnoteA{\lipsum[14-16]} (2)
\end{document}
First few pages of result:
(Note the wasted space on page 3, and the overflow/truncation on page 4.)
I imagine an algorithm something like the following would work:
- Given a source text S, and commentaries C1, C2, C3 (where "3" stands for an arbitrary small number), which are divided into matching "units" of the form (s, c1, c2, c3).
- Maintain (vertical) lists lines[S], lines[C1], lines[C2], lines[C3], each initially empty.
- For each unit (s, c1, c2, c3),
- Typeset (i.e. break into lines) each of these, and append the lines to lines[S], lines[C1], lines[C2], lines[C3] respectively.
- If the total current height of lines[S] + lines[C1] + lines[C2] + lines[C3] is still less than the page height, continue.
- Otherwise, fill the current page with some appropriate fraction of these four lines, and repeat until the total height becomes less than a page's height.
- Finally, flush the remaining contents of the four lists.








\inserts/modified footnotes. I don't think that LuaTeX would be particularly helpful here, although it may make one or two things easier. – Max Chernoff Nov 13 '22 at 23:32magazinelibrary oftcolorboxpackage has potential (particularly in combination withekdosispackage). I will investigate. – Cicada Nov 16 '22 at 14:10