I am currently translating a book and typesetting the translation.

For reviewing purposes, I would find it very useful to display the original and translated texts side-by-side, without having to duplicate the text I have for the typesetted translation. My translation is stored in a chapters/ directory, one file per chapter, beginning with a \chapter command, and containing several \section* commands each.

My idea would be to have a chapters_orig/ directory with the chapters in the original language, and then automatically generate a document that contains the two languages side-by-side, paragraph by paragraph. I have read about the parallel package but I don't see how I could use it to automatically generate this document without altering my current document.


Although I've answered my question with a bash script, I'm still interested in a TeX-based solution, and I would be happy to make it a package.

  • I just glanced at the parallel documentation and learned of a design decision that may affect whatever you do: its macro \ParallelPar is intended to provide for coordinated side-by-side paragraphs. Thus, corresponding chunks may be different sizes but not fall too much out of sync via judicious use of this command. It seems to me that you will have to do something similar whether or not you use parallel, or else your side-by-side document will be a little confusing. Basically, your two files need to be written with parallelization in mind. – Ryan Reich Apr 25 '11 at 20:48
  • @Ryan: I've read about \ParallelPar in parallel's documentation. It also says that it's been suggested to make it automatic instead of explicit, which would be much easier for me since I do want paragraphs to correspond properly. Using \ParallelPar explicitly would make it quite hard for me though, without modifying the translated text. – ℝaphink Apr 25 '11 at 21:07

I think parallel is the best way to go, but doing it the way I want to is a bit tricky in pure TeX. After much thinking, I ended up writing a bash script to do it. It's not the most elegant solution (you can call it ugly if that makes you feel better), but it does the trick.

Here is my script:



# Split all files
for l in fr en; do
   mkdir -p $SPLITDIR/$l
   for c in $CHAPDIR/$l/*.tex; do
      f=$(basename $c)
      csplit --quiet --prefix $SPLITDIR/$l/${num}_                         --suffix-format=%02d.tex                          --elide-empty-files                  $c /^$/+1 {*}

# Generate document
for c in $CHAPDIR/fr/*.tex; do
   f=$(basename $c)

   # Make chapter title
   #echo "\input{$SPLITDIR/en/${chnum}_00}" > $sfile
   #sed -i 's@\\chapter@\\chapstyle\\chapheadstyle@' $SPLITDIR/fr/${chnum}_00.tex
   #echo "\input{$SPLITDIR/fr/${chnum}_00}" >> $sfile
   enchap=$(sed -e 's@\\chapter{\(.*\)}@\1@' $SPLITDIR/en/${chnum}_00.tex)
   frchap=$(sed -e 's@\\chapter{\(.*\)}@\1@' $SPLITDIR/fr/${chnum}_00.tex)
   echo "\\chapter{$enchap \\\\$frchap}" > $sfile

   echo '\normalfont' >> $sfile

   echo '\begin{Parallel}{2in}{2in}' >> $sfile
   for pfr in $SPLITDIR/fr/${chnum}_*.tex; do
        secname=$(basename $pfr .tex)
        [[ "x$secnum" = "x00" ]] && continue


        # Replace chapter with \Huge, section with \Large
        sed -i 's@\\section\*@\\secstyle@' $pfr

        # Remove lettrines
        sed -i 's@\\chlettrine{\(.*\)}{\(.*\)}@\1\2@' $pfr

        if [ ! -f "$pen" ]; then
           echo "E: Missing file $pen"
           exit 1

        echo '\ParallelPar' >> $sfile
        echo "\ParallelLText{\selectlanguage{english}\input{$pen}}" >> $sfile
        echo "\ParallelRText{\selectlanguage{french}\input{$pfr}}" >> $sfile
   echo '\end{Parallel}' >> $sfile

I've moved my translated text to chapters/fr/ and added original chapters in chapters/en/. The script creates a splits/fr/ and splits/en/ directories (for the note, splits/ has got an 's' because I've got a rule called "split" in my Makefile), splits the chapters in chapters/* by paragraph (using csplit) and reassembles the chapters in splits/, using the parallel package.

The master document then contains the call to load the parallel package, as well as the \input calls:

% All chapters

Running ./split.sh followed by pdflatex masterdoc.tex generates the document with split chapters.

And here is how it renders:

split view with line numbers

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.