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

 MobileRead Forums Bug in Preview with epubs that contain MathML equations?

06-14-2021, 09:49 AM   #1
RbnJrg
Wizard

Posts: 1,210
Karma: 4155811
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Bug in Preview with epubs that contain MathML equations?

I know that, in Sigil 1.6, Preview is now totally asynchronousis but even so, when someone does click with the mouse somewhere in CodeView, Preview scrolls to show the same text clicked in the source code. Well, nothing of that happens with the epub I attach; no matter the place where I do click in Codeview that Preview remains always in the same place (at the beggining of the file). It seems that something is broken when the epub has MathML equations.

By the way, I don't know why Bibi Reader can't open this epub.

Regards
Rubén

EDIT: The attached epub passes Epubcheck.
Attached Files
 MathML Case.epub (4.0 KB, 21 views)

 06-14-2021, 10:32 AM #2 KevinH Sigil Developer   Posts: 5,518 Karma: 3513158 Join Date: Nov 2009 Device: many I just tested it and had no trouble at all but you have to understand one thing: Clicking inside a mathml equation in CV or clicking inside an equation in Preview can *never* work. Neither actually exists in the other. Inside Preview MathJax replaces the mathml with inline svg of the image. So when you click in CV inside a mathml tags there is no equivalent node in the DOM inside of Preview. When in Preview and you click inside an mathml equation, you are clicking in an svg image that has no correspondence in CV. To use Sigil to navigate by clicking in CV and PV, simply click on any non-mathml element that will exist in both and they will sync. That is just a limitation of how MathJax works. As for BibiReader and MathJax, you probably have to load it in the extensions folder inside bibi since bibi itself does not come with or support mathjax. This is why I really wanted true mathml support in browsers but when Chrome decided to drop it, and replace it with a polyfill kludge (ie. MathJax) it really hurts. As few browsers support true mathml and even fewer support the mml3 extensions (which is what that test case is testing). If you check it out in calibre which uses Mathjax 3 + you will see much of that testcase is broken because even MathJax in its 3.X versions dropped mml3 support which will hopefully be soon added back. Last edited by KevinH; 06-14-2021 at 10:37 AM.
 06-14-2021, 10:50 AM #3 DiapDealer Grand Sorcerer     Posts: 24,250 Karma: 163636384 Join Date: Jan 2010 Device: Nexus 7, Kindle Fire HD I'm having trouble on Windows getting it to sync properly (either direction) even when clicking only the html elements. Clicking in the h tags in Code View does not take me to that section in Preview.
06-14-2021, 10:56 AM   #4
RbnJrg
Wizard

Posts: 1,210
Karma: 4155811
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
 Originally Posted by KevinH To use Sigil to navigate by clicking in CV and PV, simply click on any non-mathml element that will exist in both and they will sync. That is just a limitation of how MathJax works.
Thanks for your answer Kevin. I did what you say, but even so CV and PV don't sync. Do the following:

1. Open in Sigil MathML Case.
2. In CV, go at the end of the sheet, where you read:

Code:
<h2>Multiscripts, Under-over, Greek and Gothic alphabets</h2>
and do click here; you'll see that nothing happens in PV, it remains at the start of the view. At least, that is what happens in my Windows system.

Quote:
 As for BibiReader and MathJax, you probably have to load it in the extensions folder inside bibi since bibi itself does not come with or support mathjax.
Ok; understood

Last edited by RbnJrg; 06-14-2021 at 10:59 AM.

06-14-2021, 10:58 AM   #5
RbnJrg
Wizard

Posts: 1,210
Karma: 4155811
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
 Originally Posted by DiapDealer I'm having trouble on Windows getting it to sync properly (either direction) even when clicking only the html elements. Clicking in the h tags in Code View does not take me to that section in Preview.
I agree with what you are experimenting. That is exactyly what happens in my Windows PC.

 06-14-2021, 11:15 AM #6 KevinH Sigil Developer   Posts: 5,518 Karma: 3513158 Join Date: Nov 2009 Device: many It seems from looking at the Inspector in Preview, that MathJax is now injecting lots more crap into the DOM tree than they used to. The problem is that extra nodes throws off the webpaths (think element counts from the body tag level by level much like an epubcfi) so much they no longer function as they are invalid. This confuses the go to location very badly. Sometimes it works but other times it does not depending on how many element node counts are off. Not sure exactly how we can deal with this.
 06-14-2021, 04:45 PM #7 KevinH Sigil Developer   Posts: 5,518 Karma: 3513158 Join Date: Nov 2009 Device: many I spent most of today looking at this. It is going to be a bear to fix. MathJax just inserts so much crap that any type of cfi or element path will be wrong. Very wrong. And it gets worse the more equations are in the file. If I turn off just about all the crap as I can, it still wraps each math node in a script tag of type math/mml and it adds 2 divs at the top as the first two children of the body. One div is required as it has the svg paths and glyphs needed. The other is just a stupid message field that can not be deleted even if your set showMessages to false and to not display. Even worse the Mathjax java script code will constantly recreate it even if has been deleted and set not to be used. So the only approach that might work is to register a start-up hook for when mathjax ends and then create some javascript to remove all of the extra script tags added to wrap the math ml tags from the dom, then remember if using mathml and if so compensating for the two extra first children of the body when passing a location into Preview and do the reverse when passing a location out of Preview to CV. What a mess! All because Chrome decided to kill all support for true native mathml in the browser. Last edited by KevinH; 06-14-2021 at 04:47 PM.
 06-14-2021, 04:49 PM #8 DiapDealer Grand Sorcerer     Posts: 24,250 Karma: 163636384 Join Date: Jan 2010 Device: Nexus 7, Kindle Fire HD I wouldn't expect anyone to go down that rabbit hole.
 06-14-2021, 05:00 PM #9 KevinH Sigil Developer   Posts: 5,518 Karma: 3513158 Join Date: Nov 2009 Device: many Well call me Alice! I will try to do this tomorrow just to see how doable and robust this approach would be. If I can get it working reasonably well without the changes being too invasive we can consider it. If not, we should just leave it as a bug and wait for MathJax 3.x with mml3 support and see if it deals with things any better.
 06-14-2021, 06:46 PM #10 DiapDealer Grand Sorcerer     Posts: 24,250 Karma: 163636384 Join Date: Jan 2010 Device: Nexus 7, Kindle Fire HD Far be it for me to discourage a man with a plan. I was just thinking that Preview/Codeview sync is probably able to be broken at any time by scripts included with epubs.
 06-14-2021, 06:50 PM #11 KevinH Sigil Developer   Posts: 5,518 Karma: 3513158 Join Date: Nov 2009 Device: many Yes, any scripts that add dom nodes that are first level children of the body tag are going to be an issue. But that would be because of their own javascript and not our internal stuff. I would like our internal stuff to not impact the sync if at all possible.
 06-15-2021, 06:17 AM #12 Notjohn mostly an observer   Posts: 1,468 Karma: 987654 Join Date: Dec 2012 Device: Kindle You guys are heroes!
 06-15-2021, 10:09 AM #13 KevinH Sigil Developer   Posts: 5,518 Karma: 3513158 Join Date: Nov 2009 Device: many Okay, I tried this approach and it seems to work. The changes included modifying the SIGIL_EBOOK_MML_SVG.js file to strip out and turn off a bunch of junk (had to modify the version inside ML.zip as well), plus some special post mathjax run javascript cleanup code, and some routines to compensate for the added 2 divs as the first children of the body when getting and setting location. I have pushed all of this to master. If anyone gets a chance, I would love to see if and how this works on Windows (it should) but most importantly if it works with a system level MathJax 2.X on Linux. If it seems to work on all platforms, we will leave it as is, otherwise if it can not be easily fixed, we can revert it and worry about it again when the mathjax conversion to Mathjax 3.X includes the mml3 extension. Hope this works!
 06-15-2021, 10:17 AM #14 BeckyEbook Evangelist     Posts: 406 Karma: 1093035 Join Date: Jan 2017 Location: Poland Device: Kindle (Key3, PW2, PW3), Nook (ST, GLP), Kobo Touch, Tolino Vision 2 I confirm in Windows 10. Of course, jumps to preview only on click h1, h2 and p in the sample file.
06-15-2021, 10:38 AM   #15
KevinH
Sigil Developer

Posts: 5,518
Karma: 3513158
Join Date: Nov 2009
Device: many
Wonderful! Thanks.

I can confirm it works in macOS, so that just leaves Linux.

I will try to fire up my Linux box later tonight and give it a try there, unless someone beats me to it.

Quote:
 Originally Posted by BeckyEbook I confirm in Windows 10. Of course, jumps to preview only on click h1, h2 and p in the sample file.

Last edited by KevinH; 06-15-2021 at 12:06 PM.