Creating ready-to-print photo books with Ruby and TeX
Beginning and End
So what do the template files actually look like? TeX, or rather LaTeX, code is teeming with backslashes and uses curly braces to delimit text areas. After a preamble with the document type and some additional required TeX macro packages, the actual document always begins with a \begin{document}
statement and ends with \end{document}
. The intro.tex
and outro.tex
templates in Listing 3 and 4 do exactly this, defining the beginning and end of each photo album you intend to generate.
Listing 3
intro.tex
01 \documentclass[10pt]{book} 02 \usepackage[export]{adjustbox} 03 \usepackage{color} 04 \pagecolor{black} 05 \color{white} 06 \usepackage[paperwidth=9in, 07 paperheight=7in, 08 total={8in,6.5in}]{geometry} 09 \pagestyle{empty} 10 \begin{document} 11 \sffamily
Listing 4
outro.tex
\end{document}
The LaTeX color and pagecolor packages define the font and background colors in the document. Because photo books somehow look more professional in dark mode (i.e., with a white font on a black background) – or not, the choice is yours – the template sets \color{white}
and \pagecolor{black}
.
LaTeX documents usually print page numbers at the bottom of every page, but that's not a good look for a photo book, so the command \pagestyle{empty}
turns off this feature. In addition, TeX's standard font, Computer Modern, looks somewhat antiquated nowadays, but the sans serif version (selected by the command \sffamily
) is still pretty modern, at least to my untrained eyes. The adjustbox package lays the foundation for the graphics package to include photos in the text and supports features like scaling to make sure the photos fit into the boxes left blank by TeX in the layout stage.
The photo book's page format is specified by the geometry package starting in line 6 of Listing 3. In line with the specifications of the print service provider I use, the pages measure 9 by 7 inches in landscape format, with the actual printed area being slightly smaller at 8 by 6.5 inches to allow for a margin. For other service providers, you may need to make adjustments to the page format here. Also, some printers require the PDF to set page dimensions beyond the actual paper size being used to allow for the ink to extend all the way to the page border, even after a somewhat inaccurate cutting process trims off the edge. This is known as "full bleed" in the printing process.
The end of the TeX document is heralded by the outro.tex
template, which merely fires off an \end{document}
to tell TeX that it's done.
Floating in the Center
Listing 5 shows you a TeX template for an empty page with an optional, centered text module. The template processor replaces the placeholder <%= text %>
in line 3 with the value contained in the ERB variable text
. To ensure that the Huge
-sized text output is centered vertically as a chapter heading, Line 2 uses \vspace*
to set a fill space above it, while line 4 does the same thing underneath the text. Because the two fill spaces above and below occupy equal areas in line with the rules of fair space allocation, the text ends up at the middle of the page. TeX, by the way, distinguishes between \vspace
and \vspace*
: The command without the asterisk is ignored at the top of the page, which – somewhat surprisingly – would make the chapter heading float up to the top of the page.
Listing 5
chapter.tex
01 \null\newpage 02 \vspace*{\fill} 03 \center{\Huge{<%= text %>}} 04 \vspace*{\fill}
Good First Impression
The photo book's cover page in Figure 1 displays an image with a line of text in a large font below it; the text is aligned vertically with the image's right margin. Listing 6 introduces a horizontally centered environment to the cover.tex
template using \begin{center}
and includes a photo set to a height of three inches thanks to \includegraphics
from the LaTeX library's graphics package. The template processor gets handed an array of photo files later on, and the <= photos[0] %>
placeholder defines the path to the first file in the list. LaTeX then reserves the space occupied by the image in the document. The PDF driver sets the photo later on after scaling it to the required size.
Listing 6
cover.tex
01 \vspace*{\fill} 02 \begin{center} 03 \hfill 04 \includegraphics[height=3in,valign=t]{ 05 <%= photos[0] %>} 06 \hspace {4cm} 07 \end{center} 08 \vspace{2cm} 09 \begin{center} 10 \hfill \Huge{<%= text %>} 11 \hspace {4cm} 12 \end{center} 13 \vspace{1cm}
For photos that need to stand out in a big way, Listing 7 shows a template for a page-filling landscape photo with a caption underneath, as seen on page 3 of the finished photo book in Figure 2. The \includegraphics{}
command reserves space for an image in the layout. Specifying height
limits the area vertically so that there is still room on the page for the image caption at the bottom. Line 7 sets the text below the photo with half a centimeter of extra space.
Listing 7
single.tex
01 \null 02 \begin{figure} 03 \centering 04 \includegraphics[height=5.5in,valign=t]{ 05 <%= photos[0] %>} 06 \linebreak 07 \par\vspace{.5cm}\par 08 \Huge{\sffamily <%= text %>} 09 \end{figure}
« Previous 1 2 3 4 Next »
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
-
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.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.