问题
I'm trying to add the Mathjax library to a SharePoint library so that we can use LaTex syntax to add equations.
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.
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>
Directly below
<SharePoint:CustomJSUrl runat="server" />
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.
Thanks in advance.
回答1:
My solution of editing the master page was actually working, it was just that I was using the unsecured 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.
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>
来源:https://stackoverflow.com/questions/23865427/add-mathjax-script-to-pages-in-office-365-sharepoint