# Syncing text on bilingual pages

This is quite a technically involved question. Of which the essence is how XeLaTeX handles page-breaking.

I need to produce a bilingual book. With one language on the left hand side page and another language covering the same text on the right hand side page.

There are a few points to bear in mind:

• The book being produced is the Holy Bible, so it is a very large text, therefore as much of the work as possible should be automated..
• It needs to end the same verse for both languages for every set of pages.
• All the packages included in the MWE below are actually used by other features in the final product.

So bearing this all in mind, the question is; Does XeLaTeX have the ability to find out how much of my text have been used on the page. Or which is the last Section / Subsection used on the page. So that it can be used for the second language to produce the same content on that page.

MWE:

\documentclass[pagesize=pdftex, fontsize=12]{scrbook}
\usepackage[paperwidth=11.2cm, paperheight=17.4cm, top=2cm,bottom=1cm, left=1cm, right=1cm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lettrine}
\usepackage{xltxtra}
\usepackage{tocloft}
\usepackage{etoolbox}
\usepackage[toc]{multitoc}
\usepackage{setspace}
\usepackage{needspace}
\usepackage{calc}
\usepackage{fix2col} %fixes numbering of the sections in the header for two columns

\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Times New Roman}

\usepackage{polyglossia}
\setmainlanguage{spanish}

\newcommand{\Sectionnumber}{%
\sbox\Sectionbox{\smash{\raisebox{-\baselineskip}{%
\fontsize{2.2\baselineskip}{0}\selectfont\theSection}}\enspace}}

\newcounter{Section}
\newcounter{Subsection}[Section]
\newlength{\Sectionwidth}
\newif\ifFirstSubsection
\newsavebox{\Sectionbox}

\makeatletter
\newcommand{\Section}{%
\par\vskip\z@ \@plus 2\p@
\FirstSubsectiontrue\clubpenalty\@M
\refstepcounter{Section}\stepcounter{Subsection}%
\Sectionnumber\setlength{\Sectionwidth}{\wd\Sectionbox}%
\hangindent\Sectionwidth\hangafter-2
\leavevmode\llap{\box\Sectionbox}\ignorespaces}
\newcommand{\Subsection}{%
\par\clubpenalty\@clubpenalty
\ifFirstSubsection
\ifnum\prevgraf=\@ne\nobreak\hspace*{\Sectionwidth}\fi
\FirstSubsectionfalse
\fi
\refstepcounter{Subsection}\textbf{\theSubsection}\enspace\ignorespaces}
\makeatother

\parindent=0pt
\parskip=0pt

\begin{document}
\frontmatter

\mainmatter

\setcounter{section}{0}

\Section EN el principio crió Dios los cielos y la tierra.
\Subsection Y la tierra estaba desordenada y vacía, y las tinieblas estaban sobre la haz del abismo, y el Espíritu de Dios se movía sobre la haz de las aguas.
\Subsection Y dijo Dios: Sea la luz: y fué la luz.
\Subsection Y vió Dios que la luz era buena: y apartó Dios la luz de las tinieblas.

\Section Y FUERON acabados los cielos y la tierra, y todo su ornamento.
\Subsection Y acabó Dios en el día séptimo su obra que hizo, y reposó el día séptimo de toda su obra que había hecho.
\Subsection Y bendijo Dios al día séptimo, y santificólo, porque en él reposó de toda su obra que había Dios criado y hecho.

\Section EN el principio crió Dios los cielos y la tierra.
\Subsection Y la tierra estaba desordenada y vacía, y las tinieblas estaban sobre la haz del abismo, y el Espíritu de Dios se movía sobre la haz de las aguas.
\Subsection Y dijo Dios: Sea la luz: y fué la luz.
\Subsection Y vió Dios que la luz era buena: y apartó Dios la luz de las tinieblas.

\Section Y FUERON acabados los cielos y la tierra, y todo su ornamento.
\clearpage

\setcounter{Section}{0}
\Section In the beginning God created the heaven and the earth.
\Subsection And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.
\Subsection And God said, Let there be light: and there was light.
\Subsection And God saw the light, that it was good: and God divided the light from the darkness.

\Section Thus the heavens and the earth were finished, and all the host of them.
\Subsection And on the seventh day God ended his work which he had made; and he rested on the seventh day from all his work which he had made.
\Subsection And God blessed the seventh day, and sanctified it: because that in it he had rested from all his work which God created and made.

\Section In the beginning God created the heaven and the earth.
\Subsection And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.
\Subsection And God said, Let there be light: and there was light.
\Subsection And God saw the light, that it was good: and God divided the light from the darkness.

\Section Thus the heavens and the earth were finished, and all the host of them.
\clearpage
\end{document}

• Do you know the parallel package? Dec 10, 2012 at 13:49
• A bit off-topic, but are you sure you want Times New Roman? For me, it sounds almost like a blasphemy; the Holy Bible does deserve a beautiful font, not one of the ugliest ones... Dec 10, 2012 at 17:53
• ledpar is another good option, though it is geared more towards critical editions with facing page translations.
– jon
Dec 10, 2012 at 20:02
• @McGafter -- oh, right! I forgot about newer eledpar! You should probably consult the ledpar and ledmac manuals for basic set-up stuff. But I haven't had occasion to use newer versions yet. If the existing answer does what you need, I won't bother providing an eledpar example. But note that you should use pdfcolparallel in place of the parallel package, as the former fixes bugs of the latter and provides colour support (which may not be necessary in your case). As for your fonts, you could use (IMHO) a freer and yet nicer font, like Linux Libertine, or the TeX-Gyre fonts.
– jon
Dec 11, 2012 at 17:12
• @McGafter -- I posted an example. There seem to be a few problems with the current versions of eled*, but I think there are workarounds for now.
– jon
Dec 12, 2012 at 16:40

Ok, it turns out there are a few problems with the versions of eledpar and eledmac, which I just downloaded from CTAN. The first is that there is a serious bug if you use the memoir class, which I didn't have time to look into. Update: This has been addressed on eledmac's github page, but it has not made it to CTAN yet.

That said, however, an eledpar way of going about this:

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}%
\usepackage[T1]{fontenc}%
\usepackage[fulloldstylenums,largesmallcaps]{kpfonts}%

\usepackage{eledmac, eledpar,lipsum}

\numberlinefalse% turn off lineation commands (from eledmac)

\usepackage[spanish,english]{babel}

% It seems easier to have 'parallel' Spanish and English sectioning macros
% so that you don't have to worry about one counter for both languages
\newcommand{\SpanSectionnumber}{%
\sbox\Sectionbox{\smash{\raisebox{-\baselineskip}{%
\fontsize{2.2\baselineskip}{0}\selectfont\theSpansection}}\enspace}}
\newcommand{\EngSectionnumber}{%
\sbox\Sectionbox{\smash{\raisebox{-\baselineskip}{%
\fontsize{2.2\baselineskip}{0}\selectfont\theEngsection}}\enspace}}

\newcounter{Spansection}
\newcounter{Spansubsection}[Spansection]
\setcounter{Spansection}{0}
\newcounter{Engsection}
\newcounter{Engsubsection}[Engsection]
\setcounter{Engsection}{0}
\newlength{\Sectionwidth}
\newif\ifFirstSubsection
\newsavebox{\Sectionbox}

\makeatletter
\newcommand{\Spansection}{%
\par\vskip\z@ \@plus 2\p@
\FirstSubsectiontrue\clubpenalty\@M
\refstepcounter{Spansection}\stepcounter{Spansubsection}%
\SpanSectionnumber\setlength{\Sectionwidth}{\wd\Sectionbox}%
\hangindent\Sectionwidth\hangafter-2
\leavevmode\llap{\box\Sectionbox}\ignorespaces}
\newcommand{\Spansubsection}{%
\par\clubpenalty\@clubpenalty
\ifFirstSubsection
\ifnum\prevgraf=\@ne\nobreak\hspace*{\Sectionwidth}\fi
\FirstSubsectionfalse
\fi
\refstepcounter{Spansubsection}\textbf{\theSpansubsection}\enspace\ignorespaces}

\newcommand{\Engsection}{%
\par\vskip\z@ \@plus 2\p@
\FirstSubsectiontrue\clubpenalty\@M
\refstepcounter{Engsection}\stepcounter{Engsubsection}%
\EngSectionnumber\setlength{\Sectionwidth}{\wd\Sectionbox}%
\hangindent\Sectionwidth\hangafter-2
\leavevmode\llap{\box\Sectionbox}\ignorespaces}
\newcommand{\Engsubsection}{%
\par\clubpenalty\@clubpenalty
\ifFirstSubsection
\ifnum\prevgraf=\@ne\nobreak\hspace*{\Sectionwidth}\fi
\FirstSubsectionfalse
\fi
\refstepcounter{Engsubsection}\textbf{\theEngsubsection}\enspace\ignorespaces}
\makeatother

\parindent=0pt
\parskip=0pt

%%% The following are defined only for convenience:
\newcommand{\spanishchunk}{%
\selectlanguage{spanish}
\Spansection EN el principio crió Dios los cielos y la tierra.
\Spansubsection Y la tierra estaba desordenada y vacía, y las tinieblas estaban sobre la haz del abismo, y el Espíritu de Dios se movía sobre la haz de las aguas.
\Spansubsection Y dijo Dios: Sea la luz: y fué la luz.
\Spansubsection Y vió Dios que la luz era buena: y apartó Dios la luz de las tinieblas.

\Spansection Y FUERON acabados los cielos y la tierra, y todo su ornamento.
\Spansubsection Y acabó Dios en el día séptimo su obra que hizo, y reposó el día séptimo de toda su obra que había hecho.
\Spansubsection Y bendijo Dios al día séptimo, y santificólo, porque en él reposó de toda su obra que había Dios criado y hecho.

\Spansection EN el principio crió Dios los cielos y la tierra.
\Spansubsection Y la tierra estaba desordenada y vacía, y las tinieblas estaban sobre la haz del abismo, y el Espíritu de Dios se movía sobre la haz de las aguas.
\Spansubsection Y dijo Dios: Sea la luz: y fué la luz.
\Spansubsection Y vió Dios que la luz era buena: y apartó Dios la luz de las tinieblas.

\Spansection Y FUERON acabados los cielos y la tierra, y todo su ornamento.
}

\newcommand{\englishchunk}{%
\selectlanguage{english}
\Engsection In the beginning God created the heaven and the earth.
\Engsubsection And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.
\Engsubsection And God said, Let there be light: and there was light.
\Engsubsection And God saw the light, that it was good: and God divided the light from the darkness.

\Engsection Thus the heavens and the earth were finished, and all the host of them.
\Engsubsection And on the seventh day God ended his work which he had made; and he rested on the seventh day from all his work which he had made.
\Engsubsection And God blessed the seventh day, and sanctified it: because that in it he had rested from all his work which God created and made.

\Engsection In the beginning God created the heaven and the earth.
\Engsubsection And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.
\Engsubsection And God said, Let there be light: and there was light.
\Engsubsection And God saw the light, that it was good: and God divided the light from the darkness.

\Engsection Thus the heavens and the earth were finished, and all the host of them.
}

\begin{document}

\begin{pages}

\begin{Leftside}
\beginnumbering\pstart
\spanishchunk\par\spanishchunk\par\spanishchunk
\pend\endnumbering
\end{Leftside}

\begin{Rightside}
\beginnumbering\pstart
\englishchunk\par\englishchunk\par\englishchunk
\pend\endnumbering
\end{Rightside}

\Pages

\begin{Leftside}% it might be better to create new environments for these
\beginnumbering\pstart
\spanishchunk\par\spanishchunk\par\spanishchunk
\pend\endnumbering
\end{Leftside}

\begin{Rightside}% it might be better to create new environments for these
\beginnumbering\pstart
\englishchunk\par\englishchunk\par\englishchunk
\pend\endnumbering
\end{Rightside}

\Pages
\end{pages}

\end{document}


It may be wiser to create your own Spanish and English environments for each chunk of text, but I left them as is to illustrate the mandatory parts of each 'side'. If you prefer parallel columns, then change

\begin{pages}
...
\Pages
\end{pages}


to:

\begin{pairs}
...
\Columns
\end{pairs}

• I noticed that reledpar is now the replacement for the eledpar package. Nov 21, 2020 at 6:44

Although Stephan Lehmke has already suggested the parallel package, I thought I might add to that comment. I have used the parallel package for bilingual course descriptions. It works very well and provides me with an excellent way to provide domestic and foreign students with identical information. From what i have read and experienced the package has some drawbacks. The most disturbing is that the list environments may totally mess up things. I found that I could mock up list environments using the hanging package. It does not seem that you will need lists very much in your case but be aware that the parallel package is not perfect in that sense and that you may need to find alternative solutions to some typesetting features provided by LaTeX in general. Another detail is that paragraphs are indented so you need to add a \noindent for the first paragraph if that is what you need. Here is an MWE:

\documentclass{article}
\usepackage{parallel,hanging}

\begin{document}

\begin{Parallel}[v]{.47\textwidth}{.47\textwidth}
\ParallelLText{\noindent Some introductory text in language 1, not to be indented

\begin{hangparas}{4mm}{1}
--- Some text in language 1

--- Some more text in language 1

\end{hangparas}

}
\ParallelRText{\noindent Some introductory text in language 2, not to be indented

\begin{hangparas}{4mm}{1}
--- some text in language 2

--- some more text in language 2
\end{hangparas}

}
\end{Parallel}

\end{document}