In the early days of math-blogging, one was happy to get LaTeXRender working. Some years later, the majority of math-blogs were using the, more user-friendly, wp-latex plugin to turn LaTeX-code into png-images. Today, everyone uses MathJax which works with modern CSS and web fonts instead of equation images, so equations scale with surrounding text at all zoom levels.

However, MathJax has one downside : it doesn’t parse in ePub-readers. Peter Krautzberger wrote a post Epub and mathematics in which he suggested two methods to turn MathJax into ePub, but after dozens of experiments I still fail to reproduce these.

No doubt, someone will soon come up with a working alternative, but for the impatient here’s a quick but dirty method to turn your MathJax powered wordpress post into ePub :

the tools

• download and install the ePub export plugin. It automatically creates an ePub file when a post or page is published or updated. The ePubs are stored in the uploads directory (to be found in the wp-contents directory).
• download and install the wp-latex plugin. MathJax uses the normal \$tex-delimeters whereas wp-latex requires \$latex, so this plugin doesn’t interfere with the default use of MathJax.
• download the wp2latex python script. It converts a standard LaTeX file into a format that is ready to be copied into WordPress.

the routine

• Edit the post you want to convert to ePub. Copy the contents of the post box to a file say post1.tex and save this in the same directory containing the latex2wp.py script.
• In Terminal go to that directory and type the command ‘python latex2wp.py post1.tex’. It will produce a new file post1 in the same directory.
• Copy the contents of post1 into the post box of your WordPress-post and press the update button. This time the TeX-commands in your post will be rendered using wp-latex and the ePub export-plugin will have created an ePub-version of it.
• Locate this newly created ePub file in the relevant wp-contents/uploads/ folder (file has a number.epub name) and, if wanted, change its name into something easier to recognize and copy it somewhere outside the uploads directory. This will be your desired ePub-version of the post.
• Replace the contents of the post box of your WordPress-post with the contents of the post1.tex file and hit the ‘Update’ button, to restore your original post (powered by MathJax).
• Email your ePub-file to your iPad and open it with iBooks. Not quite as nice as MathJax-parsed TeX but a lot better than reading unparsed TeX-commands.

Published in web