I have a problem that I think would best be solved by an output routine. It seems like an act of moderate TeX wizardry so before I get stuck in the weeds on a wrong approach I thought I would describe the problem and see if anyone endorses it or suggests something else. I'm just as happy to receive some pointers towards the solution that I can work out myself as the complete solution.
Note I'm using Plain TeX here, partly because I want to learn the advanced wizardry. I'm not especially interested in a LaTeX solution.
I am typesetting a collection of poetry in translation. I want to keep the origin with the translation so my input should be shaped roughly like this:
<Poem #1 English>
<Poem #1 Spanish>
<Poem #2 English>
<Poem #2 Spanish>
I want the English on the left page and the Spanish on the right page. I would like to mark up the poem in one language and then the other. So in short, there are two ways TeX can help me:
If the poem is very long, the first page of both languages should be facing each other on the first two pages, then the second page. in both languages on the third and fourth page, etc. I don't want to have to "eyeball it" and cut the poem into chunks myself.
If the poem is very short (i.e. less than 1/2 the page) I'd like two poems on both sides, like this:
<short English A> | <short Spanish A> | <short English B> | <short Spanish B> p.2 p.3
I'm happy to add whatever is necessary to my macros and input to make this happen, I just don't want to manually do the reordering.
This sounds like a job for the OTR to me. I'm trying to see how to approach this problem.
My first thought is to avoid insertions and just do it by triggering the page builder and using marks. I'd leave a mark when I set the language of the poem; if topmark is English and the page is even, ship it. This leads me to this:
\newbox\EnglishBox
\newbox\SpanishBox
\def\alternatingoutput{%
% If we just read some English, stick it in the English box
\if E\firstmark\setbox\EnglishBox\vbox{\unvbox\EnglishBox \unvbox255}\fi
% If we just read some Spanish, stick it in the Spanish box
\if S\firstmark\setbox\SpanishBox\vbox{\unvbox\SpanishBox \unvbox255}\fi
% If we're on an even page, emit some English; otherwise some Spanish
\ifodd\pageno%
\setbox0\vsplit\SpanishBox to \vsize\shipout\box0\advancepageno
\else%
\setbox0\vsplit\EnglishBox to \vsize\shipout\box0\advancepageno
\fi}
I modified my macros \startpoem
and \startspanishpoem
to make the appropriate mark; I had a mark{}
in \stoppoem
but that only seemed to create situations in which this if structure was not comprehensive.
This doesn't seem to do it at all; I get a lot of underfull
warnings (which I assume are caused by not having stretchable glue / \vfil
on the bottom of the box after I bite it off with \vsplit
).
At this point I think I'm in pretty far over my head. I'm wondering if I should be using insertions instead to produce this effect. Any pointers would be greatly appreciated!
Edit: I've now tried to solve it with insertions, which I think is going somewhat better:
\newinsert\EnglishIns
\newinsert\SpanishIns
\count\EnglishIns=1000 \count\SpanishIns=1000
\skip \EnglishIns=0pt \skip \SpanishIns=0pt
\dimen\EnglishIns=\vsize \dimen\SpanishIns=\vsize
\def\poemoutput{%
\ifodd\pageno%
\setbox0\vsplit\SpanishIns to\vsize%
\else%
\setbox0\vsplit\EnglishIns to\vsize%
\fi
\setbox255\vbox{\box0\box255\vfill}
\plainoutput}
\output={\poemoutput}
This feels more promising, but I see a few problems / questions:
- Is this approach to making an output routine reasonable? I mean, rearranging what's in
box255
and then invoking another output routine. - I seem to be losing formatting on the way out. Is that a side effect of using
\vsplit
or have I just missed some other detail? - What are the right values for
\count\EnglishIns
etc.? My fear is that if I accumulate a lot of material for the wrong language on one page it will wind up in the OTR even though I want to ship out the next language. Is this a real problem? If so, what are the right values, or does it depend on knowing in advance the longest poem?
Thanks!