LaTeX Publishing

Generate Your First E-book

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

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. In another article and the book, we 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 and we will see what we can do!

For general LaTeX questions, you can also check out the community at 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:

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, enter your name and email, confirm the email, and log into your Overleaf account at clicking on Log In.

Copy the Template

If you do not want to use the template, check out the appendix 24 for instructions to add TeX4ht to your existing project.

Once you have your account, copy the template either by visiting or by going to, 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 and click on Projects or go directly to; 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.comProjects) 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.

Figure 12.1: The project settings screen in Overleaf.

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 Chapter 18.

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

Figure 12.2: The zip file with the HTML output can be downloaded in the “Logs and output files” screen at the very bottom.

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 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 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.

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, 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, 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 Chapter 20), 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 (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.

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 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.

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

Editing LaTeX Publishing Uncategorized

Comparing Word and LaTeX

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

What is magic for? What use is wizardry if it cannot save a unicorn?

Peter S. Beagle, The Last Unicorn [Beagle1991, cf. p. 187f]

Having written six books on topics including project management and philosophy, I have gained a great deal of respect for a well-written book. It is not enough to just have a stack of notes that you sort into chapters. It is not enough to spend a lot of time editing and organizing those notes. It will create a book, but is a book really what you wanted? It might sound a bit strange, but the goal of writing a book is not the book itself. It is that the book will be read.

Even the best technologies cannot save a unicorn—or make us better authors. They cannot tell us what to write. But they can help us to bring our imagination and ideas onto paper more quickly and efficiently. All you need to become a successful author is your mind, a pen, and paper. Everything you need to become a published author more quickly is in the following chapters.

Comparing Word and LaTeX

Everyone knows Word. However, “knowing” Word mostly refers to ease of use, as it is a “what you see is what you get” (WYSIWYG) text editor. But if I asked how, using Word, to refer to another document’s text block and add that as a citation in a footnote, most people would have to look on the Internet to find out how that could be done. While most of the functionality is available through icons, you still need to know where to look when something is not a standard command like those used in formatting, making lists, or choosing fonts.

Word ⋅  Word usually refers to Microsoft Word. Generally, it is used as an umbrella term for all word processors that directly show you what you will get as an end result (as opposed to first having to process the file). This approach is more intuitive, but it makes editing large projects very complicated.

In LaTeX (pronounced LAH-tekh or LAY-tekh), you instead create a text document which is then translated into an actual formatted document (your book). Formatting is done through commands you enter as text into the document. To write a LaTeX document, you never have to touch your mouse, as you can enter everything by keystrokes alone.

LaTeX ⋅  LaTeX is a typesetting system that works more like a compiler than a word processor. While initially complicated, LaTeX allows better management of larger projects like theses or books by splitting the document into sections: style, references, and text.

Word and LaTeX each have particular advantages:

If you know the commands, creating a LaTeX document will be quicker than writing a Word document. You never have to break your concentration to access a special command. Sure, there are shortcuts in Word, too, but those have to be learned as well.

Because all commands are part of a LaTeX document, you can edit your text on any device with any editor you like, while Word documents require an installed editor (well, Word) that does not show the formatting and control information.

The upside of Word is its automated grammar check. LaTeX online platforms like Overleaf provide spell checks, but no integrated grammar check. We will have to wait for future releases in that regard.

Word offers integrated basic graphic functionality for symbols while LaTeX has to rely on a rather complicated vector graphics engine.

Editing a Word document using different versions of the software might lead to compatibility problems and it will certainly not look the same in all versions. While there are collaborative online editors for Word, you are then on the same level as LaTeX online editors like Overleaf and you lose the ability to work on your document while on the road without Internet connectivity. Compatibility issues are especially problematic if you are co-authoring a book or working with an editor, or when relying on exact page numbers. Do not forget that books can exist for quite a long time. Will your Word file still work in 10 or 20 years when it’s time to release a new edition of your book or use parts of your book in a new book or article?

LaTeX’ more substantial post-processing of each change allows for much more complex algorithms, which provide you with better hyphenation and professional-looking typography—both features come out of the box and require little to no tweaking. In LaTeX, the document is processed in the background with a delay (a few seconds up to several minutes), while Word has to provide any change in real time, which requires that editing is optimized primarily for speed. While LaTeX updates the whole document with each committed change, you need to update some elements manually in Word (for example, the table of contents and the index).

In LaTeX, an element of the style of the entire document can be changed with a single line of code, while it takes 10 clicks in Word to change the style of a document. While Word does have a sophisticated versioning system, this applies only to the text itself. The style information (for example, the formatting of headers or footers) in Word is not part of the visible document. Hence, changes to the style are not directly visible in the document version history.

Versioning system ⋅  A versioning system is a tool to track changes to a document. That means you can go back and check what has been changed and by whom.

If your document contains graphics, processing Word files can become really slow, or the program might even crash. Why? Because while you are editing, all the images have to be cached somewhere, which takes a lot of memory. When editing LaTeX documents, images in the editor are visible only by their text reference and are only later—one by one—compiled into a PDF or e-book.

LaTeX is known for its beautiful typography. For example, it supports kerning (see Figure 11.1) and ligatures (see Figure 11.2), giving a typeface its finishing touch. Improved hyphenation, proper small caps, and proper justification are other features LaTeX offers that Word cannot do as well or without additional work.

Figure 11.1: Example of applying kerning to a typeface.
Figure 11.2: Example of a ligature.

While Word has several tools inbuilt that support multiple languages (dictionary, basic grammar check, special characters, etc.), it is not designed to handle multiple languages at the same time. If you want to produce, for example, a German and an English version of your book, the best advice would be to use two separate documents and translate and compare them paragraph by paragraph. In LaTeX, a single document can contain multiple languages. To create a multi-language project, you can put each paragraph of the second (or third) language below the original language. This makes translation work more manageable and reduces work for synchronization when making revisions. This is possible by a simple switch command that uses all entries marked with either one language or with another.

In LaTeX, you can add functionality to switch between e-book and print output without having to manage two separate documents. For example, my Philosophy for Heroes: Knowledge project produces four output files: the German e-book, the English e-book, the German PDF, and the English PDF. Even if your ultimate goal is to focus on the printed version of your book, merely having a more affordable e-book version will help to increase sales as it gives your readers a choice. Those who do not have a preference about reading your book in print or as an e-book might opt for the cheaper version rather than not buying your book at all.

Because LaTeX documents are compiled, you have the option to build your document not as one huge file like in Word, but as a collection of many files. As mentioned above regarding images, you can also include text files at any part of the document (as opposed to copying the whole text into one huge file). This makes it easier to divide the work and proceed section by section, as opposed to having to locate the part you are currently working on each time you open the document. It also makes rearranging sections easier: you no longer have to copy and paste pages over pages (never being sure if you have successfully copied everything and nothing was lost). Instead, you just move the reference to a section to another place. For example, let us assume you write a book about dogs and cats and first discuss dogs, then cats. In LaTeX, you would put each discussion into a separate file, and include them into your main file like this:


Moving your discussion about cats to the front is done by simply switching the position in the main file:


If your document contains formulas, LaTeX provides an entire scientific library of functions to edit and display them directly in the document. While you can create basic formulas in Word, for any complex mathematics you need to use a separate program to create and embed an image. Likewise, especially non-fiction books rely heavily on citation. To manage your sources in Word, you need a separate plugin or third-party program (like Citavi), while LaTeX supports the most widely used standard BibTeX for free, with no plugins required.

Citavi ⋅  Citavi is a plugin for Word (see to manage your bibliography and citations.

LaTeX is open source and free (even the online editor Overleaf is free if you can do without password protection), while you have to pay license costs for Word.

Figure 11.3: Comparison of Word and LaTeX depending on the complexity of the task: for natural sciences, anything more complex than articles takes more effort in Word; for social sciences, anything more complex than papers takes more effort in Word; for novels, book series take more effort in Word than in LaTeX.

Ultimately, it depends on your needs. If you want to write a complex document like a book, the advantages of LaTeX outweigh those of Word. If you want to quickly write a few pages, Word is superior. For longer and more complex books, LaTeX takes less effort (see Figure 11.3). In this book, I will help you to get your book done and published with LaTeX using the free template provided with the book.

Editor“what you see is what you get”source file is compiled
Compatibilitydependent on editorindependent of editor
Graphicssimple inbuilt editor, mouse-basedpowerful but complex editor, text-based
Typographyoptimized for speedoptimized for quality
Styleinbuilt styleseparate style document
Multi-platformonly via exportpossible with scripting
Refreshsome elements need manual refresheverything is refreshed with each compile
Formulasbasic support needs external toolscomplete support
Figure 11.4:Comparison of Word and LaTeX