User:Nageh/mathJax.js

This is an old revision of this page, as edited by Nageh (talk | contribs) at 15:42, 25 May 2013. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
if ( typeof(mathJax) === "undefined" ) mathJax = {};

mathJax.version = "0.2.3";

mathJax.loaded = false;

mathJax.Config = function() {
  MathJax.Hub.Config({
    root: "//en.wikipedia.org/w/index.php?action=raw&maxage=86400&ctype=text/javascript&title=User:Nageh/mathJax",
    config: "TeX-AMS-texvc_HTML.js",
    "v1.0-compatible": false,
    displayAlign: "left",
    menuSettings: { zoom: "Click" },
    "HTML-CSS": { imageFont: null, preferredFont: ["STIX"], mtextFontInherit: true, styles: { ".MathJax_Display": { margin: "0.8em 0em" } } },
    NativeMML: { styles: { "DIV.MathJax_MathML": { margin: "0.3em 0em" } } },
    styles: { "mtext": { "font-family": "sans-serif ! important", "font-size": "80%" } }
  });
  if ( typeof(mathJax.fontDir) !== "undefined" ) MathJax.OutputJax.fontDir = mathJax.fontDir; else MathJax.Hub.Config({ NativeMML: {webFont: null} });
  if ( typeof(mathJax.fontVariant) !== "undefined" ) MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready", function() {
    var VARIANT = MathJax.OutputJax["HTML-CSS"].FONTDATA.VARIANT;
    VARIANT["normal"].fonts.unshift(mathJax.fontVariant);
    VARIANT["bold"].fonts.unshift(mathJax.fontVariant+"-bold");
    VARIANT["italic"].fonts.unshift(mathJax.fontVariant+"-italic");
    VARIANT["-tex-mathit"].fonts.unshift(mathJax.fontVariant+"-italic");
  });
  // delete unneeded, unsafe commands
  MathJax.Hub.Register.StartupHook("TeX Jax Ready", function() {
    var MACROS = MathJax.InputJax.TeX.Definitions.macros;
    delete MACROS.href;
    delete MACROS['class'];
    delete MACROS.cssId;
    delete MACROS.style;
    delete MACROS.require;
  });
  MathJax.Hub.Register.LoadHook("[MathJax]/jax/output/HTML-CSS/fonts/STIX/fontdata.js", function() {
    var DELIMITERS = MathJax.OutputJax["HTML-CSS"].FONTDATA.DELIMITERS;
    DELIMITERS[0x21D1].stretch.ext[2] = .09;
    DELIMITERS[0x21D3].stretch.ext[2] = .09;
    DELIMITERS[0x21D5].stretch.ext[2] = .09;
  });
  MathJax.Message.styles["#MathJax_Message"].right = MathJax.Message.styles["#MathJax_Message"].left;
  delete MathJax.Message.styles["#MathJax_Message"].left;
  if ( typeof(mathJax.userConfig) !== "undefined" ) MathJax.Hub.Config( mathJax.userConfig );
  MathJax.Hub.Startup.onload();
}

mathJax.Load = function(element) {
  if (this.loaded)
    return true;

  var span = element.getElementsByTagName("span"), i;
  for (i = span.length-1; i >= 0; i--) {
    if (span[i].className === "tex") {
//      this.span = span;
//      this.spanIndex = i;

      // create configuration element
      var config = 'mathJax.Config();';
      var script = document.createElement( 'script' );
      script.setAttribute( 'type', 'text/x-mathjax-config' );
      if ( window.opera ) script.innerHTML = config; else script.text = config;
      document.getElementsByTagName('head')[0].appendChild( script );

      // create startup element
      script = document.createElement( 'script' );
      script.setAttribute( 'src', '//en.wikipedia.org/w/index.php?action=raw&maxage=86400&ctype=text/javascript&title=User:Nageh/mathJax/MathJax.js' );
      script.setAttribute( 'type', 'text/javascript' );
      document.getElementsByTagName('head')[0].appendChild( script );

      this.loaded = true;
      break;
    }
  }
  return false;
}

mathJax.Init = function() {
  this.Load( document.getElementById("bodyContent") || document.body );

  // compatibility with wikEd
  if ( typeof(wikEd) == "undefined" ) { wikEd = {}; }
  if ( typeof(wikEd.config) == "undefined" ) { wikEd.config = {}; }
  if ( typeof(wikEd.config.previewHook) == "undefined" ) { wikEd.config.previewHook = []; }
  wikEd.config.previewHook.push( function(){ if (window.mathJax.Load(document.getElementById("wikEdPreviewBox") || document.body)) MathJax.Hub.Queue(["Typeset", MathJax.Hub, "wikEdPreviewBox"]) } );

  // compatibility with ajaxPreview
  this.oldAjaxPreviewExec = window.ajaxPreviewExec;
  window.ajaxPreviewExec = function(previewArea) {
    if ( typeof(mathJax.oldAjaxPreviewExec) !== "undefined" ) mathJax.oldAjaxPreviewExec(previewArea);
    if ( mathJax.Load(previewArea) ) MathJax.Hub.Queue( ["Typeset", MathJax.Hub, previewArea] );
  }
}

mathJax.Init();