Jeffrey Adachi

Projects




Typesetting Books With LaTex



While most of the work put into a book is probably generating the content (text, artwork and photographs), the presentation of the content and cover can have a big impact on the reader.
This is the realm of typsetting.

Typesetting is different from word processing (like that done in Microsoft Word and GoogleDocs).
You can find many online discussions of "word processors vs typsetting", "Word vs LaTeX", etc..
The short version for me is that I may use a word processor for composing text,
but once I have the text and want to make it look nice, I use a typesetting program.

Microsoft Word, GoogleDocs have some formatting, so could be used to layout a book.
But I prefer the look of text prepared using a typesetting program called LaTeX, so that is what I will describe below.


What Will Be Covered:



What Won't be Covered:


I don't haven any special expertise in the following areas, so I will not be commenting on them.

An Introduction to Typesetting with LaTeX


This section introduces the LaTeX typesetting program and presents files required for three example books: text only and text plus photos.

What is LaTeX?


LaTeX is a free typesetting program, originally designed for preparing technical material, like mathematics, for publication.
It brings the same fine control of page layout of any text.

The book is stored in one or more text files with names ending in ".tex".
Typically, these files contain the text of my book, with some extra commands that describe the formatting.
Since the files a text files, they are human readable which means that you can see what formatting is being applied.
Formatting does not require navigating obscure menus and icons.
With a single mouse click, the LaTeX engine converts the *.tex files and outputs a PDF file (a process called "compiling").


How To Get LaTeX


As mentioned above, LaTeX is free.
It is available in multiple distributions (bundles of the core LaTeX engine with associated files).
I use the one from MikTeX.
MikTeX supports Windows, Mac and Linux and the download page has links to tutorials to guide you through the installation.
This page describes other LaTeX distributions: LaTeX Distributions


Simple Book 1: Text Only


This section describes the parts of a LaTeX file required to generate a minimal book with title page and chapters with text.
Here is the LaTeX code for a book, as rendered by TeXworks, the editor included with MikTeX.

simple_book_code

Explanation of the LaTeX file: To compile the book, one would click the green triangle in the upper left of the window.

simple_book.pdf is the pdf compiled from the sample code.
simple_book.tex is an editable version of the sample code that you can copy and modify.


Simple Book 2: Text and Photos


This section describes the LaTeX file required to add pictures to a book.

simple_book_with_pictures_code

simple_book_with_pictures.pdf is the pdf compiled from the sample code.
simple_book_with_pictures.tex is an editable version of the sample code that you can copy and modify.

Explanation of the New LaTeX Commands:

Extensions

The two examples shold be enough to get you started with LaTeX.
If you need other document types (articles, slides, report, ...), automatically generated features (table of contents, list of figures, bibliography, ...) and special cases of formatting (mathematics, custom indentation, family trees, other languages, ...) there are lots of free online resources.
If you want a special feature, someone has probably already figured out (and shared) how to do it.


Things to Know About Preparing a Book for Print.


The output of LaTeX is a pdf file.
So the preceding examples apply to publishing in electronic form as well as in print.
This section will discuss some considerations specific to perpating a book for print.

Print on demand services provide guidelines for preparing your document.
(Lulu.com's "Book Creation Guide" is 25 pages long.)
Although terminology may vary, the requirements for your pdf whould fall into a few categories.


Paper Size vs Book Size


When you go to a local copy center and print a letter sized book with spiral binding, they print your book on 8.5" x 11" inch paper.
When you use a print on demand service, they print your book on oversized paper and trim the book to its final size after binding. (This insures the page edges all line up neatly).

For example, for a US letter sized book, you would generate a pdf with pages that are 8.75" x 11.25" to allow for the trimming.
To allow for slight inaccuracies in the trimming, a half inch safety margin should be left around your text.
An additional 0.2 inch "gutter" is required for the edge of the page that is bound.
That leaves a working area of 7.3" x 10" for your book (text and photos).

So keep in mind


Embedded Fonts


PDF files can use the fonts installed on your computer.
If the printer's computer doesn't have the font you used for your book, then a different font may be substituted.
Obviously, this could be a problem.
The solution is storing a complete set of all needed fonts in the PDF file itself.
This is called font embedding.
It makes the PDF file larger, but insures that the PDF file looks (and prints) the same on all computers.

The way this is accomplished in LaTeX is to use the command,
\usepackage[T1]{fontenc}


Image Resolution


Generally, we think higher resolution images are better, but high res images can unneccesarily bloat yout PDF files, leading to longer upload times.
If your printer is using 300 or 600 dpi, then including a 2400 dpi scan is just wasting space.
As you saw in the example LaTeX code, pictures are included with a size.
Since a picture has a fixed number of pixels, the number of pixels per inch changes when you change the dimensions of the picture on your page.
The implication is that you don't know how many pixels you want until you know the final layout of your book.

[Note: For publishing in electronic form, higher resolution photos may still be useful if you want readers to be able to zoom in for more detail.]

Since my first book had hundreds of photos, manually resizing the photos was not feasible.
I wrote a small script in the python programming langauge to automate this process.
The process starts by identifying all LaTeX files in a given folder.
For each image file that is included with the \includegraphics command,

  1. Get the image's printed dimension from the LaTeX file.
  2. Read the size in pixels from the image file.
  3. Scale the image to get the desired resolution in dots per inch (dpi).
  4. Save the scaled image to a new file.
If the graphicspath parameter is set to the new folder, the PDF is created with appropriately sized images.
If needed, the program can also make the image files a common format like jpg.
[A link the python program will be included below in the section on free tools.]


Image Color Spaces


You may have run into online discussions about color spaces (e.g. CMYK vs. RGB).
The issue is that computers describe color using RGB (combining red, green and blue lights), printers traditionally described colors using CMYK (combining cyan, magenta, yellow and black inks) and there is not a simple map from one to the other.
Unfortunately, not all colors you can see can be reproduced by your computer monitor and not all colors on your monitor can be printed on paper.

The traditional method of putting color images in books required converting the images to a CMYK color space.
Even now, converting your images to CMYK gives you more predictability and control over the final results.
But it can get complicated.
A full description of this process can literally fill a book.
CMYK 2.0, is a book with 268 pages describing the terminology, tools and processes for controlling color.
If you are not already calibrating the color on your monitor, then this might be overkill.
(But you might be interested in reading the book anyway to see whether you should be calibrating the color on your monitor.)

Fortunately, some modern printers (as described here Lulu's Image Formatting FAQ's) can support both sRGB and CMYK images.
Since sRGB is supported by common digital cameras, monitors and photo editing software, it is likely you can include photos you took without converting to CMYK.
If you need color space conversions, your photo editing tools may already support this.
I tend to use python (see teh section on Free Tools below) for my color space conversions.

Whichever color space you work in, it's probably a good idea to get a single copy to review before printing in large volume.


Free Tools