Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 08-17-2012, 05:02 AM   #1
vri
Junior Member
vri began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Aug 2012
Device: none
epub and mathjax

for a great piece of ebook software!

I use sphinx to create an ebook with mathematical equations. If I include a link to the Mathjax script at Mathjax CDN in the head of the html file that contains the equations, Calibre renders it beautifully.
However, this requires an internet connection. I can make a link to a local install, but then it will not work for others.

The natural solution I see is to let Calibre know somehow where it can find mathjax and to have it available by default. I have searched the forums etc, but it seems that no-one else has addressed this, right?

I have no experience at all in Calibre; what would be the easiest way to accomplish this? A recipe? A plugin? Add it to resources somehow?

Any help would be appreciated.

Cheers, Theo
vri is offline   Reply With Quote
Old 08-17-2012, 05:08 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Why not have both a link to a local version and the link to the version in the CDN? In fact you can use something like require.js to load the appropriate version dynamically.
kovidgoyal is offline   Reply With Quote
Advert
Old 08-17-2012, 05:24 AM   #3
vri
Junior Member
vri began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Aug 2012
Device: none
Well, the problem with a local version is that the location depends on the OS.
Distributing mathjax with the epub is not attractive, as it is quite big.

So that is why I thought that I could maybe configure a path for mathjax or so in Calibre and have Calibre look for it in that way. Or is this the wrong direction?
vri is offline   Reply With Quote
Old 08-17-2012, 07:39 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Then you'd have to ensure every calibre user you send the book to has the mathjax module installed. Better to just distribute it witht he epub. Files in an epub are compressed.
kovidgoyal is offline   Reply With Quote
Old 08-17-2012, 08:28 AM   #5
vri
Junior Member
vri began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Aug 2012
Device: none
Thanks for thinking along!
As far as I can see, a zipped mathjax is 17.6 MB! So I really do not want to distribute that with an epub.
I could use CDN as default (which would also imply users always get the latest version), and require a plugin or something the like to be installed for offline rendering.
For my own purposes, it is no problem to ask readers to do a local install.

But would the general user not be interested to have equations rendered off-line, you think? So an installed plugin could offer that?
vri is offline   Reply With Quote
Advert
Old 08-17-2012, 08:51 AM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
The ebook viewer has no plugin architecture at all, so first someone would have to develop that. Not particularly difficult, but still, it has to be done.

The viewer is based on WebKit so it probably supports the HTML 5 offline APIs. So another approach would be to see if you can use those to enable offline viewing after an initial online view.
kovidgoyal is offline   Reply With Quote
Old 08-17-2012, 09:21 AM   #7
vri
Junior Member
vri began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Aug 2012
Device: none
Ok, now I understand the problem better. I feel too unexperienced to start on a plugin architecture for the viewer. I'll check out HTML 5 offline API's. Thanks.
vri is offline   Reply With Quote
Old 08-17-2012, 10:36 AM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I had a few minutes so I added a framework for viewer plugins.

http://bazaar.launchpad.net/~kovid/c...revision/12969

At the moment they are very limited (they can only load fonts and load javascript) but that should be enough for mathjax.
kovidgoyal is offline   Reply With Quote
Old 08-17-2012, 11:19 AM   #9
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
And I had a look at the mathjax package and the vast majority of its size comes from the png versions of every mathematical symbol. These should not be needed for the calibre viewer, as you can just use the OTF fonts. If you remove the png fonts, the package size should be under 1 MB zipped up.
kovidgoyal is offline   Reply With Quote
Old 08-17-2012, 12:18 PM   #10
vri
Junior Member
vri began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Aug 2012
Device: none
Man, you are fabulous!

Meanwhile, I found this post about slimming down MathJax along the lines that you indicated:
http://boolesrings.org/krautzberger/...other-attempt/

I will work on this some more and get back..

Cheers, Theo
vri is offline   Reply With Quote
Old 08-17-2012, 01:51 PM   #11
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Just for completeness attached is a basic mathjax plugin and a sample epub file it works on. I only tested it on my machine, so it may be that it needs more fonts in the bundle. Also in a production quality plugin you shoud scan for a

<meta name="calibre-enable-mathjax" value="input/TeX" />

tag and only load mathjax if it is present, with the correct input filter as per the value. Zipped up, the plugin is only 2.7MB, so if you can refine it a bit and test it on a few more machines, I might be willing to add it to calibre.

NOTE that you have to be running calibre from trunk for this plugin to work and you may have trouble with file paths on windows, I only tested it on linux.
Attached Files
File Type: zip MathJax Plugin.zip (2.67 MB, 388 views)
File Type: epub sample.epub (149.8 KB, 498 views)
kovidgoyal is offline   Reply With Quote
Old 08-17-2012, 02:11 PM   #12
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
It seems to work for me even without the svg fonts, which will knock another MB off the size. Attached is plugin without those fonts. Maybe its because my machine already has the STIX fonts installed, needs to be tested on some other machine.
Attached Files
File Type: zip MathJax Plugin.zip (1.55 MB, 385 views)
kovidgoyal is offline   Reply With Quote
Old 08-17-2012, 06:51 PM   #13
pkra
Junior Member
pkra began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Aug 2012
Device: all
Hi,

Very cool to see a plugin happening -- Calibre is a great tool!

@kovidgoyal: since you activated SVG output, you won't need STIX or any fonts (the SVG fonts are webfonts that certain old browsers understand, SVG-rendering is different). But you should definitely add MathML-input to the configuration you're creating (and why not asciimath notation as well?) The point being that the standard for math in epub3 is MathML, both practically (the only thing epub3 reading systems are required to understand) and conceptually (ensuring accessibility etc). This may seem moot in a time where no reading system renders MathML 100%, but it's still the right thing to do imho. Since the OP is coming from a shinx/reST-setup, it should be possible to properly translate the math into MathML in the conversion process (not sure the sphinx people are working on that but pandoc goes a long way).

For what it's worth, here's the semi-official guide to shrinking MathJax in general:

https://github.com/mathjax/MathJax/w...2-installation

We're working on a better guide to include in the official MathJax documentation (mathjax.org/docs).

I should point out that my old blog post linked to above is outdated and the example files won't even work. However, the result is still possible, i.e., you can include a shrunk MathJax inside your epub file and it will render in javavscript-enabled readers such as Calibre and iBooks. (I do plan to update that post soon...) A very good start is to simply check out the MathJax code included in Readium (in particular, the MathJax configuration file they use)

One last thing, we created a resource on epub3 reading systems and MathML at http://www.mathjax.org/resources/epub-readers/ -- any help and comments are very welcome there!
pkra is offline   Reply With Quote
Old 08-18-2012, 12:07 AM   #14
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Thanks, its good to have someone familiar with mathjax internals to help. Some questions:

1) Can we use the unpacked javascript? I much prefer using unpacked javascript as it allows easier debugging and local modifications.

2) Are there any other config options apart from imageFonts:null to use to suppress warnings with svg output and no fonts? Though looking at the code, it seems like imageFonts is no longer needed.

3) What would be a good way of allowing the user to specify parts of the config via a script tag in the document while still setting most of it in calibre code. I suppose I could define my own config function, but I was hoping that there exists a canonical way to do it.

4) For some reason, none of the right click menu entries work in the calibre viewer.

4.5) Is there a config option that will allow mathjax to log errors using console.log? This makes debugging easier.

5) The HTML/CSS output and the right click menus dont work with calibre's viewer in paged mode. This is because the paged mode is implemented using the CSS3 columns module, which causes all the CSS positioning you use to break. You could probably fix that by using getBoundingClientRect to calculate positions rather than the usual offsetParent techniques.

6) Equations do not reflow when the viewer window is too narrow for them, I assume that's by design? I see the same behavior in Chrome with both html/css output and svg output

Last edited by kovidgoyal; 08-18-2012 at 12:45 AM.
kovidgoyal is offline   Reply With Quote
Old 08-18-2012, 06:24 AM   #15
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I've added mathjax to the calibre viewer. Here's the config

Code:
        MathJax.Hub.Config({
            positionToHash: false,
            showMathMenu: false,
            extensions: ["tex2jax.js","asciimath2jax.js","mml2jax.js"],
            jax: ["input/TeX","input/MathML","input/AsciiMath","output/SVG"]
                });
I had to disable the menus because of the aforementioned paged mode issue.
kovidgoyal is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
epub to epub conversion problem with regex spanning multiple input files ctop Conversion 2 02-12-2012 01:56 AM
HTML containing mathjax to MOBI? kongzifan Conversion 2 12-10-2011 05:13 AM
[Old Thread] Reading epub on viewer inexplicably changes the time stamp of epub greenapple Library Management 20 03-19-2011 10:18 PM
epub, ePub, EPUB, warum blos ePub? flowoeB Lounge 5 11-27-2009 09:37 AM


All times are GMT -4. The time now is 05:39 AM.


MobileRead.com is a privately owned, operated and funded community.