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.
So… how do we use LaTeX? What do we need to install, set up, etc.? And just how do we use LaTeX to create an e-book?
For now, we will focus on getting you started generating a PDF and e-book. Later in Chapter 2, we will go step by step through the process of copying your book from your text source (e.g., Word) to the template.
As these are possibly your first steps in the world of Overleaf and LaTeX, feel free to contact me at [email protected] if you encounter any problems!
Before we start, yes, setting up LaTeX the first time is more complicated than writing a letter in Word. But there are many solutions available that allow you to use LaTeX without much hassle. One of those solutions is Overleaf , which I am using in writing this very book (and all my other books). It it available free for projects that do not require password protection. For professional books, I recommend the Pro upgrade which also comes with full project history, access management, support for larger projects, and priority support.
Overleaf requires no installation. Just sign up, use my template, fill in your text, and you are ready to download the necessary files for print book or e-book creation. If you are using a different LaTeX website or your own local installation, a different configuration might be necessary.
The first thing you will need is an account on the online platform Overleaf . Overleaf is an online editor and project manager for LaTeX documents. For this, simply go to https://www.overleaf.com/signup, enter your name and email, confirm the email, and log into your Overleaf account at https://www.overleaf.com clicking on “SIGN IN.” (if you want to help me hosting future templates and projects, use this instead: https://www.overleaf.com/signup?ref=506f081f3617)
Clone the Template
Once you have your account, grab a copy of the template either by visiting https://tinyurl.com/ltxtemplate, or by going to https://www.overleaf.com/latex/templates, searching for “Book Template for Amazon KDP and Google Play,” and opening “Book Template for Amazon KDP and Google Play (e-book and PDF)”, and pressing “OPEN AS TEMPLATE.” Please note: Overleaf is currently updating its interface. As this is still ongoing, please use the old editor by selecting “No thanks, open in Overleaf v1 editor.” Once the update is complete (early 2019), I will update this book accordingly. As of now (September 2018), e-book export is not working properly. For the most up-to-date information about Overleaf v2, check https://www.lode.de/template. Once cloned, any changes to the template will be applied to your own copy of the template. It is accessible via your Overleaf project view (go to https://www.overleaf.com and click on “My Projects”); your new project should be listed there. The template itself needs to be adapted of course—after all, it is your book, not mine. But for now, let us focus first on how to get from the template to a book. So, navigate to your project view (https://www.overleaf.com, “My Projects”) and click on the new project “Clemens Lode’s LaTeX Book Template.” Then, click on the project. If you are asked whether to port it to v2, select “No thanks, open in v1.” In the opened window, you should should see a menu bar at the top. Clicking on “PROJECT” closes or opens the file overview on the left. On the right, you will see a preview of the PDF output. Remember what I mentioned at the beginning of the book: LaTeX is not a “what you see is what you get” editor. Instead, whatever you write first has to be compiled into a PDF. Hence, you have the actual editing window in the middle (horizontally), and the separate output window on the right side of the screen.
The template is set up to produce both HTML files and PDF files. The HTML files can later be converted into formats that can be read by, for example, a Kindle e-book reader. For now, let us first create a PDF output.
For now, click on the settings icon (the wheel) at the top right of the screen. A new window shows up (see Figure 2.1), in the “Advanced Build Options,” click on the drop down menu right of “LaTeX Engine.”
For now, we want the PDF output, so select XeLaTeX.
Switching here between pdfLaTeX and XeLaTeX allows you to switch between HTML output for e-books (pdfLaTeX) and PDF output for printed books (XeLaTeX).
Once selected, click on “SAVE PROJECT SETTINGS.” Switching between pdfLaTeX and XeLaTeX requires a “recompile from scratch.” If a red error window shows up, select “recompile from scratch.” If all is fine, it should show “up-to-date and saved” and you can proceed with the download.
To download the PDF of the XeLaTeX output, simply click on PDF in the top menu. Done! Your first PDF. This PDF could be used to upload to on-demand book services like Amazon’s KDP. We will discuss this later.
Please note that the PDF will need further polishing, for example to configure what content is shown on the left hand and on the right hand pages. We will discuss issues like this in Chapter 8.
For now, we want the PDF output, so select XeLaTeX.
For now, let us try out the HTML generation. For this, click again on the settings icon on the top right, and in the “Advanced Build Options” right of “LaTeX Engine,” select pdfLaTeX this time, and press “SAVE PROJECT SETTINGS.”
Before continuing, wait until the compilation is finished. A red error message should pop up (if it does not, you can skip to the next paragraph). Simply press “recompile from scratch” and you should be good to go. Wait until the compilation is done and either “warning” or the message “up-to-date and saved” shows up and you can proceed with the download. If you encounter a problem here, feel free to contact me at [email protected]
For downloading the HTML file, you need to have your project window on the left opened (click on “PROJECT” in the menu bar if it is not open). Scroll all the way down to “DOWNLOAD AS ZIP” and click the small arrow near the bottom (see Figure 1.2). Wait until any ongoing compilation is done, then select “Input and Output Files,” and after a short while, a download with the zip archive should start. Extract that zip archive and navigate to the main directory. There, you should find a english.html. Click it and the browser with the book template’s contents should show up.
Convert HTML to Kindle
Now we need one final tool, namely the Kindle Previewer. Go to https://www.amazon.com/gp/feature.html?docId=1000765261 and scroll down to the download links. If the link is not available or if it is broken, simply search for “Amazon Kindle Previewer” in a search engine.
Once downloaded, start the installation, and then start the Kindle Previewer. There, select “File / Open Book” (see Figure 1.3) and browse to the directory where you have unzipped the files of the book. Select english.html and press “Open.” This starts the conversion process.
Depending on the book size, this might take a moment (“Converting your book to Kindle format”). Once finished, a virtual Kindle reader should show up where you can browse through your book. If you are fine with the contents, press “File / Export” in the menu, and press “Export.” A message box should pop up that reads “Book is successfully exported here.” You can safely ignore the warning message “Enhanced Typesetting is enabled for the book being previewed, but it is not supported in the exported file.” This refers only to the fact that any fonts you are using in the HTML file are ignored and replaced by the respective fonts of the e-book reading device.
Now you have a MOBI file we can use later to upload to Amazon’s KDP platform and release it directly as an e-book on Amazon. We will discuss the details later (see Chapter 10), but in essence, that is the entire publishing process, at least from the technical side.
Before you continue: while you are learning LaTeX, you should create a backup whenever your project compiles successfully. You can click on “HISTORY & REVISIONS” (top menu, see Figure 1.4), enter a name of the backup in the “label current version” field, and press “ADD LABEL.”
It is best to name each backup by the milestone you have reached so far so that you later know at what point you have made the backup. For example, after completing polishing the files for an e-book release (but before polishing it for print), you could name it “e-book polishing complete.”
You can recover a previous version by simply clicking again on the “HISTORY & REVISIONS” entry in the top menu, and then click on “restore” in the corresponding line of the previous backup. That being said, you do not have to save as you write. Your latest changes are always saved automatically.
Did you know?
Overleaf really shines in collaboration with another author or your editor. Using labels for different versions can help to speed up the review process significantly. Read more in Writing Better Books, the Agile Way