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}

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Workspace: Netbook Photo Tools

    Find out how to turn your netbook into a fabulous photo tool.

  • Jekyll

    Most people starting a blog will almost automatically turn to WordPress, which calls for PHP, a database, and regular security updates … and thus a lot of attention. With the small Jekyll template engine, you can avoid all that.

  • FotoInsight Designer 4.5

    The newly released version 4.5 of the digital photo service is compatible with Linux and Mac operating systems and comes with geotagging and other new features.

  • Perl: Elasticsearch

    The Elasticsearch full-text search engine quickly finds expressions even in huge text collections. With a few tricks, you can even locate photos that have been shot in the vicinity of a reference image.

  • Books

     

comments powered by Disqus