# Making Books with Latex…

A while ago I took a course and the vast majority of the useful information was presented in powerpoints and source code comments (via Jupyter notebooks). With all the spare time that covid has provided me, I have been trying to revisit that course and with the help of some normal formal textbooks, make a set of ‘course’ notes for myself. I believe that writing information out in your own voice really solidifies a lot of information for yourself.

The most important thing is to capture the information in a document that can be printed out. Hence, one of the main goals is trying to have the minimal amount of Latex class and package settings and parameters as possible, while still producing a document with some cool visual embellishments. The big thing is to learn and keep track of the information as a PDF, and not worry that much about formating.

To keep thing simple with all the examples, the lipsum package was used to generate some random text. Also the math was related to a previous Fourier series project. Again, things are being kept simple so we only want a screenful of additional code in the tex’s file preamble section, not multiple additional separate external files.

#### Basic Book…

Using Latex with no special packages or setting produces a pretty boring looking book. It is functional, however the style it brings back bad memories of from university course notes, hence some styling needs to be done.

All that needs to be done to produce the most basic of books is:

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage[margin=0.75in]{geometry}

\begin{document}

\tableofcontents

\chapter{First Chapter}
Some text...

\section{First Section}
More text...

\end{document}

Here is an example of such a basic book:

By adding a few things to the preamble and using a few packages, the produced book can be improved a fair bit nicer. Some of the key changes are:

The margins were adjusted so that a nice wide margin is on each page. There are a few purposes of this margin: 1) according to some, a narrower text block is easier to read, specifically if the ratio of the height to the width result in the golden ratio; 2) if this document is printed out, one can make notes in the extra space; 3) and finally, certain details are better suited in the margin rather than the main text block. Note that Latex switches the margins are switched back and forth for the left (verso) and right (recto) pages.

\setlength{\marginparwidth}{2in}
\setlength{\marginparsep}{0.15in}
\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{1.5in}
\setlength{\textwidth}{5in}
\setlength{\topmargin}{0in}
\setlength{\textheight}{8.4in}
\setlength{\footskip}{0.35in}
\raggedbottom
\renewcommand{\baselinestretch}{1}

Use to the Palatino font…

\usepackage{mathpazo}

Use the titlesec package to change the title format so that chapter titles are written out a little nicer and also some lines are drawn as well.

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\fontfamily{ppl}\selectfont\Huge\bfseries}
{\filleft\fontsize{48}{48}\fontfamily{ppl}\selectfont\thechapter}
{1ex}
{\titlerule\vspace{1ex}\filleft}
[\vspace{1ex}\titlerule]

Any code is written out in the verbatim environment. Also it is placed within a tcolorbox:

\begin{tcolorbox}
\begin{verbatim}
code...
\end{verbatim}
\end{tcolorbox}

The changebar package was used to draw bars beside ‘math stuff’. Note that the this package sometimes has some issues when compiling the document. The solution is to re-run the compilation and the problem does go away.

\usepackage[leftbars,color]{changebar}
\setlength{\changebarsep}{-3pt}
\setlength{\changebarwidth}{1.5pt}
\newenvironment{mathstuff}
{\cbcolor{black}\par \vspace{8pt} \cbstart \vspace{-15pt} \begin{enumerate} \item[]}
{\end{enumerate} \vspace{-5pt} \cbend \par \vspace{7pt} }

Also to note that since I am the primary audience of documents that I write, then I choose some style elements that make me happy even though I know that they are incorrect or bad. This includes block paragraphs (paragraphs with no leading indentation). These are made with the following settings:

\setlength{\parindent}{0pt}
\setlength{\parskip}{2.5ex}

Finally, an example of this more advanced book is shown below:

#### Using the Memoir Class…

The advanced book example shows that a nicer book can be made with a few additional items thrown into the preamble. However, instead of figuring out the necessary items to slowly add or tweak over the course of writing a large document, using the Memoir class makes life a lot easier.

Memoir comes with a few macros to set the page layout sizes. They make some complex issues such as dealing with trim marks (when multiple pages are printed on a single sheet), folded pages, and allowing an extra space for the spine. For an 8.5 x 11 inch page, the following was used:

\setstocksize{11in}{8.5in}
\setlrmarginsandblock{0.75in}{2.5in}{*}
\setulmarginsandblock{1in}{0.75in}{*}
\setmarginnotes{0.25in}{1.75in}{0.5in}
\checkandfixthelayout

The memoir class comes with some predefined page styles. Perhaps the most useful of all of them are the chapter page styles which make the chapter’s first page a little more visually appealing and looking more like a real book instead of like bad course notes. Some example chapter styles can be found here (also that is where the following code was taken from).

\usepackage{color,graphicx}
\definecolor{medblue}{rgb}{0.161, 0.322, 0.639}
\renewcommand\colorchapnum{\vspace{1.5in}\color{medblue}}
\renewcommand\colorchaptitle{\HUGE\color{medblue}}
\chapterstyle{pedersen}

With the rest of the settings we are using the defaults provided by the memoir class. An example of the output is seen below:

#### Other Stuff…

From the internet it seems that the Koma-script book package is a very popular solution. First I have to admit that I have some incompatibility issues with my old install of Latex and the current version of the package, so in the future with a fresh install of everything I would give it a try.

It seems that Koma-script documents involve a little more overhead in terms of settings and parameters than Memoir. However, they provide a higher amount of customization and therefore one is able to produce some very nice documents. Some nice koma-script book examples include Kaobook class or this Phd thesis template.

#### Code…

All of the code and output is available here.