1

After reading this Adding Mathjax to a Joomla website

I don't know anything about writing extention but based on mentioned link, I am assuming it is should be easy to write a simple system plugin to enable both mathjax and latex2html5.

I come up with this

<?php

// no direct access
defined('_JEXEC') or die('Restricted index access');

class plgSystemMathJaxLatex2Html5 extends JPlugin {
    public function onContentPrepare($context, &$article, &$params, $page = 0)
    {   
            $doc = JFactory::getDocument();
            $doc->addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML");
            $doc->addScript(plugins/system/MathJaxLatex2Html5/assets/js/latex2html5.min.js);
            $doc->addStyleSheet(plugins/system/MathJaxLatex2Html5/assets/css/latex2html5.css);
    }
}

Link to the installation of latex2html5 http://latex2html5.com/installation.html

I think the only thing left now is how to include the required mathjax config into plugin.

<script type="text/x-mathjax-config">
    // <![CDATA[
    MathJax.Hub.Config({ 
        TeX: {extensions: ["AMSmath.js", "AMSsymbols.js"]},     
        extensions: ["tex2jax.js"],
        jax: ["input/TeX", "output/HTML-CSS"],
        showProcessingMessages : false,
        messageStyle : "none" ,    
        showMathMenu: false ,
        tex2jax: {
            processEnvironments: true,
            inlineMath: [ ['$','$'], ["\(","\)"] ],
            displayMath: [ ['$$','$$'], ["\[","\]"] ],
            preview : "none",
            processEscapes: true
        },
        "HTML-CSS": { linebreaks: { automatic:true, width: "latex-container"} }
    });
    // ]]>
</script>

Can anyone please guide me to the completion of the plugin?

Thanks

1 Answer 1

0

Fair play to you for deciding to use a plugin and attempt this on your own, +1.

You're very close, but forgot to use quotes when defining the path to the script and stylesheet. The following will work:

$doc->addScript('http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML');
$doc->addScript(JUri::root() . 'plugins/system/MathJaxLatex2Html5/assets/js/latex2html5.min.js');
$doc->addStyleSheet(JUri::root() . 'plugins/system/MathJaxLatex2Html5/assets/css/latex2html5.css');

Also note that for the script and stylesheet that your are importing from your own server, I have used JUri::root() to define the root of the your Joomla installation as a baseline.

Update:

For to call the function, you can Joomla's addScriptDeclaration() function which will inject your defined script into the head and automatically use the <script> tags

$js = '
MathJax.Hub.Config({ 
        TeX: {extensions: ["AMSmath.js", "AMSsymbols.js"]},     
        extensions: ["tex2jax.js"],
        jax: ["input/TeX", "output/HTML-CSS"],
        showProcessingMessages : false,
        messageStyle : "none" ,    
        showMathMenu: false ,
        tex2jax: {
            processEnvironments: true,
            inlineMath: [ ['$','$'], ["\(","\)"] ],
            displayMath: [ ['$$','$$'], ["\[","\]"] ],
            preview : "none",
            processEscapes: true
        },
        "HTML-CSS": { linebreaks: { automatic:true, width: "latex-container"} }
    });
';
$doc->addScriptDeclaration($js);
3
  • Thank you for pointing out the errors. I have updated the question to reflect the additional config file needed by latex2html5. Can I include those directly in the extention or I have to put it in a .js and load it through addScript?
    – Starry
    Commented Aug 5, 2014 at 9:44
  • @Starry - I have updated my answer. Hope this helps
    – Lodder
    Commented Aug 5, 2014 at 9:47
  • 1
    thank you for the guidance, it helps, now I don't need to manually edit template file.
    – Starry
    Commented Aug 5, 2014 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.