*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 LaTeXismore 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 [email protected] 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⋅Overleafis 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 tohttps://www.overleaf.com/register, enter your name and email, confirm the email, and log into your Overleaf account at https://www.overleaf.comclicking onLog In.
Copy the Template
*If you do not want to use the template, check out this articleto add TeX4ht to your existing project.
Once you have your account, copy the template either by visiting/template/or by going tohttps://www.overleaf.com/latex/templates, searching forBook Template for Amazon KDP, Google Play, and Leanpub, and openingBook Template for Amazon KDP, Google Play, and Leanpub (e-book and PDF)and pressingOpen 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 tohttps://www.overleaf.comand click onProjectsor go directly tohttps://www.overleaf.com/project); your new project should be listed there.
The template itself needs to be adapted of course—after all, it isyourbook, 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 projectBook Template for Amazon KDP, Google Play, and Leanpub. In the opened window, you should see a menu bar at the top with theMenubutton 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.**Figure 12.1:**The project settings screen in Overleaf.
For now, click on theMenubutton at the top left. A new panel shows up (see Figure 12.1). In theSettingssection, click on the drop-down menu right ofCompiler.
pdfLaTeX⋅pdfLaTeXis a basic LaTeX typesetting engine that translates LaTeX documents directly into PDFs or HTML files (with the help ofTeX4ht).
XeLaTeX⋅XeLaTeXis a LaTeX typesetting engine with an extended font, as well as UTF-8 encoding (for special characters) support. It takes longer to compile withXeLaTeXthan the more basicpdfLaTeX.
For now, we want the PDF output, so selectXeLaTeX.
Switching here betweenpdfLaTeXandXeLaTeXallows 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 onRecompilein the menu above the preview window on the right. If the compilation did not work, the document icon to the right ofRecompilewill 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 theXeLaTeXoutput, simply click on the third symbol (Download PDF, the second symbol to the right ofRecompilein the PDF view). You can also click onMenuon the top left, and click onPDF. 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 theMenubutton at the top left, and this time, selectpdfLaTeXin theSettingssection, in the drop-down menu to the right ofCompiler. Then, pressRecompilein 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 besideRecompile), feel free to contact me at [email protected].**Figure 12.1:**The project settings screen in Overleaf.
Convert HTML to Kindle
For downloading the e-book, you have to actually download all the output files (clicking on theLogs and output filesicon at the top of the right window, scrolling all the way down toOther logs & files, and selecting theallfiles.zipentry, 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 anoutput.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 theoutput.txt. If you cannot make sense of it, just let us know, we can help!
Now we need one final tool, namely theKindle Previewer. Go tohttps://www.amazon.com/gp/feature.html?docId=1000765261and scroll down to the download links. If the link is not available or if it is broken, simply search forAmazon Kindle Previewerusing a search engine.
Once downloaded, start the installation, and then start the Kindle Previewer. There, selectFile / Open Book(see Figure 12.3) and browse to the directory where you have unzipped the files of the book. Selectoutput.htmland pressOpen. This starts the conversion process.**Figure 12.3:**Importing the HTML file in Kindle Previewer to convert it into a MOBI format.
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, pressFile / Exportin the menu, and pressExport. 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 onHistory(top menu, see Figure 12.4), then onAll history, then onView single version, then onLabel this version, then enter a name for the backup.**Figure 12.4:**Setting the name of the current version of the book for later reference.
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 onHistory, then onCompare to another version, then onLabels, 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.