◊(Local Yarn Code "making-a-bookmaking-machine.poly.pm")

File articles/making-a-bookmaking-machine.poly.pm from the latest check-in


#lang pollen

◊; Copyright 2015 by Joel Dueck. All Rights Reserved.

◊(define-meta published "2015-02-24" conceal "blog,feed")

◊title{Making a Book-Making Machine}

I’m trying to automate the process of taking a blog (or any collection of plain text and images) and
producing a printed book, for reasons that will be stated elsewhere. These are my notes on doing
so.

◊newthought{Working backwards:} I’ll be using CreateSpace to print and bind the book. CS’s main
inputs are 1) a PDF of the book’s cover and 2) a PDF of the book’s interior. I’ll figure out how to
automate the creation of the cover later; for now I’ll focus on the book’s interior. I’ll be using
◊link[1]{pandoc} to convert HTML or Markdown into LaTeX, which can then be used to generate the PDF.
Most of the work will be in creating a suitable LaTeX template. On my Mac, I set up the development
environment for this by installing ◊link[2]{MacTeX} and ◊link[3]{Homebrew}, then installing pandoc
from the command line with:

◊blockcode{$ brew install pandoc}

As a simple test, I took the plain text of one of my own blog posts and saved it to simplepost.txt.
I also manually added some meta-data to the top (as ◊link[4]{described} in pandoc’s user guide),
like so:

◊blockcode{---
title: Imagination and Self-Doubt
author: Joel Dueck
date: July 18, 2014
---

# Imagination and Self-Doubt

...}

and then ‘compiled’ to PDF:

◊blockcode{$ pandoc -s -o out.tex simplepost.pdf
$ xelatex out.tex out.pdf}

The result is a very basic PDF set in Computer Modern, suitable for printing on loose sheets of 8.5″
× 11″ paper:

◊figure-@2x["bookscript-output1.png"]{PDF output using Pandoc and LaTeX on a simple Markdown file}

In later notes I’ll be working on customizing the LaTeX template used by pandoc to get
a good-looking PDF suitable for use with CreateSpace.

◊url[1]{http://johnmacfarlane.net/pandoc/index.html} 
◊url[2]{http://www.tug.org/mactex/index.html}
◊url[3]{http://brew.sh/}
◊url[4]{http://johnmacfarlane.net/pandoc/README.html#metadata-blocks}

◊note[#:date "2015-02-28"]{Since this effort happens to be geared towards created printed copies of
blogs, we’ll have each blog post correspond to a chapter in the book.

Blog posts are a little different than normal book chapters, though. Book chapters usually have
numbers, but posts are more commonly marked by the date on which they were posted. I had a hard time
finding examples of LaTeX chapter styles which featured a date within the chapter heading itself, so
I came up with my own solution. My preferred starting point was memoir’s “dowding” chapter style, in
which the chapter number appears above the chapter title, and both are centered. I copied its
definition and changed it so that, instead of printing automatic chapter numbers in numbered
headings (e.g., “Chapter One”) it instead prints whatever text I supply:

◊blockcode{
\makeatletter
\makechapterstyle{dowdingdate}{%
  \setlength{\beforechapskip}{2\onelineskip}
  \setlength{\afterchapskip}{1.5\onelineskip \@plus .1\onelineskip 
                            \@minus 0.167\onelineskip}%
  \renewcommand*{\chapnamefont}{\normalfont}%
  \renewcommand*{\chapnumfont}{\chapnamefont}%
  
  % Remove the word "Chapter" before the date (where the chapter 
  % number would normally be)
  \renewcommand*{\printchaptername}{}%
  
  % Print the contents of \chapterDesc in place of the chapter number
  % (except in appendices, where a simple [roman] numeral is printed)
  \renewcommand*{\printchapternum}{\centering\chapnumfont 
                                   \ifanappendix \thechapter
                                   \else \chapterDesc\fi}
  % (Original, for reference:) % 
  %\renewcommand*{\printchapternum}{\centering\chapnumfont 
  %                                 \ifanappendix \thechapter
  %                                 \else \numtoName{\c@chapter}\fi}%
  \renewcommand*{\chaptitlefont}{\normalfont\itshape\huge\centering}%
  \renewcommand*{\printchapternonum}{%
      \vphantom{\printchaptername}\vskip\midchapskip}} \makeatother }

Then I define a couple of new commands that allow me to pass an additional string of text to be used
in place of each chapter’s number:

◊blockcode{\newcommand{\setChapterDescription}[1]{%
   \def\chapterDesc{#1}%
}

\newcommand{\ChapterDate}[2]{
    \setChapterDescription{#2}
    \chapter{#1}
    \setChapterDescription{}
}

% define as empty to prevent an error the first time
\def\chapterDesc{} }

And here’s how I use all this in the template:

◊blockcode{
...
\begin{document} 
\chapterstyle{dowdingdate}

\ChapterDate{My Summer Vacation}{July 22, 2014}
...
}

◊figure-@2x["bookscript-output2.png"]{The new chapter style, set in Adobe Caslon Pro} }

◊note[#:date "2018-03-01"]{The first version of the LaTeX template pictured in the previous note is
now available on github as part of ◊link['github]{Simple Book Machine}, which is a shell script and
a system for using LaTeX templates to build a book from a collection of text files. 

The output generated can theoretically be uploaded straight to CreateSpace for use in a 5.25″ × 8″
sized bound book. (I have yet to actually try this, but the PDF does meet all their requirements.)
I plan to add options for a few other book sizes and designs in the future.}

◊url['github]{https://github.com/otherjoel/simplebookmachine}