diff --git a/manual/images/lorentz.png b/manual/images/lorentz.png new file mode 100644 index 0000000000..4b261dde38 Binary files /dev/null and b/manual/images/lorentz.png differ diff --git a/manual/mathjax.html b/manual/mathjax.html new file mode 100644 index 0000000000..0716b36f21 --- /dev/null +++ b/manual/mathjax.html @@ -0,0 +1,100 @@ + + + +
++ ++ + + diff --git a/manual/resources/mathjax.epub b/manual/resources/mathjax.epub new file mode 100644 index 0000000000..417c038cc9 Binary files /dev/null and b/manual/resources/mathjax.epub differ diff --git a/manual/tutorials.rst b/manual/tutorials.rst index dd41c730b0..420c1a4cbd 100755 --- a/manual/tutorials.rst +++ b/manual/tutorials.rst @@ -18,4 +18,5 @@ Here you will find tutorials to get you started using |app|'s more advanced feat regexp server creating_plugins + typesetting_math diff --git a/manual/typesetting_math.rst b/manual/typesetting_math.rst new file mode 100644 index 0000000000..6dae41a106 --- /dev/null +++ b/manual/typesetting_math.rst @@ -0,0 +1,57 @@ + +.. include:: global.rst + +.. _typesetting_math: + + +Typesetting Math in ebooks +============================ + +The |app| ebook viewer has the ability to display math embedded in ebooks (ePuB +and HTML files). You can typeset the math directly with TeX or MathML or +AsciiMath. The |app| viewer uses the excellent `MathJax +The Lorenz Equations
+ ++\begin{align} +\dot{x} & = \sigma(y-x) \\ +\dot{y} & = \rho x - y - xz \\ +\dot{z} & = -\beta z + xy +\end{align} +
+ +The Cauchy-Schwarz Inequality
+ +\[ +\left( \sum_{k=1}^n a_k b_k \right)^{\!\!2} \leq + \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right) +\]
+ +A Cross Product Formula
+ +\[ + \mathbf{V}_1 \times \mathbf{V}_2 = + \begin{vmatrix} + \mathbf{i} & \mathbf{j} & \mathbf{k} \\ + \frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\ + \frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 \\ + \end{vmatrix} +\]
+ +The probability of getting \(k\) heads when flipping \(n\) coins is:
+ +\[P(E) = {n \choose k} p^k (1-p)^{ n-k} \]
+ +An Identity of Ramanujan
+ +\[ + \frac{1}{(\sqrt{\phi \sqrt{5}}-\phi) e^{\frac25 \pi}} = + 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} + {1+\frac{e^{-8\pi}} {1+\ldots} } } } +\]
+ +A Rogers-Ramanujan Identity
+ +\[ + 1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots = + \prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, + \quad\quad \text{for $|q|<1$}. +\]
+ +Maxwell's Equations
+ ++\begin{align} + \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ + \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ + \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ + \nabla \cdot \vec{\mathbf{B}} & = 0 +\end{align} +
+ +In-line Mathematics
+ +Finally, while display equations look good for a page of samples, the +ability to mix math and text in a paragraph is also important. This +expression \(\sqrt{3x-1}+(1+x)^2\) is an example of an inline equation. As +you see, equations can be used this way as well, without unduly +disturbing the spacing between lines.
+ + +
+ \begin{align} + \dot{x} & = \sigma(y-x) \\ + \dot{y} & = \rho x - y - xz \\ + \dot{z} & = -\beta z + xy + \end{align} +
+ +This snippet looks like the following screen shot in the |app| viewer. + +.. figure:: images/lorentz.png + :align: center + + :guilabel:`The Lorentz Equations` + +The complete HTML file, with more equations and inline mathematics is +reproduced below. Also, a link the EPUB version, generated by converting the +HTML file to EPUB in |app|: `mathjax.epub <_static/mathjax.epub>`_. + +.. literalinclude:: mathjax.html + :language: html + :emphasize-lines: 8,9,29-38 + diff --git a/src/calibre/ebooks/conversion/plugins/epub_output.py b/src/calibre/ebooks/conversion/plugins/epub_output.py index be5a1ab4a1..48ee28be6e 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_output.py +++ b/src/calibre/ebooks/conversion/plugins/epub_output.py @@ -388,7 +388,8 @@ class EPUBOutput(OutputFormatPlugin): if not tag.text: tag.getparent().remove(tag) for tag in XPath('//h:script')(root): - if not tag.text and not tag.get('src', False): + if (not tag.text and not tag.get('src', False) and + tag.get('type', None) != 'text/x-mathjax-config'): tag.getparent().remove(tag) for tag in XPath('//h:body/descendant::h:script')(root): tag.getparent().remove(tag)