Creating ready-to-print photo books with Ruby and TeX
Two Towers
If you want to lay out two photos in portrait format side by side on one page of a book in landscape format, just use the twotowers.tex
template in Listing 8 (two towers being a metaphor for two images in portrait format). The template references the two photos passed in as parameters by <%= photos[0] %>
and <%= photos[1] %>
. The photos on page 4 of the photo book in Figure 2 are two mirror images, the first one a real photo of a piece of broken road, right by the ocean south of San Francisco; its mirrored counterpart was created by the ImageMagick Convert tool's -flop
option.
Listing 8
twotowers.tex
01 \null 02 \begin{figure} 03 \centering 04 \includegraphics[height=5in,valign=t]{ 05 <%= photos[0] %>} 06 \hspace{1cm} 07 \includegraphics[height=5in,valign=t]{ 08 <%= photos[1] %>} 09 \linebreak 10 \par \vspace{1cm} \par 11 \Huge{\sffamily <%= text %>} 12 \end{figure}
Of course, a page of a book in landscape format can also accommodate four landscape photos arranged as a rectangular box. The four.tex
template in Listing 9 shows the corresponding TeX code. For some attractive spacing between the images, the template shrinks the photos to a height of 2.5 inches and sets the horizontal spacing to 0.5 centimeters in lines 5 and 13. The vertical spacing is set to 0.75 centimeters in line 9.
Listing 9
four.tex
01 \begin{figure} 02 \centering 03 \includegraphics[height=2.5in,valign=t]{ 04 <%= photos[0] %>} 05 \hspace{.5cm} 06 \includegraphics[height=2.5in,valign=t]{ 07 <%= photos[1] %>} 08 \par 09 \vspace{.75cm} 10 \par 11 \includegraphics[height=2.5in,valign=b]{ 12 <%= photos[2] %>} 13 \hspace{.5cm} 14 \includegraphics[height=2.5in,valign=b]{ 15 <%= photos[3] %>} 16 \linebreak 17 \par\vspace{.5cm}\par 18 \Huge{\sffamily <%= text %>} 19 \end{figure}
The underlying text in the \Huge
font is also centered within the \centering
environment and ends up 0.5 centimeters below the lower image pair, as specified by line 17. The \par
statement introduces a new paragraph in TeX, and \vspace{}
tells the typesetting engine to leave space between paragraphs – in this case, 0.5 centimeters.
Your Own Templates
The templates presented thus far will help you create an attractive photo book. The book consists of the cover, blank pages, chapter headings, and photo pages with one photo in landscape format, two photos in portrait format, and four photos in landscape format – all of them with optional page text. To output the finished photo book in PDF format, all that you need is a script like Listing 1 that retrieves the templates and includes appropriate photos from your hard disk. After cobbling together the code for a TeX document, the final b.print
will invoke the xelatex
compiler to turn it into a print-ready PDF.
Of course, you can let your creativity run wild and create arbitrary new TeX templates that you can then call in the Ruby script. Because the entire book definition is a text file and managed by a version control system like Git, you can incorporate changes without worrying about failed attempts or even add parts of an existing book to a new one – I guess you could call it photo book engineering.
Tempus Curat Omnia
By the way, I found a nice quote in Donald Knuth's TeX book [1], which I read as a refresher for this article – imagine, the first edition was published in 1984! On page 110, he explains why TeX meticulously tries to rearrange paragraphs such that the word spacing in all lines looks as equal as possible – up to the point where a single word at the end of a paragraph can force the entire paragraph text to be reworked. On the other hand, TeX won't look several pages ahead, in terms of pagination, in order to distribute illustrations and text paragraphs as smartly as possible across pages. Knuth also gives a reason for this design decision: The RAM of a typical desktop computer was simply not big enough at the time to hold several pages at once – how times change.
Infos
- Knuth, Donald E. The TeXbook. Addison-Wesley Professional, 1984: https://www.amazon.com/TeXbook-Donald-Knuth/dp/0201134489
- Goossens, Michel, Sebastian Rahtz, and Frank Mittelbach. The LaTeX Graphics Companion. Addison-Wesley, 1997: https://www.amazon.com/LaTeX-Graphics-Companion-Illustrating-Postscript/dp/0201854694/
- Schilli, Michael. Perl Power! Longman Group, 1998: https://www.amazon.com/Perl-Power-JumpStart-Guide-Programming/dp/0201360683/
« Previous 1 2 3 4
Buy this article as PDF
(incl. VAT)