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)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.