# MathJax and latex2html5 Joomla System Plugin

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" ,
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

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" ,
tex2jax: {
processEnvironments: true,
inlineMath: [ ['$','$'], ["$$","$$"] ],
displayMath: [ ['$$','$$'], ["$","$"] ],
preview : "none",
processEscapes: true
},
"HTML-CSS": { linebreaks: { automatic:true, width: "latex-container"} }
});
';
$doc->addScriptDeclaration($js);

• 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 Aug 5 '14 at 9:44
• @Starry - I have updated my answer. Hope this helps – Lodder Aug 5 '14 at 9:47
• thank you for the guidance, it helps, now I don't need to manually edit template file. – Starry Aug 5 '14 at 9:53