简体   繁体   English

将MathJax脚本添加到Office 365 Sharepoint中的页面

[英]Add MathJax script to pages in Office 365 Sharepoint

I'm trying to add the Mathjax library to a SharePoint library so that we can use LaTex syntax to add equations. 我正在尝试将Mathjax库添加到SharePoint库中,以便我们可以使用LaTex语法添加方程式。

I've seen several methods while searching on the web, but none seems to be working properly with the latest version of MathJax and with the Office 365 version of SharePoint. 在网上搜索时,我已经看到了几种方法,但是似乎没有一种方法可以与最新版本的MathJax和Office 365版本的SharePoint一起正常工作。

One solution I found, that works in Chrome but works neither in IE nor in Firefox, is to add the javascript link directly into the master page. 我发现一种可以在Chrome浏览器中使用但不能在IE和Firefox中使用的解决方案是将javascript链接直接添加到母版页中。 I edited seattle.master and added the following: 我编辑了seattle.master并添加了以下内容:

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=default"></script>

Directly below 正下方

<SharePoint:CustomJSUrl runat="server" />

It works fine in Chrome, but doesn't show anything in IE or Firefox. 它在Chrome浏览器中工作正常,但在IE或Firefox中不显示任何内容。 I don't have any error message in the browser's console, it just doesn't display. 我在浏览器的控制台中没有任何错误消息,只是没有显示。

Thanks in advance. 提前致谢。

My solution of editing the master page was actually working, it was just that I was using the unsecured CDN. 我编辑母版页的解决方案实际上是有效的,只是我使用的是不安全的CDN。

Changing the script to 将脚本更改为

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

Which is the URL for the https version of the CDN makes it work correctly. CDN的https版本的URL使其正常运行。

I'm keeping this until I have found a better solution. 我一直坚持到找到更好的解决方案为止。

Edit: 编辑:

There was the issue that the script was triggering even if in "Design" mode and made it nearly impossible to change the equation once written. 存在一个问题,即使在“设计”模式下,脚本也会触发,并且一旦编写就几乎无法更改公式。

To fix the issue, I replaced the simple line above by the following: 为了解决这个问题,我用以下内容替换了上面的简单行:

<script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(function(){
        var inEditMode = SP.Ribbon.PageState.Handlers.isInEditMode();
        if(!inEditMode)
        {
            var script = document.createElement("script");
            script.type = "text/javascript";
            script.src  = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
            document.getElementsByTagName("head")[0].appendChild(script);
        }
    }, 'SP.Ribbon.js');
</script>

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

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