4

The parallel package is able to set parallel columns and align them at \ParallelPar tokens:

\documentclass{article}

\usepackage{parallel}

\usepackage{mwe}

\begin{document}
\begin{Parallel}[c]{.45\textwidth}{.45\textwidth}
  \ParallelLText{\lipsum[1]}
  \ParallelRText{\lipsum[3]}
  \ParallelPar

  \ParallelLText{\lipsum[2]}
  \ParallelRText{\lipsum[4]}
  \ParallelPar

  \ParallelLText{\lipsum[5]}
  \ParallelRText{\lipsum[7]}
\end{Parallel}
\end{document}

When you change the c (column) option to p (page) however, the alignment is lost. How can I get the behavior I need?

I am not tied to any particular input format, although I am reading in the translations in this format.

Solution Idea

\tikzmark comes to mind, but I've never used it and I'm not sure it's applicable. The core problem here is that, at the start of every paragraph, we need to record the vertical position we are at on the page and save it in some queue. Say we are typesetting the original text (foreign) on the verso (left hand page of the spread) and the translation on the recto. Every paragraph to be set on the verso and recto should be saved in a box. (I'm assuming that we won't have more than n paragraphs :). n is small.; I know there are a limited number of box registers.) The depth of each box should be set to the maximum of the original and the translation. This depth is then enqueued. Boxes continue to be set on the verso in this way until we can't fit the paragraph on the page. At this point, the boxes destined for recto are placed according the queue of depths. (Perhaps this queue isn't necessary if we set the depths of the boxes manually, but I'm not sure if this would distort the text a la graphicx.)

Potential Algorithm

If this isn't supported by the parallel package, I've come up with an algorithm that should work—I am just uncomfortable implementing it; I've never worked across pages before.

  1. Read text blocks to be aligned into boxes: \l_original_box and \l_translation_box.
  2. Set the depth of each box to the maximum between them.
  3. Does \l_original_box fit on this page?
    • Yes
      1. Typeset \l_original_box.
      2. Place \l_translation_box into a queue (a seq).
    • No
      1. Start a new page.
      2. Empty queue (of translations) onto the page. (Assuming identical page dimensions, this should fit on the page since the depths are identical to the originals.)
  4. Loop until EOF. (See linked.)

EDIT: As I'm going through with trying to solve this using the above algorithm (Work In-Progress), I've noticed that care has to be taken for long lines. In the verse environment, long lines are indented. (Is there anything like a parbox for expl3?)

Sean Allred
  • 27,421
  • Could you elaborate on what c vs. p are supposed to mean? Is your output supposed to remain on one page? I am not familiar with this package. – Steven B. Segletes Apr 22 '14 at 15:07
  • 1
    @StevenB.Segletes The parallel is meant for parallel texts (e.g. translations) set side-by-side. The c option sets them in columns on the same page, whereas the p option sets them on separate pages. Unfortunately, \ParallelPar seems to just be \newpage when the p option is in effect. The output is to appear to operate on the entire spread. – Sean Allred Apr 22 '14 at 15:10
  • Related: http://tex.stackexchange.com/questions/130907/how-do-i-create-6-parallel-texts-aligned-by-paragraph-with-3-texts-on-each-page/131394#131394 – Steven B. Segletes Apr 22 '14 at 15:12

1 Answers1

4

As suggested in my comment, I adapted the answer at How do I create 6 parallel texts aligned by paragraph, with 3 texts on each page?. Here, I made it for two columns instead of six, and removed the foreign language support. I left lines in the table, since I figure it is easier to see where to remove them, than as to where one must add them. The column width is defined by the length \colwidth, currently set to 0.9\textwidth.

I also just placed simple lipsum in the boxes, as per your MWE, though the approach supports column \centering and the quote environment. Column entries will not break in the middle, but will be completely contained on a single page. The blank lines apparent at the bottom of each entry are an artifact of \lipsum, which includes, by default, a new paragraph at the end.

\documentclass[]{article}
\usepackage{ifthen}
\usepackage{calc}
\usepackage{lipsum}

\makeatletter
\newcounter{tabindex}
\newtoks\@tabtoks
\newcommand\addtabtoks[1]{%
  \@tabtoks\expandafter{\the\@tabtoks\stepcounter{tabindex}#1}}
\newcommand*\resettabtoks{\@tabtoks{}}
\newcommand*\synctabindex[1]{\setcounter{tabindex}{\value{#1}}}
\newcommand*\printtabtoks{\the\@tabtoks}
\makeatother

\def\colwidth{.9\textwidth}
\newcounter{sptstartrow}
\newcounter{sptendrow}
\newcounter{entries}
\newcounter{pagerows}
\newlength\CurrentTableHeight
\newlength\CurrentRowHeight
\newsavebox\pagerow

\newcommand\newspecialtable{%
  \setcounter{sptendrow}{0}%
  \setcounter{entries}{0}%
  \setcounter{pagerows}{0}%
  \setlength\CurrentTableHeight{0pt}%
}

\makeatletter
\newcommand\twoby[2]{%
  \stepcounter{entries}%
  \expandafter\def\csname entryX\roman{entries}Xa\endcsname{#1}%
  \expandafter\def\csname entryX\roman{entries}Xf\endcsname{#2}%
  \synctabindex{entries}%
  \sbox{\pagerow}{\formatcol{a}\formatcol{f}}%
  \setlength\CurrentRowHeight{\ht\pagerow+\dp\pagerow}%
  \addtolength\CurrentTableHeight{\CurrentRowHeight}%
  \ifdim\CurrentTableHeight>\textheight %
    \makespecialtable[\thepagerows]%
    \setcounter{pagerows}{0}%
    \setlength\CurrentTableHeight{\CurrentRowHeight}%
    \else\fi%
  \stepcounter{pagerows}%
}
\makeatother
\newcounter{index}
\newcommand\makespecialtable[1][\theentries]{%
  \setcounter{sptstartrow}{\thesptendrow}%
  \addtocounter{sptendrow}{#1}%
  \ifthenelse{\thesptendrow > \theentries}{\setcounter{sptendrow}{\theentries}}{}%
  \clearpage
  \setcounter{index}{\thesptstartrow}%
  \synctabindex{index}
  \resettabtoks%
  \whiledo{\theindex < \thesptendrow}{%
    \stepcounter{index}%
    \addtabtoks{%
      \csname entryX\roman{tabindex}Xa\endcsname &
      \vphantom{\formatcol{f}}
      \\%
      \hline%
    }%
  }%
  \begin{tabular}{|p{\colwidth}|@{\extracolsep{-\tabcolsep}}l}%
   \hline%
   \printtabtoks%
  \end{tabular}%
  \clearpage
  \setcounter{index}{\thesptstartrow}%
  \synctabindex{index}
  \resettabtoks%
  \whiledo{\theindex < \thesptendrow}{%
    \stepcounter{index}%
    \addtabtoks{%
      \csname entryX\roman{tabindex}Xf\endcsname &
      \vphantom{\formatcol{a}}
      \\%
      \hline%
    }%
  }%
  \begin{tabular}{|p{\colwidth}|@{\extracolsep{-\tabcolsep}}l}%
   \hline%
   \printtabtoks%
  \end{tabular}%
}

\newcommand\formatcol[1]{%
   \parbox[t]{\colwidth}{\csname entryX\roman{tabindex}X#1\endcsname\strut}%
}

\newcommand\finishspecialtable{\makespecialtable}

\begin{document}
\centering
\newspecialtable
\twoby
  {\lipsum[1]}%
  {\lipsum[3]}%
\twoby
  {\lipsum[2]}%
  {\lipsum[4]}
\twoby
  {\lipsum[5]}%
  {\lipsum[7]}
\twoby
  {\lipsum[1-2]}%
  {\lipsum[3]}%
\twoby
  {\lipsum[2]}%
  {\lipsum[5]}

\finishspecialtable
\end{document}

enter image description here

enter image description here