Filling the Template

This is an excerpt of the book “Better Books with LaTeX.” The book comes with a LaTeX template you can use to easily create your own books.

Now that you have walked through the whole “build chain” of creating documents with the template, you can start to add content to it. In this section, we go through each file of the template ( to 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 where 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 themselves 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 its note to the book, too, describing 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 where it is finally printed.

With the overall structure in mind, let us look at all the elements one by one. Let us start with the project title.

After having opened the template project, on the left side in the project file overview, you can find the file english.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 German (or another language), you can click on the arrow right beside the file name and select “Set as Main File.” If you want to switch back to English, just click on the arrow right beside english.tex and select “Set as Main File.” 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 number of 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 the file size of an e-book should be as small as possible (large e-books cost more), while file size for print can be ignored and thus the image quality can and should be as high as possible.

If you do not have a cover file, skip this step. We will discuss cover creation in chapter 11.

Rename both versions of your cover (JPG and PNG) into “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.

To upload a file, click on the arrow right of “images” in the left project window, and select “Upload from Computer.” If the file already exists, it gets overwritten. The simplest approach is to rename your cover file to fit the existing template, otherwise you have to change the line 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, the 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 (with https://).
  • Replace Your email address with your email address.
  • Replace Edition with the edition number.
  • 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 the license.
  • Replace Your newsletter email with your newsletter email.
  • Replace Your website with your website (with https://).

Did you know?

Getting all the legalities right is part of a book project, especially when it comes to licenses, ISBNs, quotes, and images. -→ Read more in Writing Better Books, the Agile Way 

Next in line 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. Later we will learn how to rearrange, add, or remove whole page or sections (see Chapter 6.2).

Another page that is optional 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—special 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 own epigraph, consider whether you want to add a certain 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 yourself with your self-publisher hat on. It should focus less on the content of the book but rather 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 like an erroneous print. 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 basically an “elevator pitch,” a short introduction telling the reader why this book is important to 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 can 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 findfirstchapter.texsecondchapter.tex, and thirdchapter.tex. Those are just example files which you can simply delete or rename after you have added your own texts.

  • If you are starting your book from scratch, simply open main/firstchapter.tex, remove the default template text below “\end{chapterpage}”, and start typing.
  • 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 give each chapter a name.
  • 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 actual name of your chapter. This way you can more easily move them around later without renaming them. For example, in this book project Better Books with LaTeX , this chapter is called main/filling-template.tex.

Once you have identified all chapters and created the files, you need to copy the text to each chapter. For this, simply select the text of your chapter (including the title), and copy and paste it into the corresponding .tex file.

Next, take a look into main/firstchapter.tex. Here, you see additional formatting at the top:

\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 

For each of your chapter files, copy and paste the above printed template to the top of your file. 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{famousperson-bibitem-quote}\else\citep[p.~123]{bibitem}\fi

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 formatted text in Word, check out Chapter 3 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 right away.

Did you know?

There are several approaches for how to organize the individual chapters and sections of your book. The one you choose depends on your project management method. My preferred approach is to divide my content into small (ideally independent) slices, where each slice provides the reader with some benefit. -→ Read more in Writing Better Books, the Agile Way 

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 LaTeX commands. The most frequent issues are:

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

  Back Matter

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

By “references” I mean the glossary, questions to reflect on 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. I found it useful in my own book series Philosophy for Heroes to make it a little bit easier for the reader to understand the concepts. The index is created automatically, but it will need some work within the text of the main matter of the book, which we will also discuss later. The same applies to the bibliography (see Chapter 4).

By “connecting with the author” I mean the “About the Author” section, advertisement for your (or your publisher’s) other books, an optional section about how the book was created, and a reminder 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 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 put this information.

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 give 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 deepen 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, but then again, I also wrote this book about how to create books. 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 will later talk about how to reorganize or remove individual sections (see Chapter 6.2).

One last thing, what about the table of contents? Just as in Word, it is generated based on the chapters and sections you have defined, so no work is required. As the project files are fully compiled after each change, you do not even need to refresh the table of contents manually. 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.

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

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 explained at the end of the previous Chapter 1 (top menu entry “HISTORY & REVISIONS”).

2018-10-23T21:56:58+00:00Tags: |