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, we will go step by step through the process of copying your book from your text source (e.g., Word) to the template.
LaTeX Support
While we have tested the template that comes with this book several times, you will likely encounter an issue not discussed here. Creating a document in LaTeX is more complex than doing so in Word, but even in Word there are issues you might run into where the solution is not immediately apparent.
If you encounter any error or have a question about LaTeX as it is used in the template, please do not hesitate to contact us. The question and the answer might be added to an FAQ for other readers to solve their problems. We offer free support if you provide us with a link to your Overleaf project. For major changes, one of our LaTeX developers can help you out at an affordable rate. But most issues can probably be solved immediately and at no cost (“You forgot to close the parentheses,” “You need to load package X,” “Your graphics file is corrupt,” etc.). Simply contact us at mail@lode.de and we will see what we can do!
For general LaTeX questions, you can also check out the community at https://tex.stackexchange.com. If you post a brief (but working) example with LaTeX code with which you are having a problem, the community can usually provide high-quality advice.
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 for writing this very book (and all my other books). Overleaf is an online editor and project manager for LaTeX documents. It is available free for projects that do not require password protection. If you want to keep your LaTeX code private, I recommend the Pro upgrade which also adds full project history, access management, support for larger projects, and priority support.
Overleaf ⋅ Overleaf is an online editor and project manager for LaTeX documents. It manages your project with a versioning system and automatically compiles your LaTeX code into PDF and (with some help) HTML. It is free for public projects and does not require an installation or setup. You can get an account here: https://www.overleaf.com.
Overleaf requires no installation. Just register an account, 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 required. To register an account on Overleaf, simply go to https://www.overleaf.com/register, enter your name and email, confirm the email, and log into your Overleaf account at https://www.overleaf.com clicking on Log In.
Copy the Template
If you do not want to use the template, check out this article to add TeX4ht to your existing project.
Once you have your account, copy 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, Google Play, and Leanpub, and opening Book Template for Amazon KDP, Google Play, and Leanpub (e-book and PDF) and pressing Open as Template.
Once copied, any changes to the template will be applied to your own copy. It is accessible via your Overleaf project view (go to https://www.overleaf.com and click on Projects or go directly to https://www.overleaf.com/project); 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, Projects) and click on the new project Book Template for Amazon KDP, Google Play, and Leanpub. In the opened window, you should see a menu bar at the top with the Menu button that opens the options for the project. 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.
Create a PDF
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 Menu button at the top left. A new panel shows up (see Figure 12.1). In the Settings section, click on the drop-down menu right of Compiler.
pdfLaTeX ⋅ pdfLaTeX is a basic LaTeX typesetting engine that translates LaTeX documents directly into PDFs or HTML files (with the help of TeX4ht).
XeLaTeX ⋅ XeLaTeX is a LaTeX typesetting engine with an extended font, as well as UTF-8 encoding (for special characters) support. It takes longer to compile with XeLaTeX than the more basic pdfLaTeX.
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) but requires you to recompile your project. For this, click on Recompile in the menu above the preview window on the right. If the compilation did not work, the document icon to the right of Recompile will show a red box with the number of errors and warnings. If no number is shown or if there are only warnings (yellow box), you can proceed with the download.
To download the PDF of the XeLaTeX output, simply click on the third symbol (Download PDF, the second symbol to the right of Recompile in the PDF view). You can also click on Menu on the top left, and click on PDF. Done! Your first PDF. This PDF could be used to upload to on-demand book services like Amazon’s KDP.
Please note that the PDF will need further polishing, such as configuring what content is shown on the left-side and on the right-side pages. We will discuss issues like this in this article.
Create HTML Output
For now, let us try out the HTML generation. For this, click on the Menu button at the top left, and this time, select pdfLaTeX in the Settings section, in the drop-down menu to the right of Compiler. Then, press Recompile in the right panel. Before continuing, wait until the compilation is finished. If you encounter a problem here (and a little red box with a number appears on the document icon right beside Recompile), feel free to contact me at mail@lode.de.
Convert HTML to Kindle
For downloading the e-book, you have to actually download all the output files (clicking on the Logs and output files icon at the top of the right window, scrolling all the way down to Other logs & files, and selecting the allfiles.zip entry, see Figure 12.2). A download with the zip archive should start now. After downloading, extract that zip archive, and navigate to the main directory. There, you should find an output.html. That is your converted LaTeX document! Click it and the browser with the book template’s contents should show up. You can now easily copy and paste the whole document or parts of it into, for example, a WordPress post and publish it online. If there is no HTML file, double-check for any errors within Overleaf and check the output.txt. If you cannot make sense of it, just let us know, we can help!
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 using a search engine.
Once downloaded, start the installation, and then start the Kindle Previewer. There, select File / Open Book (see Figure 12.3) and browse to the directory where you have unzipped the files of the book. Select output.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 how the contents look, press File / Export in the menu, and press Export. For the name of the exported file, I recommend including the current date to prevent confusion when uploading (for example, bbwltaw-09032019.mobi). 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 that you 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 here), but in essence, that is the entire publishing process, at least from the technical side.
Versioning
Before you continue: while you are learning LaTeX, you should create a backup whenever your project compiles successfully. You can click on History (top menu, see Figure 12.4), then on All history, then on View single version, then on Label this version, then enter a name for the backup.
It is best to name each backup by the milestone you have reached so that you later know at what point you have made the backup. For example, after polishing the files for an e-book release (but before polishing it for print), you could name it “e-book polishing complete.”
You can always go back to a previous version and compare the changes you have made. Click on History, then on Compare to another version, then on Labels, and then on a file in the list on the left side with a note “edited” right beside it. That being said, you do not have to save as you write. Your latest changes are always saved automatically.