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)

DiapDealer 03-31-2021 01:12 PM

No. Client Javascripts have been enabled all along. It's definitely the URLInterceptor:

Code:

Debug: Warning: URLInterceptor blocking access to url  QUrl("file:///C%3A/Program Files/Sigil/polyfills/MJ/MathJax.js?config=local/SIGIL_EBOOK_MML_SVG")
The only thing I can think of is that we may have to find a way to keep the colon after the drive-letter from being percent-encoded on Windows. I'll try to quickly brute that change and see if it makes a difference.

KevinH 03-31-2021 01:17 PM

I am sure it is drive letter related but it should not be % url encoding related
as that is converted to a local file path before comparison.

So in URLInterceptor.cpp, the the following code snippet:

Code:

        QString destpath = destination.toLocalFile();

      ...

        // or the path must be inside the Sigil's MathJax folder                                                               
        if (destpath.startsWith(mathjaxfolder)) {
            info.block(false);
            return;
        }

Immediately after this snippet but before it reaches the debug warning that it will be blocked, it might be useful to add the following:

qDebug() << destpath;
qDebug() << mathjaxfolder;

I am guessing there is some drive letter case or leading / difference going on.

KevinH 03-31-2021 01:25 PM

Do you want me to push that change and then add [deploy] for you to test with?

DiapDealer 03-31-2021 01:28 PM

Actually, I think it may be the way the mathjax folder/url is being concatenated on Windows

Debug: mathjax: "/C:/Program Files/Sigil/polyfills/MJ/"
Debug: usercss: "C:/Users/Doug/AppData/Local/sigil-ebook/sigil/"

Both are resulting in technically correct urls for the user css file and the mathjax javascript file when all is said and done, but in the case of the mathjax folder: if the URLInterceptor is being told to specifically allow file calls from inside the "/C:/Program Files/Sigil/polyfills/MJ/" folder then that's why it's failing. No such folder exists (that starts with a forward slash).

We either build the mathjax folder/url differently for Windows, or we special-case the starts-with section of the URLInterceptor's mathjax exemption on Windows to strip the leading slash

KevinH 03-31-2021 01:31 PM

So the path to the mathjaxfolder is built in MainWindow.cpp Perhaps the bug is there. The mathjax folder should not have a leading "/" in it, right.

From MainWindow.cpp:

Code:

#ifdef Q_OS_MAC
    // On Mac OS X QCoreApplication::applicationDirPath() points to Sigil.app/Contents/MacOS/                                 
    QDir execdir(QCoreApplication::applicationDirPath());
    execdir.cdUp();
    mathjaxurl = execdir.absolutePath() + "/polyfills/MJ/";
#elif defined(Q_OS_WIN32)
    mathjaxurl = "/" + QCoreApplication::applicationDirPath() + "/polyfills/MJ/";
#else

On MacOS it is built as an absolute path.

On Windows I am not so sure. What does QCoreApplicationDirPath() return?

But then later on we need to build a file url from it and we do it manually.

Maybe that is why the "/" is prepended?

Code:

    m_mathjaxfolder = mathjaxurl;
    mathjaxurl = mathjaxurl + "MathJax.js";
    mathjaxurl = "file://" + Utility::URLEncodePath(mathjaxurl);
    mathjaxurl = mathjaxurl + "?config=local/SIGIL_EBOOK_MML_SVG";

Perhaps we should use QUrl::fromLocalFile() here instead of building the url manually?

KevinH 03-31-2021 01:40 PM

So we could remove the addition of the leading "/" for Windows in the first snippet:

Code:

#ifdef Q_OS_MAC
    // On Mac OS X QCoreApplication::applicationDirPath() points to Sigil.app/Contents/MacOS/                                 
    QDir execdir(QCoreApplication::applicationDirPath());
    execdir.cdUp();
    mathjaxurl = execdir.absolutePath() + "/polyfills/MJ/";
#elif defined(Q_OS_WIN32)
    mathjaxurl = QCoreApplication::applicationDirPath() + "/polyfills/MJ/";
#else

and then change the second snippet to:

Code:

    m_mathjaxfolder = mathjaxurl;
    mathjaxurl = mathjaxurl + "MathJax.js";
    mathjaxurl = QUrl::fromLocalFile(mathjaxurl).toString();
    mathjaxurl = mathjaxurl + "?config=local/SIGIL_EBOOK_MML_SVG";

Or something close. That should work on all platforms, right?

DiapDealer 03-31-2021 01:50 PM

I think should, yes. Let me give it a whirl on Windows and Linux and I'll get back to you.

QCoreApplicationDirPath() returns the folder where the Sigil exe is, by the way. That's also where the poyfill folder is located as well.

KevinH 03-31-2021 01:52 PM

Just tried it and it works fine on MacOS.

DiapDealer 03-31-2021 02:18 PM

It fixed things on Windows and continued to work without issue on Linux! Seem a lot cleaner method too.

I'm consistently getting a few errors in inspector related to MathJax on Windows and Linux, though. Are you seeing anything about missing MathMenu.js files and MathZoom.js files? MathJax seems to be looking for them in polyfills/MJ/extensions. The files are definitely not there, I'm just wondering what's looking for them (and if they should be there).

KevinH 03-31-2021 02:25 PM

The MathMenu can not be used was was intentionally removed as it allowed the user to change MathJax settings and it can not be interacted with as Preview is not a Browser.

MathZoom is an accessibility features but Prefix's Zoom takes precedence and so it is unneeded as well. MathJax will dynamically load only those extensions that are present.

So we should be good to go.

KevinH 03-31-2021 02:27 PM

Can you push push that MainWindows Mathjax fix with [deploy] or do you want me to do it?

DiapDealer 03-31-2021 02:44 PM

I'll take care of it.

I know you've already pushed some bigger changes beyond 1.5.1, so I won't be able to use CI to deploy something on the order of a 1.5.2, but that's fine. This has been broken on Windows since July of last year and this is the first report we've gotten on it! So I don't think there's a huge need. We can definitely hold off until Sigil 1.6.

I'll make a patch for the 1.5.1 source for anyone who wants to roll their own, and can make an installer available for @snarkophilus and the few others who might not want to live without the fix. :)

This one's on me. I clearly only tested MathJax functionality on my main Linux machine since version 1.2.0, and didn't look any further when it appeared to work. :o

Also, I can't seem to recreate the issue I was having on Linux where setting a custom Sigil temp folder was breaking MathJax functionality in 1.5.1. Perhaps I just missed a restart after changing the enable javascript setting :blink:

KevinH 03-31-2021 03:11 PM

Sounds good.

snarkophilus 03-31-2021 08:00 PM

Thanks guys for your busy work while I was asleep :)

DiapDealer 04-01-2021 12:07 PM

Quote:

Originally Posted by snarkophilus (Post 4108163)
Thanks guys for your busy work while I was asleep :)

No problem.

It was such a simple change that I replaced the Windows installer packages in the github Sigil 1.5.1 release. Feel free to redownload the installer (don't forget to verify the checksums) and verify that it solves the problem for you.

I included a note and the patch for 1.5.1 in the documentation of the release, as well.


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.