First of all, full disclosure: this is my first question on this site, so apologizes in advance.
The Problem: I would like to have a Latex command that accepts two documents and presents them in the following way. The two pieces of text should proceed side by side (in a two-column fashion) and then switch to one column again for whichever of the two comes out to be longer. Note that the two texts can be quite long and indeed span multiple pages. I have access to the two input documents, but I would like to modify them as little as possible, ideally the solution should not alter them at all.
Incredibly realistic sketch of the solution.
+-----------------+
| Shared Title |
+--------+--------+
| | |
| | |
| Left | Right |
| Text | Text |
| | |
| | |
| | |
+--------+--------+
~pagebreak~
+--------+--------+
| Left | Right |
| Text | Text |
| +--------|
| |
| Trailing End |
| of Left Text |
+--------+--------+
What I got so far: Thanks to questions such as this one I was able to position the two texts side by side with the following code.
\newcommand{\sidebyside}[2]
{
\begin{paracol}{2}
\begin{tcolorbox}[blanker, breakable, width=\linewidth]
#1
\end{tcolorbox}
\switchcolumn
\begin{tcolorbox}[blanker, breakable, width=\linewidth]
#2
\end{tcolorbox}
\end{paracol}
}
That I can later use in the document with a call such as:
\sidebyside{\input{left_text}}{\input{right_text}}
However with this setup whichever text comes up the longer will just keep going in its own column, while I would like it to break the two-column layout and proceed using the whole page. The idea I had was to modify the previous command to only print part of one of the two inputs to match its length to the shortest, like the following:
\newcommand{\sidebyside}[2]
{
% Somehow measure which of #1 and #2 is longer
\begin{paracol}{2}
\begin{tcolorbox}[blanker, breakable, width=\linewidth]
% Part of #1 with length matched to #2
\end{tcolorbox}
\switchcolumn
\begin{tcolorbox}[blanker, breakable, width=\linewidth]
% Part of #2 with length matched to #1
\end{tcolorbox}
\end{paracol}
% Put here the remaining trail of either #1 and #2
}
The main sub-problems that I am facing are: "How to measure which of the two inputs is longer?", "How to print only part of and input given its target length?".
The approach I depicted above may be doomed to fail, so I am open to any solution. I am using Overleaf as part of online collaboration.