Search code examples
javascriptmathjaxepiceditor

Epiceditor paired with MathJax


Is there anyway to load a script (such as MathJax) into the EpicEditor preview iFrame? I want my previews to be correct Markdown and then have the javascript run to preview the MathJax content.

Thanks!


Solution

  • It seems that you ought to inject MathJax script manually into previewer iframe. Something like this:

    var editor = new EpicEditor(opts).load();
    
    previewer = editor.getElement('previewer');
    var mathjax = previewer.createElement('script');
    mathjax.type = 'text/javascript';
    mathjax.src = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
    previewer.body.appendChild(mathjax);
    
    var config = previewer.createElement('script');
    config.type = 'text/x-mathjax-config';
    config.text = "MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']], displayMath: [['$$','$$']], processEscapes: true}});";
    previewer.body.appendChild(config);
    

    And then you can render equations on preview event:

    editor.on('preview', function() {
        editor.getElement('previewerIframe').contentWindow.eval(
            'MathJax.Hub.Queue(["Typeset",MathJax.Hub]);');
    });
    

    That also works in fullscreen live edit mode.