# Doing an interlinear text

I want to produce a three-line interlinear text with numbers and asterisks in the top line, Greek in the middle, and the vernacular (Portugese) in the bottom. An example is below:

The challenge, as I understand it, is to get TeX macros to produce it as pdf directly in the desired shape. Each word is to be something as a three-story fraction. And those fraction-like words must be joined by inter-word spacing or punctuation(commas, etc), and justified within the space available for each line. I will have to type in the two languages, and that suggests me the use of polyglossia TeX package. And here is my limit. The rest is for you, my helpers.

-
I'm afraid this is very difficult to follow. Please place links properly using the tools in the editor, and make it clear what your question is. – qubyte Feb 23 '12 at 12:59
You are right, that seems to be the translation i did some time ago, when my old mac g3 with the textures program was still working. Now i changed to Mac pro, and need to adapt everything to the Intel mac Book Pro. I cannot afford buying the new Textures, and even if i could, with the G3 damaged and the different processors, I do not think i can make the two machines "talk" to each other. So, How to do it in the Mac pro. As a first guess, i can see we now have polyglossia package. And the words are something like three-store fractions. i am anxious to re-start an proceed the job.... – Joaquim Pedro Feb 23 '12 at 13:18
This seems to be an exact duplicate of tex.stackexchange.com/questions/44050/… – rdhs Feb 23 '12 at 13:19
@Joaquim As Alan Munn said, expex looks like your best bet. But it will be very hard to reproduce your layout exactly. You may want to ask at the Apple SE if it's possible to get your G3's copy of Textures running on your Macbook. – rdhs Feb 23 '12 at 13:35

# Interlinear glosses using ExPeX

As I mentioned in my previous answer, I think that the ExPex package provides good tools for what you would like to do, although the input isn't thought out in the way you describe. The basic idea of automatic glossing in ExPex is that each line of the glosses is entered separately, and the package lines up the pieces in each gloss using white space, with braces to delimit groups.

See below for a solution using a spreadsheet to keep the text and numbers aligned.

Here is an example of your first two verses (thanks Morbusg for typing the first verse!). I've also added some formatting of the verses as \section{} commands using the titlesec package.

% !TEX TS-program = XeLaTeX

\documentclass[11pt]{book}
\usepackage[margin=1in]{geometry}
\usepackage{titlesec}
\usepackage{polyglossia}
\defaultfontfeatures{Ligatures=TeX}
\setmainlanguage{brazil}
\setotherlanguage[variant=ancient]{greek}
\setmainfont{Linux Libertine O}
\usepackage{expex}

\titleformat{\chapter}[display]
{\normalfont\filcenter}
{\LARGE\MakeUppercase{\chaptertitlename} \thechapter}
{1pc}
{\vspace{1pc}%
\LARGE}
\titlespacing{\chapter}
{0pt}{0pt}{10pt}

\titleformat{\section}[leftmargin]
{\normalfont
\vspace{0pt}%
\bfseries\Large\filleft}
{\thesection}{.5em}{}
\titlespacing{\section}
{4pc}{1.5ex plus .1ex minus .2ex}{0pt}

\renewcommand{\thesection}{\arabic{chapter}:\arabic{section}}

\lingset{glhangstyle=none}
\begin{document}
\setcounter{chapter}{1}
\chapter{O sonhou Nabucodonsor}
\section{}
\begingl
\gla 1722--3588 2094 3588 1208 3588 392 * 1797 *
1798 2532 1839 3588 4151--1473 {} 2532 3588 5258--1473 1096--575--1473//

\glb {εν τω} έτει τω δευτέρω της βασιλείας Ναβουχοδονόσορ ενυπνιάσθη Ναβουχοδονόσορ
ενύπνιον και εξέστη το πνεύμα αυτού και ο {ύπνος αυτού} {εγένετο απ 'αυτού}//

\glc No ano {} segundo do reinado {de Nabucodonosor} sonhou Nabucodonsor
{um sonho,} e desconcertou-se o espirito dele, e o {sono dele} {se lhe fugiu.}//
\endgl
\section{}
\begingl
\gla 2532   2036   3588   935   2564   3588   1883.3   2532   3588   3097   2532
3588   5333  2532   3588   *  3588   312   3588   935
3588   1798--1473  2532   2064   2532   2476 1799   3588   935//

\glb  και  είπεν  ο  βασιλεύς  καλέσαι  τονς  επαοιδούς  και  τονς  μάγους  και
τονς  φαρμακούς   και  τονς  Χαλδαίούς   τον   αναγγείλαι   τω   βασιλεί
τα {ενύπνια αυτού}  και  ήλθον  και  έστησαν  ενώπιον  του  βασιλεύς //

\glc  E  mandou   o   rei   chamar   os   encantadores,   e   os  magos,   e
os  {ministradores de poções,}  e  os   Caldeus,   para  anunciar   ao  rei
{as \emph{coisas}} {dos sonhos dele.}   e  vieram  E  {postaram-se}  diante
de  rei//
\endgl

\end{document}


# Using datatool to manage the parallel texts

The biggest problem with all of the solutions posted here is managing the relations between the numbering line, the Greek line, and the translation line. In the solution above, the input text is more readable, but it is difficult to find mistakes in the input. In Yiannis' and Morbusg's solutions, the input is quite tedious, and the text itself is unreadable in the source document. The following is an attempt at a solution to both problems. The idea is to keep the parallel texts in a CSV file and then use the datatool package in conjunction with ExPex to build the text.

Format of the CSV file

The CSV file contains 3 columns: Number, Greek, and Portuguese. Each row therefore constitutes a triple of a number, a Greek word (or words) and its translation. Each verse is delimited by the keyword section (since verses are \sections in the document) in the number column.

Because of the way the input lines are built up, spaces and *'s and empty cells need to be escaped in the CSV file. We do this with the following markup:

space = \space
empty cell = \null
* = \esc{*}


Sample CSV file

Here is the CSV file for the same text as in the example above. This file was created with Open Office, and saved at UTF-8 with TAB as the delimiter. We can't use , as the delimiter, since we need to allow for punctuation in the text.

Chapter2.csv

"Number"    "Greek" "Portuguese"
"section"
"1722--3588"    "{εν\space τω}" "No"
"2094"  "έτει"  "ano"
"3588"  "τω"    "\null"
"1208"  "δευτέρω"   "segundo"
"3588"  "της"   "do"
"392"   "βασιλείας" "reinado"
"\esc{*}"   "Ναβουχοδονόσορ"    "{de\space Nabucodonosor}"
"1797"  "ενυπνιάσθη"    "sonhou"
"\esc{*}"   "Ναβουχοδονόσορ"    "Nabucodonsor"
"1798"  "ενύπνιον"  "{um\space sonho,}"
"2532"  "και"   "e"
"1839"  "εξέστη"    "desconcertou-se"
"3588"  "το"    "o"
"4151--1473"    "πνεύμα"    "espirito"
"\esc{\null}"   "αυτού" "dele,"
"2532"  "και"   "e"
"3588"  "ο" "o"
"5258--1473"    "{ύπνος\space αυτού}"   "{sono\space dele}"
"1096--575--1473"   "{εγένετο\space απ\space 'αυτού}"   "{se\space lhe\space fugiu.}"
"section"
"2532"  "και"   "E"
"2036"  "είπεν" "mandou"
"3588"  "ο" "o"
"935"   "βασιλεύς"  "rei"
"2564"  "καλέσαι"   "chamar"
"3588"  "τονς"  "os"
"1883.3"    "επαοιδούς" "encantadores,"
"2532"  "και"   "e"
"3588"  "τονς"  "os"
"3097"  "μάγους"    "magos,"
"2532"  "και"   "e"
"3588"  "τονς"  "os"
"5333"  "φαρμακούς" "{ministradores\space de\space poções,}"
"2532"  "και"   "e"
"3588"  "τονς"  "os"
"\esc{*}"   "Χαλδαίούς" "Caldeus,"
"3588"  "τον"   "para"
"312"   "αναγγείλαι"    "anunciar"
"3588"  "τω"    "ao"
"935"   "βασιλεί"   "rei"
"3588"  "τα"    "{as\space \emph{coisas}}"
"1798--1473"    "{ενύπνια\space αυτού}" "{dos\space sonhos\space dele.}"
"2532"  "και"   "e"
"2064"  "ήλθον" "vieram"
"2532"  "και"   "E"
"2476"  "έστησαν"   "{postaram-se}"
"1799"  "ενώπιον"   "diante"
"3588"  "του"   "de"
"935"   "βασιλεύς"  "rei."


Document Code

Here is the document that reads the CSV file and generates the output:

% !TEX TS-program = XeLaTeX

\documentclass[11pt]{book}
\usepackage[margin=1in]{geometry}
\usepackage{titlesec}
\usepackage{polyglossia}
\defaultfontfeatures{Ligatures=TeX}
\setmainlanguage{brazil}
\setotherlanguage[variant=ancient]{greek}
\setmainfont{Linux Libertine O}
\usepackage{datatool}
\usepackage{expex}

% Format chapter and verse (\section) headings
\titleformat{\chapter}[display]
{\normalfont\filcenter}
{\LARGE\MakeUppercase{\chaptertitlename} \thechapter}
{1pc}
{\vspace{1pc}%
\LARGE}
\titlespacing{\chapter}
{0pt}{0pt}{10pt}

\titleformat{\section}[leftmargin]
{\normalfont
\vspace{0pt}%
\bfseries\Large\filleft}
{\thesection}{.5em}{}
\titlespacing{\section}
{4pc}{1.5ex plus .1ex minus .2ex}{0pt}

% format section label
\renewcommand{\thesection}{\arabic{chapter}:\arabic{section}}

% multiple gloss lines will align on the left margin
\lingset{glhangstyle=none}

% initialize some token registers to build up the lines from the database cells
\newtoks\glosslineA
\newtoks\glosslineB
\newtoks\glosslineC

% create a command to append a cell to the token register
% Thanks to Enrico Gregorio for this code
\long\def\Append#1#2{#1=\expandafter{%
\the\expandafter\expandafter\expandafter#1\expandafter\space #2}}

% Define a command to empty the token registers
\def\emptytoks{\glosslineA{}\glosslineB{}\glosslineC{}}

% Define a command used to escape * in the input cell
\def\esc#1{#1} %
\def\SecTest{section} % verse delimiter check

\begin{document}
\DTLsetseparator{   }% literal tab; with UTF8 source, \DTLsettabseparator doesn't work
\DTLloaddb{text}{Chapter2.csv}
\setcounter{chapter}{1}
\chapter{O sonhou do Nabucodonsor}
\DTLforeach{text}
{% assign each cell in a row to a macro
\Codes=Number,
\GreekText=Greek,
\PortugueseText=Portuguese%
}
{% If we're in the first row, start a section; otherwise if we find a section, output
%  the previous section's lines, and start a new section, then empty the token registers
\DTLiffirstrow{\section{}}{
\DTLifeq{\Codes}{\SecTest}{
\begingl
\expandafter\gla\the\glosslineA//
\expandafter\glb\the\glosslineB//
\expandafter\glc\the\glosslineC//
\endgl
\section{}
\emptytoks
}
{% For each cell, append it to the token register for that line
\Append\glosslineA{\Codes}%
\Append\glosslineB{\GreekText}%
\Append\glosslineC{\PortugueseText}%
}}}
% output the last section's lines.
\begingl
\expandafter\gla\the\glosslineA//
\expandafter\glb\the\glosslineB//
\expandafter\glc\the\glosslineC//
\endgl

\end{document}


# Output of both solutions

-
Alan-- This is a fine answer. I guess one have to try the two different ways of input and see what is best. My first thoughts, when I posted was that this would probably be an easier way of doing it, but more error prone (think tables), also if you need to do a correction I think it may be more difficult. My other thought was that using the grouping method, is easier to automate an index, which can act as a sort of dictionary. – Yiannis Lazarides Feb 26 '12 at 18:20
@YiannisLazarides Linguists have been doing this regularly for decades. It also makes the raw text infinitely more readable. As I suggested in the answer, you could actually keep the raw text in a spreadsheet, which would keep things aligned very easily. It might even be possible to combine this with datatool to keep the texts in sync. – Alan Munn Feb 26 '12 at 18:37
Thank you VERY , VERY MUCH for every answer. When I first started to ask questions to my patron in the translation as I would see he was changing fonts and macros and even programs (Plain Tex to XeteX and the like) he asked why I wnate "to learn Chemistry to have coffee strained". Now i confirm that I MUST learn Chemistry, for i undertant too little from your answers. Yet, I do own a compass now (a bussola), and I am confident I am in the right path (learning "Chemistry"). I am not yet able to provide the sort of feedback you expect, but I proceed in my learning and attempts, very grateful. – Joaquim Pedro Mar 9 '12 at 17:14

I suggest you start from something like what is shown in the minimal below. You will have to input all three "words" line by line. I have used "|" as a delimiter and a ";" to end the macro as I feel it will be easier to capture the input this way.

\documentclass{article}
\usepackage[polutonikogreek, english]{babel}
\fboxrule0pt
\fboxsep1pt
\parindent0pt
\begin{document}

\def\add#1|#2|#3;{\fbox{\vbox{\hbox{#1}\hbox{#2}\hbox{#3}}}}
\def\addsection#1{\fbox{\vbox to 1.1cm{\vfill\hbox to 1cm{\hfill\Large\bfseries #1}\vfill}}}

\addsection{2.1}
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 1722-3588|  en tw| No;
\add 932 | Basilia Nabu| de Nabu;
\end{document}


Please try it out and pass some feedback to improve the looks and the UI. You can increase readability by an order of magnitude, if you color the greek text. Please add a comment if this is what you are after; I am looking for comments to improve the interface.

-
Is it possible to add a \smallskip or a hairline between each row? – rdhs Feb 26 '12 at 14:41
@rdhs Just increase the fboxsep to what you need. – Yiannis Lazarides Feb 26 '12 at 14:46
That also increases the distance between consecutive boxes. – rdhs Feb 26 '12 at 16:56
@rhs Yes, you are right. In this case add a small strut.\def\add#1|#2|#3;{% \fbox{\vbox{\hbox{#1}\hbox{#2}\hbox{#3}}}\rule{1pt}{35pt}}. See also tex.stackexchange.com/a/45023/963 – Yiannis Lazarides Feb 26 '12 at 17:42
Awesome, thanks. One can also add glue with \hspace{0.4em plus 50em} to get the boxes justified as in the example. – rdhs Feb 26 '12 at 18:26

This isn't very pleasant to input, but here is one thought with plain XeTeX:

\font\greek="GFS Olga" % http://www.greekfontsociety.gr/pages/en_typefaces20th.html
\font\portuguese="TeX Gyre Pagella:mapping=tex-text" % http://www.gust.org.pl/projects/e-foundry/tex-gyre/pagella
\font\bold="TeX Gyre Pagella/B" at 20pt
\fontdimen3\portuguese=1em % let interword space stretch a lot
\baselineskip=40pt % 3*10pt = 30pt, with lead ~3.3333pt 3*13.3333pt ~ 40pt
\def\ngp#1#2#3{%
\vcenter{\hbox{% \valign{\hbox{\strut##}& \hbox{\strut\greek##}& \hbox{\strut\portuguese##}\cr% it already is the portuguese font, I % just wanted to show how you could % change the last row #1&#2&#3\cr}}}}
\portuguese
{\bold 2:1}
\ngp{1722--3588}{εν τω}{No}
\ngp{2094}{έτει}{ano}
\ngp{3588}{τω}{}
\ngp{1208}{δευτέρω}{segundo}
\ngp{3588}{της}{do}
\ngp{392}{βασιλείας}{reinado}
\ngp{*}{Ναβουχοδονόσορ}{de Nabucodonosor}
\ngp{1797}{ενυπνιάσθη}{sonhou}
\ngp{*}{Ναβουχοδονόσορ}{Nabucodonsor}
\ngp{1798}{ενύπνιον}{um sonho,}
\ngp{2532}{και}{e}
\ngp{1839}{εξέστη}{desconcertou-se}
\ngp{3588}{το}{o}
\ngp{4151--1473}{πνεύμα αυτού}{espirito dele,}
\ngp{2532}{και}{e}
\ngp{3588}{ο}{o}
\ngp{5258--1473}{ύπνος αυτού}{sono dele}
\ngp{1096--575--1473}{εγένετο απ 'αυτού}{se lhe fugiu.}

{\bold 2:2}
\ngp{2532}{και}{E}
\ngp{2036}{είπεν}{mandou}
\bye


-