简体   繁体   中英

Loading MathJax in JavaFX WebView

I have an HTML file inside my project package. In other words:

com/package/name/index.html

I am using JavaFX WebEngine to load it into a WebView :

    String url = MyApp.class.getResource("index.html").toExternalForm();  
    webView.getEngine().load(url);

MyApp is in the same package as the HTMl file, so this works fine. The page is displayed as expected.

Now I want to call a javascript library. In particular, MathJax.

I have put the MathJax folder in the same package, so the path to the .js file is

com/package/name/MATHJAX/MathJax.js?

Anyway, inside the HTML file I have written

<script type="text/javascript" src="MATHJAX/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

If I were to run this file in Chrome or FireFox, it would open fine and parse my mathematics.

But if I try to open this in JavaFX's WebView , the parse does not occur (so I assume that the MathJax library is not being loaded).

What is the correct path to load MathJax, then?


Progress:

Changing the index.html file to

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js","MathMenu.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
      processEscapes: true
    },
    MathMenu: {
      delay: 600
    },
    "HTML-CSS": { availableFonts: ["TeX"] }
  });
</script>
<script type="text/javascript" src="MATHJAX/MathJax.js"></script>

Will effectively reach the MathJax.js file. However, it won't be able to load the rest of MathJax, throwing errors like this:

File failed to load: jar:file:/Users/me/Program.jar!/com/package/name/MATHJAX/extensions/MathMenu.js

Have you tried using cdn to include the js?

<script type="text/javascript" async
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?    config=TeX-MML-AM_CHTML">
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM