MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Sigil (https://www.mobileread.com/forums/forumdisplay.php?f=203)
-   -   How to use MathML/MathJax (https://www.mobileread.com/forums/showthread.php?t=338460)

snarkophilus 04-02-2021 03:17 AM

Thanks Diap!

That works for the linear equation epub and the snippet of mathml code, but it doesn't render the example epub from the Calibre documentation.

Both the code snippet and the linear algrabra book in my first post in this thread use "inline" <math xmlns="http://www.w3.org/1998/Math/MathML"> XML for each math equation but the Calibre doco example uses a <script type="text/x-mathjax-config"> phrase in the <head> section to declare it's mathml and then just a bare \[,\] or \(,\) pair in the text to bracket a maths expression. I added the following line (from a random mathml sample I found on the web) to the <head> section and then it did render:

Code:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
Is that a problem with the sample EPUB or a Sigil problem?

One minor nit: In the "about" popup, it still says Build time: 2021.03.25 14:50:59 UTC. I assume a resource wasn't updated when you uploaded the replacement 1.5.1 build? No biggie, but it was harder to make sure I'd installed the updated 1.5.1 even after I'd verified the new checksum :).

DiapDealer 04-02-2021 06:26 AM

Yeah, you're probably not going to be able to include your own MathJax script (local or remote) with its own config. Sigil's Preview automatically injects the script tags with its own version of MathJax (and its own local config) behind the scenes whenever MathMl tags are encountered.

The build-time is definitely my fault. Since only two lines of one file were changed, I didn't do a full compile from scratch. It probably should have occurred to me that that might happen, but it didn't.

BeckyEbook 04-02-2021 06:45 AM

Quote:

Originally Posted by DiapDealer (Post 4108578)
The build-time is definitely my fault. Since only two lines of one file were changed, I didn't do a full compile from scratch. It probably should have occurred to me that that might happen, but it didn't.


Tip:
I like to see the correct compilation date, so in the build batch, I added an extra line, which by removing the compiled file from "About" forces inserting the current date and time.

Code:

if exist W:\Develop\Sigil\Sigil-master\src\CMakeFiles\Sigil.dir\Dialogs\About.cpp.obj del /Q W:\Develop\Sigil\Sigil-master\src\CMakeFiles\Sigil.dir\Dialogs\About.cpp.obj

DiapDealer 04-02-2021 07:05 AM

Quote:

Originally Posted by BeckyEbook (Post 4108582)
Tip:
I like to see the correct compilation date, so in the build batch, I added an extra line, which by removing the compiled file from "About" forces inserting the current date and time.

Code:

if exist W:\Develop\Sigil\Sigil-master\src\CMakeFiles\Sigil.dir\Dialogs\About.cpp.obj del /Q W:\Develop\Sigil\Sigil-master\src\CMakeFiles\Sigil.dir\Dialogs\About.cpp.obj

What build batch?

This is never a problem under "normal" circumstances. Sigil releases are done with a full, fresh compile of all files starting with an empty build directory. As are all CI builds. This was just a one-off mistake I made looking to save some time.

BeckyEbook 04-02-2021 07:17 AM

I thought you did the build on the local computer for some batch to do it faster, I use one myself (cmake with parameters + ninja -j4).

DiapDealer 04-02-2021 07:52 AM

No. Locally I do it manually. Well, as "manually" as a 3 command process can be, anyway ;)

Too much automation gets me in just as much trouble as not enough. Makes me forget how to fix things when inevitable changes and other disruptions out of my control breaks something. The build environment is automated (paths, qt, python, visual studio, etc), but that's about it.

I've got 50 or so different cmake configurations I experiment with locally. But building Sigil still boils down to 3 commands for me:

cmake (the correct config string pasted in from the file of 50 or so)
ninja
ninja makeinstaller

That's as automated as I'm willing to get and still stay on my toes. I've got the CI deployment if I need fully automated builds for quick testing (and they're always from scratch). But I don't use those builds for official releases. I can't trust that something hasn't crept into their build environments while I wasn't looking.

snarkophilus 04-02-2021 08:27 AM

Quote:

Originally Posted by DiapDealer (Post 4108578)
Yeah, you're probably not going to be able to include your own MathJax script (local or remote) with its own config. Sigil's Preview automatically injects the script tags with its own version of MathJax (and its own local config) behind the scenes whenever MathMl tags are encountered.

I'm happy to include the builtin MathJax somehow!

Is there a way we can key off 'text/x-mathjax-config' as well as the existance of a <math> tag to enable MathML? This seems to be the difference in what Sigil does compared with what Calibre editor does to detect math. Surely this isn't as simple as adding something like '<script\\s+type="text/x-mathjax-config"' to the regex that's looking for the math tags?

snarkophilus 04-02-2021 09:04 AM

A bit of a play around (whilst admitting I don't really know what I'm doing) seems to indicate something more is needed than just detecting 'script type="text/x-mathjax-config"'.

Inspecting the preview window with a <math ...> line and grabbed the inserted MathJax script and added that to a "simple" file, but it doesn't render:

Spoiler:
Code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <script type="text/x-mathjax-config"></script>
  <script type="text/javascript" async="async" src="file:///C:/Program Files/Sigil/polyfills/MJ/MathJax.js?config=local/SIGIL_EBOOK_MML_SVG"></script>
</head>
<body>
<p>
\(\frac{\sqrt{a}}{b}\)
</p>
</body>
</html>



Using the random google-found script line I mentioned earlier does render:

Spoiler:
Code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <script type="text/x-mathjax-config"></script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</head>
<body>
<p>
\(\frac{\sqrt{a}}{b}\)
</p>
</body>
</html>



I'm hoping(!) that I can get this simple sample to render:
Spoiler:
Code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <script type="text/x-mathjax-config"></script>
</head>
<body>
<p>
\(\frac{\sqrt{a}}{b}\)
</p>
</body>
</html>


Doitsu 04-02-2021 10:06 AM

1 Attachment(s)
Since JavaScript isn't supported in epub2 books, I converted it to an epub3 book and I also embedded the MathJax JavaScript library.
It displays more or less fine in Sigil, Azardi and Apple Books, but not in Adobe Digital Editions 4.5.x.
OTOH, ADE displays the old IDPF test file fine. (So does Sigil 1.5.1.)

DiapDealer 04-02-2021 10:35 AM

Yes. The basic inline <math></math> stuff is the only thing that's going to stand a chance of working in an epub2 in Sigil. And it's probably not even technically spec. Epub3 is necessary for your sample epub (to comply with spec and work with Sigil).

The MathML section of the IDPF EPUB3 test epub is what we used when implementing the support in Sigil. The only places Sigil falls down in their tests (at least on Windows) is the optional "CSS Styling test (mathml-021)" and the required "BiDi, RTL and Arabic alphabets test (mathml-070)".

I think at least one of those was a Windows-only failure.

KevinH 04-02-2021 10:38 AM

Unlike calibre, Sigil does not support tex math or ascii math as that is not what the epub spec calls for. Only mathml notation (the spec) is supported.

So no, your simple example is not part of the epub3 spec so Sigil does not support it.

snarkophilus 04-03-2021 01:25 AM

Thanks Daip and Kevin for those explanations.

Quote:

Originally Posted by Doitsu (Post 4108643)
Since JavaScript isn't supported in epub2 books, I converted it to an epub3 book and I also embedded the MathJax JavaScript library.

Thanks! It didn't even occur to me that you could embed the JavaScript, although it's perfectly obvious now that you've done ie.

Quote:

It displays more or less fine in Sigil, Azardi and Apple Books, but not in Adobe Digital Editions 4.5.x.
OTOH, ADE displays the old IDPF test file fine. (So does Sigil 1.5.1.)
I haven't even got to what may or may not work on my Kobo Aura 2!

Doitsu 04-03-2021 02:40 AM

Quote:

Originally Posted by snarkophilus (Post 4108813)
I haven't even got to what may or may not work on my Kobo Aura 2!

AFAIK, Kobo devices support EPUB3 books, if you convert them to KEPUB files. According to the official KEPUB specs, MathML is supported.

Quote:

MathML Support

MathML is currently supported on Kobo's iOS, Android, Desktop and eInk platforms. It is not currently supported on the Windows app for Desktop and mobile. It is recommended that content creators test their content across Android, iOS and Desktop prior to distribution to ensure that equations are displaying as intended.
Try converting the old IDPF MATHML test file to a KEPUB file and side-load it to your Kobo.
(Sigil supports MathML out of the box.)

snarkophilus 04-03-2021 10:10 PM

Quote:

Originally Posted by Doitsu (Post 4108824)
AFAIK, Kobo devices support EPUB3 books, if you convert them to KEPUB files. According to the official KEPUB specs, MathML is supported.

It looks like Kobo supports MathML only, and not the LaTex format that MathJax javascript also works with. The Calibre example with the embedded MathJax.js didn't render any math.

Quote:

Try converting the old IDPF MATHML test file to a KEPUB file and side-load it to your Kobo.
(Sigil supports MathML out of the box.)
That one works to some extent. The first half(ish) of the MathML tests render mostly pl on my Aura, but the remaining are a bit hit and miss. The integral symbol is a bit short, you can see the vertical stretch on parantheses are made up of vertical bars and not a continuous line, etc.

Well off topic for Sigil now, I'll stop here!

Thanks again all for getting MathML working on Sigil again, and for helping me understand a little bit more about MathML in general.


All times are GMT -4. The time now is 10:54 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.