简体   繁体   English

在JavaFX WebView中加载MathJax

[英]Loading MathJax in JavaFX WebView

I have an HTML file inside my project package. 我的项目包中有一个HTML文件。 In other words: 换一种说法:

com/package/name/index.html

I am using JavaFX WebEngine to load it into a WebView : 我正在使用JavaFX WebEngine将其加载到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. MyApp与HTMl文件位于同一软件包中,因此可以正常工作。 The page is displayed as expected. 该页面按预期显示。

Now I want to call a javascript library. 现在,我要调用一个JavaScript库。 In particular, MathJax. 特别是MathJax。

I have put the MathJax folder in the same package, so the path to the .js file is 我已将MathJax文件夹放在同一软件包中,因此.js文件的路径为

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

Anyway, inside the HTML file I have written 无论如何,在我编写的HTML文件中

<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. 如果我要在Chrome或FireFox中运行此文件,它将很好地打开并解析我的数学。

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). 但是,如果我尝试在JavaFX的WebView打开它,则不会进行解析(因此,我假设MathJax库没有被加载)。

What is the correct path to load MathJax, then? 那么,加载MathJax的正确路径是什么?


Progress: 进展:

Changing the index.html file to index.html文件更改为

<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. 将有效地到达MathJax.js文件。 However, it won't be able to load the rest of MathJax, throwing errors like this: 但是,它将无法加载MathJax的其余部分,并引发如下错误:

File failed to load: jar:file:/Users/me/Program.jar!/com/package/name/MATHJAX/extensions/MathMenu.js 文件加载失败:jar:file:/Users/me/Program.jar!/com/package/name/MATHJAX/extensions/MathMenu.js

Have you tried using cdn to include the js? 您是否尝试过使用CDN包含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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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