Categories
LaTeX Publishing

Filling the Template

A simple way of writing books in LaTeX is using Overleaf and our template. In previous articles, we have walked through the whole “build chain” of creating documents. In this article, we go through each file of the template and give you a “to do” list of items you can work on one by one—from the title to the appendix.

This is an excerpt from Better Books with LaTeX the Agile Way. You can get a copy here.

A simple way of writing books in LaTeX is using Overleaf and our template. In previous articles, we have walked through the whole “build chain” of creating documents. In this article, we go through each file of the template and give you a “to do” list of items you can work on one by one—from the title to the appendix.

One way to understand the structure of a book is to imagine how books were created before the digital age. Imagine different groups of people working on the book and handing over the results to the next group. At the beginning of this process, there is the core material that makes up most of the book: the individual chapters and sections. Those are surrounded by the front and back matter, which consist of several layers. The author hands the text of the chapters over to the editor, together with a note introducing his or her work (the preface). The editor adds the table of contents, the indexbibliographyquotation sources, and maybe an appendix (containing summaries from throughout the book), and hands the book over to the publisher.

The publisher adds information to the book, too. That is, first the publisher page itself with the year of publication, ISBN number, copyright note, and publisher name, and then a description of how the book was created and, for example, how the reader can contact the publisher with any questions (the foreword). All the parts are then put into an envelope (consisting of the series title and half title), and handed over to the cover designer. The cover designer creates the cover, and packages it together with the book into another envelope (consisting of the title page including the cover picture) and hands it to the printer.

With the overall structure in mind, let us look at each of the elements one by one, starting with the project title. After having opened the template project, on the left side in the project file overview, you can find the file output.tex. This is the entry point of the template (hence it is displayed in bold). If you ever want to change the output language to another language, you can adapt the file accordingly by changing the parameter of the babel package. For example, replacing american with ngerman activates the babelDE script, as well as some language-related formatting and sorting. In addition, you could add language-specific hyphenation rules here. For now, let us continue with the English setting.

Front Matter

In the left project window, click on the front folder. You will see a list of several files open. Here, select title.tex. This will be the first page of the document. Then, start editing the file and do the following tasks:

  • Replace “The Title” with your book title.
  • Replace “The Subtitle” with your book subtitle
  • Replace “Publishing Company, Location” with your publishing company’s name and location.

About the last point, if you do not own a company, put in your own name and address. Note that from a legal standpoint, this depends on the country in which you are publishing the book. Writing all the information down puts you on the safe side; if you want privacy, you have to check what is required by law (and perhaps consider a P.O. box).

We also need two cover versions, one for the e-book (low resolution) and one for print (high resolution). The reason is that (at least on platforms like Amazon) your profits for each e-book shrink depending on the file size. In 2019, this download charge was around $.15 per MB, so a 10 MB e-book would reduce your profit by nearly $1.50. For print, file size can be ignored and thus the image quality can and should be as high as possible.

Rename both versions of your cover (PNG and JPG) cover_highres.png and cover.jpg and upload them into the images folder. Alternatively, just upload your cover files and replace the entries in the title.tex file.

If you do not have a cover file, skip this step. We discuss cover creation in another article and the book.

To upload a file, click on images in the left project window, click on the arrow, and select Upload File. If the file already exists, it gets overwritten. The most straightforward approach is to rename your cover file to fit the existing template; otherwise you have to change the corresponding entry in the title.tex file.

Next, open front/half-title.tex. In the print edition, this comes after the title on page 3 of the book. Complete the following tasks:

  • Replace “The Title” with your book title.
  • Replace “The Subtitle” with your book subtitle.

If your book is part of a series, add a page showing the title of the series and listing all the parts (see front/series-title.tex). We will ignore that for now and assume it is a standalone book.

Next, open front/publisher.tex. This page is usually reserved for information about the book as a product. You should enter here when it was produced, by whom, and how someone can reach you. If you just fill in the following information, your work in this file is done:

  • Replace “Your company’s name” with your company’s name.
  • Replace “Your company’s location (city)” with your company’s location.
  • Replace “Your website’s URL” with your website’s URL (using https://).
  • Replace “Your email address” with your email address.
  • Replace “Edition” with the edition number (e.g., First Edition).
  • Replace “ISBN” with your ISBN.
  • Replace “Your editor’s name” with your editor’s name.
  • Replace “Your designer’s name” with your book cover designer’s name.
  • Add your image sources and icons, including their license type.
  • Replace “Your newsletter email” with your newsletter email.
  • Again replace “Your website’s URL” with your website’s URL (using https://).

Next is the dedication page (see front/dedication.tex). Here, you can thank people who helped you create the book. This page stresses that books do not stand alone, but build on other people’s work. When writing it, think of it as a letter you would send out to those people. Some people just write, “To my husband/wife/parents.” If you see it as but a chore and want to express your gratitude to those people in person rather than in writing, you can safely leave out the dedication page. In another article or the book, we learn how to rearrange, add, or remove whole pages or sections.

Another optional page is the epigraph page (see front/epigraph.tex). This page sets the theme for the book. This can be a quote, a picture, or anything you think could fit here. Here you can be creative and put some emotion into your book, even if it might be a dry book about LaTeX and project management. In my book Philosophy for Heroes: Knowledge , I have used the epigraph to introduce the reader to the summary boxes—insights into philosophy and linguistics—that I have put at the end of every section. They tell a meta-story. They are the icing on the cake. For your epigraph, consider whether you want to add a particular plot or theme to your non-fiction book. The epigraph page is the perfect place to introduce this concept.

Next comes the foreword (see front/foreword.tex). This is written by the publisher, or by you, with your self-publisher hat on. It should focus less on the content of the book but rather on the book production process itself. Encourage the reader to give you feedback and advise how he or she can contact you with an issue with the book, such as an error. Alternatively, the foreword can be written by an expert in the field, as a type of endorsement.

After the foreword, it is now up to you, the author, to introduce the book in the preface (see front/preface.tex). This can include how you arrived at the decision to write it, a personal note to the readers, and an “elevator pitch,” a short introduction telling the reader why this book is an essential read. Try to be personal and try to stay away from sales talk or corporate speech. Add a quote by your favorite author as a finishing touch.

This concludes the front matter of the book.

Main Matter

In the folder list in the project view on the left, you will see a folder named main. This is the place for the main content, with a separate file for each chapter. Inside the main folder, you will find firstchapter.texsecondchapter.tex, and thirdchapter.tex. Those are just example files which you can simply delete or rename after you have added your own text.

  • If you are starting your book from scratch, simply open main/firstchapter.tex, remove the default template text below \end{chapterpage} and start writing.
  • If you already have your whole book (or portions of it) ready in one big Word (or text) file, you need to separate the text by chapter and put each chapter into a separate file.
  • If you have already separated your book into individual chapters, each in its own file, proceed as outlined below.

For each chapter, create a new file in the main directory in Overleaf. Instead of calling them firstchaptersecondchapter, etc., it is best to give them the chapter number plus the actual name of your chapter (for example, I named the file of this chapter main/13-filling-template.tex). This way, you can more easily refer to or rearrange them later.

Once you have identified all chapters and created the files, you need to copy the text into each chapter file. For this, simply select the text of your chapter (including the title), and copy and paste it into the corresponding .tex file. There is a chance that the project will no longer (or only partially) compile after inserting your text. This can happen if your text already contains what Overleaf interprets as LaTeX commands. The most frequent issues are:

  • Percentage signs % They are interpreted as comments by LaTeX and are thus ignored. Replace them with “\%”
  • Curly braces { } They are interpreted as special commands by LaTeX. Replace them with “\{” or “\}”
  • Dollar signs $ They are interpreted as starting or ending a mathematical formula. Replace them with “\${}”
  • Underscores _ They are used in mathematical formulas. Replace them with “\_”

Please note that there is no simple way of copying the formatting (bold, italic, font size, lists, indentation, etc.) from Word to LaTeX. If you already have your text formatted in Word, check out Chapter 14 for how to format the text manually. For any future books, I recommended that you write them directly in Overleaf from scratch and use the LaTeX formatting as you write.

Chapter Organization

Next, take a look into main/firstchapter.tex again. Here, you see additional formatting at the top that defines the chapter title page. For each of your chapter files, copy and paste the following code to the top of your file:

 
 
\begin{chapterpage}{Replace with First Chapter Name}{c1_firstchapter:cha} 
 
\begin{myquotation} The perfect place for an introducing quotation.\par\vspace*{15mm} 
\mbox{}\hfill \emdash{}Famous Person\index{Person, Famous} 
, \citetitle{bibitem}\index{@\citetitle{bibitem}} \ifxetex\label{famousperson-bibitem-quote}\else\citep[p.~123]{bibitem}\fi 
\par\end{myquotation} 
 
\end{chapterpage}  

Then, you need to:

  • Replace “Replace with First Chapter Name” with your chapter title.
  • Replace “c1_firstchapter:cha” with your chapter title label (no spaces, only lower case letters).
  • Replace the quotation text, add the person’s name, and (if you have it) the bibliography item. If you do not have the source, remove the following line:  
     
    \citetitle{bibitem}\index{@\citetitle{bibitem}} \ifxetex\label{famousperson2-bibitem-quote}\else\citep[p.~123]{bibitem}\fi  

You can find more about this in another article and the book.

There are several approaches for how to organize the individual chapters and sections of your book. Personally, I prefer to divide my content into small (ideally independent) slices, with each slice providing the reader with some benefit (as discussed in Part I of the book).

Back Matter

The back matter of a book typically consists of two elements: references and connecting with the author:

  • By “references” I mean the glossaryquestions to reflect on about the book’s contents, a summary of the main points of the book, the index, a list of image and quotation sources, and the bibliography. Whether or not you want to include the glossary, the questions, and the summary of ideas depends on the book you are writing. The index is created automatically, but it will need some work within the text of the main matter of the book, which we also discuss in another article and the book. The same applies to the bibliography.
  • By “connecting with the author” I mean the “About the Author” section, information about your (or your publisher’s) other books, an optional section about how the book was created, and a polite reminder to your readers to leave a written review online. If you want to give the book a finishing touch, end with a short quote on the last page.

Let us go through the files of the template one by one. Open the back/author.tex file and:

  • Upload a high-resolution (author_highres.png) and a low-resolution picture (author.jpg) of the author into images folder.
  • Replace the quotation text.
  • Add a short text describing your motivation, your professional background, what you are currently doing, and how to contact you.

If you have other books published, the back/advertisement.tex is the place you can list them. In the template, replace “YOUR NAME” in the chapter title, replace or remove the pictures of the book covers, and replace or remove the descriptions of the individual book entries.

Next, you are free to use the text in back/amazon.tex if you like or adapt it to your own needs, depending on where you publish the book. This is a reminder for the reader to provide you (and potential future readers) feedback.

Beyond the cited works and your other books, you can also direct the reader to additional book recommendations to delve deeper into the subject. For this, use the command \nocite in the back/recommended.tex file and list the recommended books by their book id from your bibliography file.

If you want to tell a story about how you created your book (if you have not already done so in the preface), you can do so in the back/thebooksstory.tex. Use this chapter to summarize what you have learned while writing the book. This helps you to write better books in the future and might be interesting for the reader as well. Myself, I like to talk about what is going on in the background of what I do. It is up to you. The existing default text in the template describes to a reader how the book was created using the template and this book as a guide. Feel free to skip this one—we cover how to reorganize or remove individual sections in another article or check out the book for more details.

Finally, replace the quote in back/last.tex to leave the reader with something to think about.

What about the table of contents? While it is generated automatically in both LaTeX and Word, updating it in LaTeX requires no additional work. As the project files are fully compiled after each change, you do not even need to manually refresh the table of contents. We still have to organize and format the text you have pasted into the main matter of the book, though. Once that is done, your whole table of contents will show up in the output.

That is it! Your book is finished and we can now move on to polishing.

Chances are that through the copying and writing process, a few issues have come up. That is normal! Remember, LaTeX takes a little bit of time to learn. But once you know it, it flows naturally like normal writing—like a normal language. All it takes is patience. If you hit a wall, you can always create a new copy of the template and progress in smaller steps. Even better, use the backup and restore feature (top menu entry, History, see the book for details).

This is an excerpt from Better Books with LaTeX the Agile Way. You can get a copy here.

Leave a Reply