Debian Codegraph @

manual/typesetting_math.rst

raw
1 .. _typesetting_math:
2
3
4 Typesetting mathematics in e-books
5 ====================================
6
7 The calibre E-book viewer has the ability to display mathematics embedded in e-books
8 (EPUB and HTML files). You can typeset the mathematics directly with TeX or MathML or
9 AsciiMath. The calibre E-book viewer uses the excellent `MathJax
10 <https://www.mathjax.org>`_ library to do this. This is a brief tutorial on
11 creating e-books with mathematics in them that work well with the calibre E-book viewer.
12
13
14 A simple HTML file with mathematics
15 -------------------------------------
16
17 You can write mathematics inline inside a simple HTML file and the calibre E-book viewer
18 will render it into properly typeset mathematics. In the example below, we use
19 TeX notation for mathematics. You will see that you can use normal TeX
20 commands, with the small caveat that ampersands and less than and greater than
21 signs have to be written as &amp; &lt; and &gt; respectively.
22
23 The first step is to tell calibre that this will contain mathematics. You do this by
24 adding the following snippet of code to the <head> section of the HTML file::
25
26 <script type="text/x-mathjax-config"></script>
27
28 That's it, now you can type mathematics just as you would in a .tex file. For
29 example, here are the Lorenz equations::
30
31 <h2>The Lorenz Equations</h2>
32
33 <p>
34 \begin{align}
35 \dot{x} &amp; = \sigma(y-x) \\
36 \dot{y} &amp; = \rho x - y - xz \\
37 \dot{z} &amp; = -\beta z + xy
38 \end{align}
39 </p>
40
41 This snippet looks like the following screen shot in the calibre E-book viewer.
42
43 .. figure:: images/lorentz.png
44 :align: center
45
46 :guilabel:`The Lorenz Equations`
47
48 The complete HTML file, with more equations and inline mathematics is
49 reproduced below. You can convert this HTML file to EPUB in calibre to end up
50 with an e-book you can distribute easily to other people.
51
52 .. only:: online
53
54 Here is the generated EPUB file: `mathjax.epub <_static/mathjax.epub>`_.
55
56 .. literalinclude:: mathjax.html
57 :language: html
58
59 .. note:: The calibre E-book viewer supports MathML as well as TeX, but you must
60 include the ``<script type="text/x-mathjax-config"></script>`` line in
61 your HTML file otherwise the MathML will not render.
62
63 More information
64 -----------------
65
66 Since the calibre E-book viewer uses the MathJax library to render mathematics, the best
67 place to find out more about mathematics in e-books and get help is the `MathJax
68 website <https://www.mathjax.org>`_.