将MathJax脚本添加到Office 365 Sharepoint中的页面 [英] Add MathJax script to pages in Office 365 Sharepoint

查看:89
本文介绍了将MathJax脚本添加到Office 365 Sharepoint中的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Mathjax库添加到SharePoint库中,以便我们可以使用LaTex语法添加方程式.

I'm trying to add the Mathjax library to a SharePoint library so that we can use LaTex syntax to add equations.

我在网上搜索时看到了几种方法,但是似乎没有一种方法可以与最新版本的MathJax和Office 365版本的SharePoint一起正常工作.

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.

我发现的一种解决方案是将javascript链接直接添加到母版页,该解决方案可在Chrome中使用,但在IE和Firefox中均不可用.我编辑了seattle.master并添加了以下内容:

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. I edited seattle.master and added the following:

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

正下方

<SharePoint:CustomJSUrl runat="server" />

它在Chrome浏览器中工作正常,但在IE或Firefox中不显示任何内容.我在浏览器的控制台中没有任何错误消息,只是没有显示.

It works fine in Chrome, but doesn't show anything in IE or Firefox. I don't have any error message in the browser's console, it just doesn't display.

谢谢.

推荐答案

我编辑母版页的解决方案实际上是有效的,只是我使用的是不安全的CDN.

My solution of editing the master page was actually working, it was just that I was using the unsecured CDN.

将脚本更改为

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

使用CDN的https版本的URL可以使其正常运行.

Which is the URL for the https version of the CDN makes it work correctly.

我一直坚持到找到更好的解决方案为止.

I'm keeping this until I have found a better solution.

存在一个问题,即使在设计"模式下,脚本也会触发,并且一旦编写就几乎无法更改公式.

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>

这篇关于将MathJax脚本添加到Office 365 Sharepoint中的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆