Sentence alignment for dual-line bilingual paragraph translation in LaTeX

I would like to make a translation of entire paragraphs at a time for a large document, with the start of the new sentences aligning. The following is almost what I want done, though it doesn't yet do the alignment for new sentences.

\documentclass{article}
\usepackage[margin=1in, paperwidth=8.5in, paperheight=11in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{setspace}
\begin{document}

\def\english{In the heart of the forest lived three little pigs who were brothers. The wolf always was chasing them in order to eat them. In order to escape the wolf, the pigs decided to make a house each. The smallest made his from straw, to finish first and go out to play. The middle one constructed a cottage from wood. Seeing that his little brother had finished already, he hurried to go and play with him. The oldest worked on his house of brick. 'You'll soon see what the wolf does with your houses,' he scolded his brothers but they were having a great time.}

\def\spanish{En el corazón del bosque vivían tres cerditos que eran hermanos. El lobo siempre andaba persiguiéndoles para comérselos. Para escapar del lobo, los cerditos decidieron hacerse una casa. El pequeño la hizo de paja, para acabar antes y poder irse a jugar. El mediano construyó una casita de madera. Al ver que su hermano perqueño había terminado ya, se dio prisa para irse a jugar con él. El mayor trabajaba en su casa de ladrillo. - Ya veréis lo que hace el lobo con vuestras casas - riñó a sus hermanos mientras éstos se lo pasaban en grande.}

\begin{minipage}[t][0pt]{\linewidth}
\setstretch{3}
\english
\end{minipage}

\begin{minipage}[t]{\linewidth}
\setstretch{3}
\spanish
\end{minipage}

\end{document}

How can I automatically align new sentences? For bonus points, how can I modify this method to manually indicate when one sentence in english aligns to two in spanish? I would like the paragraph to flow naturally, I don't want to add a line break after each sentence or use a package that essentially does that.

-
for reference: it's repost of stackoverflow.com/questions/2968624/… – Grigory M Aug 25 '10 at 18:06
Can you take a look at the question that Grigory M mentions and see if any of the answers there help you? If they do, we'll close this question as a duplicate. If they do not, can you please explain why you need something else so that others will know how best to help you. Thanks! – Loop Space Aug 25 '10 at 18:25
No the post Grigory M mentions did not solve the issue. You may close the post there if you wish, but please do not close this one. – denilw Aug 25 '10 at 19:10
@Andrew: the linked post doesn’t even have any answers. – Caramdir Aug 25 '10 at 19:20
My apologies! I missed the fact that the link was to stackoverflow and not to another question on this site! On reading this question, I had in mind this question: tex.stackexchange.com/questions/1641/… and so when I saw a comment linking to another question I assumed that it was the same one that I was thinking of. Okay, let me re-ask my question but pointing to the question on this site. And rest assured that I shan't close anything that is unresolved! – Loop Space Aug 25 '10 at 20:12

This is a huge hack (and I can't wholeheartedly recommend using it as-is), but it is the only way I can think of doing it without mucking with TeX's linebreaking engine. You will need to latex this twice for it to work. This also assumes that the Spanish translations are not too much longer than the English.

\documentclass{article}
\usepackage[margin=1in, paperwidth=8.5in, paperheight=11in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{setspace}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\newcount\numsentences\numsentences=0
\def\sentence#1#2{
\expandafter\xdef\csname sentenceeng\the\numsentences\endcsname{#1}
\expandafter\xdef\csname sentenceesp\the\numsentences\endcsname{#2}
}

\sentence{In the heart of the forest lived three little pigs who were brothers.}
{En el corazón del bosque vivían tres cerditos que eran hermanos.}
\sentence{The wolf always was chasing them in order to eat them.}
{El lobo siempre andaba persiguiéndoles para comérselos.}
\sentence{In order to escape the wolf, the pigs decided to make a house each.}
{Para escapar del lobo, los cerditos decidieron hacerse una casa.}
\sentence{The smallest made his from straw, to finish first and go out to play.}
{El pequeño la hizo de paja, para acabar antes y poder irse a jugar.}
\sentence{The middle one constructed a cottage from wood.}
{El mediano construyó una casita de madera.}
\sentence{Seeing that his little brother had finished already, he hurried to go and play with him.}
{Al ver que su hermano perqueño había terminado ya, se dio prisa para irse a jugar con él.}
\sentence{The oldest worked on his house of brick.}
{El mayor trabajaba en su casa de ladrillo.}
\sentence{You'll soon see what the wolf does with your houses,'' he scolded his brothers but they were having a great time.}
{- Ya veréis lo que hace el lobo con vuestras casas - riñó a sus hermanos mientras éstos se lo pasaban en grande.}

\begin{minipage}[t][0pt]{\linewidth}
\setstretch{3}
\count0=-1
\loop
\ifnum\count0<\numsentences
\tikz[remember picture]\coordinate(s\the\count0 begin);\csname sentenceeng\the\count0\endcsname\tikz[remember picture]\coordinate(s\the\count0 end);\hskip0.5in
\repeat
\end{minipage}

\begin{tikzpicture}[remember picture,overlay]
\count0=-1
\loop
\ifnum\count0<\numsentences
\path let \p1=(s\the\count0 begin), \p2=(s\the\count0 end) in (s\the\count0 begin) node {\xdef\xpos{\x1}\xdef\ypos{\y1}\xdef\xxpos{\x2}\xdef\yypos{\y2}};
\ifdim\ypos=\yypos
\node[below=12pt,left=1mm,anchor=west] at (s\the\count0 begin) {\dimen0=\xxpos\advance\dimen0 by -\xpos\hbox to \dimen0{\csname sentenceesp\the\count0\endcsname\hfill}};
\else
\path (current page.west) -- +(1.2in+\oddsidemargin,0) node[coordinate] (leftanchor) {};
\path let \p1=(leftanchor) in (s\the\count0 begin) node {\xdef\leftxpos{\x1}};
\path (leftanchor) |- node[below=12pt,left=1mm,anchor=west] {\begin{minipage}[t][0pt]{\linewidth}\setstretch{3}\dimen0=\xpos\advance\dimen0 by -\leftxpos\hspace*{\dimen0}\csname sentenceesp\the\count0\endcsname\end{minipage}} (s\the\count0 begin);
\fi
\repeat
\end{tikzpicture}

\end{document}

-
hmm, interesting. Thank you for the working example +1. I'll have to muck around with this for a bit because, like you said, it seems like problems could arise if (when) one language's sentence is much longer. – denilw Aug 25 '10 at 21:56
The \hskip0.5in in there is really a nasty hack (that adds the whitespace between each sentence). I needed that in order for the "El lobo..." sentence to not overrun the "Para escapar..." sentence. You can play around with how things look by tweaking that length. A cleaner solution might be to measure the lengths of the two sentences in the \sentence{} macro and then pad the whitespace later based on their difference. This won't always work, but it might make things look better. I'll play around with that later today if I have time. – ESultanik Aug 26 '10 at 12:22
Is there some way of using xstring to get string length and the largest of the two strings and then \phantom somehow to have both lines take up the same space? I don't know what you would do if one language had more letters but a shorter typeset sentence. – denilw Aug 26 '10 at 23:04
xstring isn't even necessary; in plain TeX, if you do \setbox0=\hbox{blah blah blah} then the register \wd0 will be set to the width of that string. I thought about doing something with \phantom, but that wouldn't allow for linebreaks in the sentences, would it? Also, you may be interested in my related question (that was prompted by my answer to your question): tex.stackexchange.com/questions/2366/… – ESultanik Aug 27 '10 at 19:23
Thanks @ESultanik for the information. – denilw Sep 7 '10 at 16:24

Check a two column setup. Copy your text in inglish (some paragraphs) and translate them. Insert vertical space as needed, to align paragraphs.

-
Thank you for your comment. Yes this problem could be avoided with columns, however I do not wish to use columns. – denilw Oct 12 '10 at 11:59