3

This question is a follow-up to my previous question. In this MWE, the gloss/interlinear and the translation ("non lipsum" text on left) are in separate parboxes and then aligned vertically on the same page. The package ifoddpage keeps the translation on the inside of the page:

enter image description here

MWE for above figure:

\documentclass{book}

\usepackage{microtype}  
\usepackage{expex}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\hebrewfont[Script=Hebrew]{FrankRuehl}
\newfontfamily\englishfont{Times New Roman}

\lingset{
    everygla=\Large,
    everyglb=\scriptsize\englishfont,
    everyglc=\scriptsize\englishfont,
    glwordalign=center,
    glhangindent=0em,
    glrightskip=0pt,
   }

\usepackage{ifoddpage}

\newcommand{\swapboxes}[2]% #1 = wide text, #2 = narrow text
{\noindent\makebox[\textwidth]{\checkoddpage
 \ifoddpageoroneside
   \parbox[t]{.71\textwidth}{#1}\hfill\parbox[t]{.26\textwidth}{#2}%
 \else
   \parbox[t]{.26\textwidth}{#2}\hfill\parbox[t]{.71\textwidth}{#1}%
 \fi}}% this \swapboxes macro forces the parboxes to switch sides every odd page

\begin{document}

\swapboxes{\exdisplay\begingl
  \gla אאאא בבבב גגגג דדדד אא בב גג דד אאאא בב גגגג דדד אאאא בבבבב גג דדדד אא בבבב גגגגג דדד אאאא בבבב גגגג דדדד אא בב גג דד אאאא //

  \glb aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa  //

  \glc aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa //

\endgl \xe}{\exdisplay\footnotesize\textenglish{Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is the end} \xe}

\swapboxes{\exdisplay\begingl
  \gla אאאא בבבב גגגג דדדד אא בב גג דד אאאא בב גגגג דדד אאאא בבבבב גג דדדד אא בבבב גגגגג דדד אאאא בבבב גגגג דדדד אא בב גג דד אאאא //

  \glb aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa  //

  \glc aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa //

\endgl \xe}{\exdisplay\footnotesize\textenglish{Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is the end} \xe}

\swapboxes{\exdisplay\begingl
  \gla אאאא בבבב גגגג דדדד אא בב גג דד אאאא בב גגגג דדד אאאא בבבבב גג דדדד אא בבבב גגגגג דדד אאאא בבבב גגגג דדדד אא בב גג דד אאאא //

  \glb aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa  //

  \glc aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa //

\endgl \xe}{\exdisplay\footnotesize\textenglish{Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is the end} \xe}

\end{document}

Why I need your help:

I want the new output to look more like the figure below, with the gloss/interlinear always on the opposite page as the translation (and full page width for both gloss and translation) and to continue like this for the rest of the document: enter image description here

I am open to both parbox and non-parbox versions. I have looked into reledmac/reledpar, but they don't seem to be compatible with expex. The parallel package could be an option, but I'm not sure it will be very user-friendly for what I want to do, which is to produce many pages text similar to the above example, and, ideally, I don't want to have to tend to the page breaking.


UPDATE: Based on this post, I created the following solution. It does not use parallel. I don't understand it very well, but it seems to work. I have tremendous vertical padding that I would love to get rid of.

MWE:

\documentclass{book}

\usepackage{expex}
\usepackage{polyglossia}
\usepackage{fontenc}
\setdefaultlanguage{english}
\setotherlanguage{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{FrankRuehl}
\newfontfamily\englishfont{Times New Roman}

\lingset{
    everygla=\Large, %some options are normalsize,large, Large, LARGE
    everyglb=\scriptsize\englishfont\it,
    everyglc=\scriptsize\englishfont,
    glwordalign=center,
    glhangindent=0em,
    glrightskip=0pt
}


%here begins the code from https://tex.stackexchange.com/a/172887/121944
\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{\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
  {\exdisplay\footnotesize\textenglish{Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is the end} \xe}%
  {\exdisplay\begingl
  \gla אאאא בבבב גגגג דדדד אא בב גג דד אאאא בב גגגג דדד אאאא בבבבב גג דדדד אא בבבב גגגגג דדד //

  \glb aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd  //

  \glc aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd //

\endgl \xe}%
\twoby
  {\exdisplay\footnotesize\textenglish{Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is the end} \xe}%
  {\exdisplay\begingl
  \gla אאאא בבבב גגגג דדדד אא בב גג דד אאאא בב גגגג דדד אאאא בבבבב גג דדדד אא בבבב גגגגג דדד אאאא בבבב גגגג דדדד אא בב גג דד אאאא אאאא בבבב גגגג דדדד אא בב גג דד אאאא בב גגגג דדד אאאא בבבבב גג דדדד אא בבבב גגגגג דדד אאאא בבבב גגגג דדדד //

  \glb aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd //

  \glc aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd //

\endgl \xe}%
\twoby
  {\exdisplay\footnotesize\textenglish{Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is the end} \xe}%
  {\exdisplay\begingl
  \gla אאאא בבבב גגגג דדדד אא בב גג דד אאאא בב גגגג דדד אאאא בבבבב גג דדדד אא בבבב גגגגג דדד אאאא בבבב גגגג דדדד אא בב גג דד אאאא //

  \glb aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa  //

  \glc aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa //

\endgl \xe}%

\finishspecialtable
\end{document}

Output:

enter image description here

  • Very interesting question. I had to do something like this a while ago and at the time I didn't find any really satisfactory answers (I basically gave up and settled for some compromise with lots of manual work). Will be curious what you find. – ShreevatsaR Nov 9 '17 at 18:28
  • Yes, I saw that thread of yours. I'm still messing around with parallel. From my limited knowledge, I get the feeling that it could be a reasonable solution if I can just learn how to avoid manual page breaks. – AML Nov 9 '17 at 18:35
  • I think now that as we have LuaTeX, it may be possible to automate the page breaks (of course LuaTeX existed in 2011 too but I knew very little about it!). But unfortunately LuaTeX doesn't have support for as many scripts as XeTeX does (and is still not usable for the script I had asked the question in 2011 about)… does LuaTeX work fine for Hebrew in your case? (Not just in the above text which simply contains repeated letters, but try with more complicated ligatures or variant characters or whatever.) – ShreevatsaR Nov 9 '17 at 20:19
  • I need to use XeTeX because of the expex package. – AML Nov 9 '17 at 20:37
2

This is an interesting typesetting problem. I wasn't able to find a solution when I asked the same (or very similar) question in 2011, but I think I have something slightly better now. It requires a bit of work, but that can all be scripted, and it does not require manual page breaking.

The idea is the following:

  • Typeset only the odd (Hebrew) pages, with odd page numbers, and with each Hebrew section being at least the height of the corresponding English section.
  • Typeset only the even (English) pages, with even page numbers, and with each English section being at least the height of the corresponding Hebrew section.
  • Join the resulting PDF files, interleaving pages from the two PDF files.

Here's a pair of facing pages, from the result:

two pages

This is odd.tex:

\newif\ifhebrewpage
\hebrewpagetrue
\input common

and this is even.tex:

\newif\ifhebrewpage
\hebrewpagefalse
\input common

and the bulk of the code is in common.tex:

\documentclass{book}
\usepackage{expex}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{Noto Sans Hebrew}
\newfontfamily\englishfont{Times New Roman}

\lingset{
    everygla=\Large,
    everyglb=\scriptsize\englishfont,
    everyglc=\scriptsize\englishfont,
    glwordalign=center,
    glhangindent=0em,
    glrightskip=0pt,
   }

% Skips page numbers by 2 each time, so that every page is odd or every page is even.
% https://tex.stackexchange.com/a/238887/48
\makeatletter
\let\old@outputpage\@outputpage
\def\@outputpage{\old@outputpage\stepcounter{page}}
\makeatother

% Typeset either English or Hebrew text, with at least as much height as the "other" text
\newsavebox\HebrewBox
\newsavebox\EnglishBox
\newcommand{\parallelPair}[2]
{
  \savebox\HebrewBox[\textwidth]{\parbox[t]{\textwidth}{#1}}
  \savebox\EnglishBox[\textwidth]{\parbox[t]{\textwidth}{#2}}
  \noindent
    \ifhebrewpage
       \usebox\HebrewBox\vphantom{\usebox\EnglishBox}
    \else
       \usebox\EnglishBox\vphantom{\usebox\HebrewBox}
    \fi
}

% Just some test text to avoid repetition; in the real document you'd have sets of \parallelPair{...}{...} and not this \testpair
\newcommand{\testpair}{
  \parallelPair{\exdisplay\begingl
  \gla אאאא בבבב גגגג דדדד אא בב גג דד אאאא בב גגגג דדד אאאא בבבבב גג דדדד אא בבבב גגגגג דדד אאאא בבבב גגגג דדדד אא בב גג דד אאאא //

  \glb aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa  //

  \glc aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa bbb ggg ddd aaaa //

\endgl \xe}{\exdisplay\strut\footnotesize\textenglish{Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is some non lipsum text to fill up this space Here is the end} \xe}
}

\begin{document}
\ifhebrewpage
  \null\newpage % Page 1 will be blank
\else
  \stepcounter{page} % Want even pages
\fi

\testpair

\testpair

\testpair

\testpair

\testpair

\end{document}

To split and join PDFs, I use pdfunite and pdfseparate from poppler utils (you could also use pdftk or possibly even LaTeX itself…):

xelatex odd.tex
xelatex even.tex
pdfseparate odd.pdf "pages_%03d_A.pdf"
pdfseparate even.pdf "pages_%03d_B.pdf"
pdfunite pages_00*.pdf out.pdf

What you see in the image above are two facing pages of out.pdf.

I find this workable, though things are not perfect:

  • The facing paragraphs are not perfectly aligned at their baselines, and I'm not sure why (haven't looked too deeply).
  • What we're insisting is that each parallel pair fit fully on respective pages. This can be a hard page-breaking problem, so you probably want \raggedbottom and you better not have some pair containing text that is taller than will fit on a single page.

(The funny thing is, at core the parallel package seems to be doing something similar, but somehow it doesn't work conveniently.)

  • I don't think this is the solution I'm looking for, as I would prefer to do everything in a single file, but I appreciate the ingenuity. – AML Nov 10 '17 at 12:44
  • @AML Well I imagine it might be possible to do everything from a single file with some macro hacks, but I'm not sure how it would be worth it. You personally need to care only about one file common.tex, and the shell script you use for compiling (or latexmk or arara or whatever you use) can take care of creating odd.tex and even.tex and splitting and joining the PDFs, then deleting those temporary .tex and .pdf (and other) files. It would be a build step that you set up once and can forget about. So it's not so onerous IMO, but yes I'll be interested to see other solutions. :-) – ShreevatsaR Nov 10 '17 at 13:13
  • This post may be relevant. – AML Nov 10 '17 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.