lib/main.js
function GetSVG(result) {
  if (!data.svg && !data.svgNode) return;
  var jax = MathJax.Hub.getAllJax()[0]; if (!jax) return;
  var script = jax.SourceElement(),
      svg = script.previousSibling.getElementsByTagName("svg")[0];
  svg.setAttribute("xmlns","http://www.w3.org/2000/svg");

  //
  //  Add the speech text and mark the SVG appropriately
  //
  if (data.speakText){
    for (var i=0, m=svg.childNodes.length; i < m; i++)
      svg.childNodes[i].setAttribute("aria-hidden",true);
    // Note: if aria-label exists, getSpeech preserved it in speakText
    // remove aria-label since labelled-by title is preferred
    svg.removeAttribute("aria-label");
    ID++; var id = "MathJax-SVG-"+ID+"-Title";
    svg.setAttribute("aria-labelledby",id);
    var node = MathJax.HTML.Element("title",{id:id},[result.speakText]);
    svg.insertBefore(node,svg.firstChild);
  }

  if (data.svg){
    //
    //  SVG data is modified to add linebreaks for readability,
    //  and to put back the xlink namespace that is removed in HTML5
    //
    var svgdata = svg.outerHTML.replace(/><([^/])/g,">\n<$1")
                               .replace(/(<\/[a-z]*>)(?=<\/)/g,"$1\n")
                               .replace(/(<(?:use|image) [^>]*)(href=)/g,' $1xlink:$2');

    //
    //  Add the requested data to the results
    //
    result.svg = svgdata;
  }
  if (data.svgNode) result.svgNode = svg;
  result.width = svg.getAttribute("width");
  result.height = svg.getAttribute("height");
  result.style =  svg.style.cssText;
}
function GetSVG(result) {
  if (!data.svg && !data.svgNode) return;
  var jax = MathJax.Hub.getAllJax()[0]; if (!jax) return;
  var script = jax.SourceElement(),
      svg = script.previousSibling.getElementsByTagName("svg")[0];
  svg.setAttribute("xmlns","http://www.w3.org/2000/svg");

  //
  //  Add the speech text and mark the SVG appropriately
  //
  if (data.speakText){
    for (var i=0, m=svg.childNodes.length; i < m; i++)
      svg.childNodes[i].setAttribute("aria-hidden",true);
    // Note: if aria-label exists, getSpeech preserved it in speakText
    // remove aria-label since labelled-by title is preferred
    svg.removeAttribute("aria-label");
    ID++; var id = "MathJax-SVG-"+ID+"-Title";
    svg.setAttribute("aria-labelledby",id);
    var node = MathJax.HTML.Element("title",{id:id},[result.speakText]);
    svg.insertBefore(node,svg.firstChild);
  }

  if (data.svg){
    //
    //  SVG data is modified to add linebreaks for readability,
    //  and to put back the xlink namespace that is removed in HTML5
    //
    var svgdata = svg.outerHTML.replace(/><([^/])/g,">\n<$1")
                               .replace(/(<\/[a-z]*>)(?=<\/)/g,"$1\n")
                               .replace(/(<(?:use|image) [^>]*)(href=)/g,' $1xlink:$2');

    //
    //  Add the requested data to the results
    //
    result.svg = svgdata;
  }
  if (data.svgNode) result.svgNode = svg;
  result.width = svg.getAttribute("width");
  result.height = svg.getAttribute("height");
  result.style =  svg.style.cssText;
}
function GetSVG ( result ) { if ( ! data . svg && ! data . svgNode ) return ; var jax = MathJax . Hub . getAllJax ( ) [ 0 ] ; if ( ! jax ) return ; var script = jax . SourceElement ( ) , svg = script . previousSibling . getElementsByTagName ( "svg" ) [ 0 ] ; svg . setAttribute ( "xmlns" , "http://www.w3.org/2000/svg" ) ; // //  Add the speech text and mark the SVG appropriately // if ( data . speakText ) { for ( var i = 0 , m = svg . childNodes . length ; i < m ; i ++ ) svg . childNodes [ i ] . setAttribute ( "aria-hidden" , true ) ; // Note: if aria-label exists, getSpeech preserved it in speakText // remove aria-label since labelled-by title is preferred svg . removeAttribute ( "aria-label" ) ; ID ++ ; var id = "MathJax-SVG-" + ID + "-Title" ; svg . setAttribute ( "aria-labelledby" , id ) ; var node = MathJax . HTML . Element ( "title" , { id : id } , [ result . speakText ] ) ; svg . insertBefore ( node , svg . firstChild ) ; } if ( data . svg ) { // //  SVG data is modified to add linebreaks for readability, //  and to put back the xlink namespace that is removed in HTML5 // var svgdata = svg . outerHTML . replace ( / ><([^/]) / g , ">\n<$1" ) . replace ( / (<\/[a-z]*>)(?=<\/) / g , "$1\n" ) . replace ( / (<(?:use|image) [^>]*)(href=) / g , ' $1xlink:$2' ) ; // //  Add the requested data to the results // result . svg = svgdata ; } if ( data . svgNode ) result . svgNode = svg ; result . width = svg . getAttribute ( "width" ) ; result . height = svg . getAttribute ( "height" ) ; result . style = svg . style . cssText ; }
Create SVG output, if requested
Create SVG output if requested