# Mathematical Formulas, Ebooks, and You

We haven’t solved the Riemann hypothesis, but we have solved how to write mathematical formulas in ebooks. If you’re like so many mathematicians and engineers accustomed to writing your papers in LaTeX, you’ll be happy to know that you’ll be using KaTeX. If you don’t know how to use either, we have a quick hack for you.

Whether you are a middle school teacher teaching logarithms or a Ph.D. student working on the Poincaré conjecture, we’ll show you how to include elegant mathematical formulas in your ebook.

## Getting Started

Since we will be using Kotobee Author to showcase how to add math formulas to your ebooks, we recommend you check our Beginner’s guide to Kotobee Author to get you started with the software, if you haven’t done so already.

Now that you’ve downloaded, installed and become familiar with Kotobee Author, open up a blank ebook and let’s dive into the two ways to add math formulas to your ebook.

## The Quick Hack

If you only want to add a formula or two, then you can quickly add them as images and we’ll show you how. If you will be writing any more than that, then please skip ahead.

What we’ll do is write the formula in an equation editor, then export it as an image. There are many dedicated applications and various online tools, but for the sake of this guide, we will be using CodeCogs’ Equation Editor. It’s free, straightforward and will export a GIF image quickly. If you have another formula editor, then go ahead and use it.

Now with the editor open, write your formula, using the buttons to add symbols. Cryptic symbols will appear in the text area, simply add numbers inside the brackets. The equation will appear below the text box.

See how it looks below the text box. Change the font type and size, if you like. Click on “**Click here to Download Image (GIF)**.” Drag and drop the image into Kotobee, and you’re done.

## The Real Deal

The ideal way to write formulas is as text directly in your ebook. Any ebook creation platform that allows external JavaScript library is all you need (and of course the library). There are several good libraries out there: Math Jax, jsMath, and KaTeX. We will be using for this tutorial KaTeX, which is a JavaScript library for displaying mathematical formulas on web browsers. It is based on LaTeX, which means it loads fast, and you can write mathematical expressions and formulas with LaTeX.

To get KaTeX working on Kotobee Author we can either download the library and add it to the ebook libraries or we can reference the online libraries (note that this will require an internet connection to display the formulas).

If you want your ebook to be read offline, then you will need to download the JS library and add it to your ebook. Here we’ll show you how to do it one of the most famous math books of our time: *Alice’s Adventures in Wonderland*. Charles Dodgson (aka Lewis Carroll) lived in a mathematically turbulent time. A lover of Euclidian geometry when algebra boomed with a renaissance of its own, his story is riddled with mathematical analogies, intended to set mathematicians of the time straight. Before we go too far off on a tangent, let’s return our focus to the center of this article. Follow these simple steps to start writing mathematical expressions in your ebook.

1. Download the KaTeX zip file. (Click to start the download.)

2. Upload three files to Kotobee Author in the **File Manager**.

The downloaded zip folder will contain many files. You will only need three. Once you’re in the **File Manager**, find and import the three files from the downloaded folder into these three locations.

FILENAME |
DESTINATION |

1. katex.min.js | EPUB > JS > katex.min.js |

2. auto-render.min.js | EPUB > JS > contrib > auto-render.min.js |

3. katex.min.css | EPUB > CSS > katex.min.css |

Now that we’ve imported the KaTeX library let’s see how we’re going to use them inside the ebook.

3. Go back to the editor and then go into Source mode to get the HTML of the ebook. Inside the <head> tag we are going to include the libraries we just imported.

<script type="text/javascript" src="../../js/katex.min.js"></script> <script type="text/javascript" src="../../js/auto-render.min.js"></script> <link type="text/css" rel="stylesheet" href="../../css/katex.min.css" /> <script> function ready(){ renderMathInElement(document.getElementById("epubContent") || document.body, {delimiters: [ // mind the order of delimiters(!?) {left: "$", right: "$", display: true}, {left: "$", right: "$", display: false}, {left: "\\[", right: "\\]", display: true}, {left: "\\(", right: "\\)", display: false}, ]}); } </script>

4. To have the equation rendered and not simply show the KaTeX connotations, we will execute the rendering function inside a function called **ready()** and have the body of the HTML run it first by adding **onload=”ready()” **to its tag. So, change the body tag as follows:

<body onload="ready()">

5. To Parse the text inside the editor, add **class=”parsed” **to the paragraph tag. Be certain to include the appropriate tags around your equation \[Your equation\], so the complete tags should look like this example of the integral of sinx with respect to x over the domain of 1 to π:

`<p class="parsed">\[\int_1^\pi \sin x \mathrm{d} x\]</p>`

If you’re not certain how to write your equation in LaTeX format, there are online editors like the one we used above, that will do it for you, so you can just copy-paste the text. In order to view your formula in Kotobee Author, go into the Preview Mode (green button lower right corner).

There it is. Now you’re all set and can add mathematical formulas that are not images, meaning higher efficiency and smaller file sizes.

Kotobee plans to add support for mathematical expressions, but for now, I hope this tutorial helped show you how to get mathematical formulas into your ebook, whether on Kotobee or elsewhere.

*Have an ebook tip, trick, or technique you want to share? Maybe you have an idea for an ebook-related tutorial? Join us in the comments section below to share.*

**Read these posts.**

The Amazing World of Elearning [Infographic]