Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
354 views
in Q2A Core by

I have this (below) in Admin/Layout/"Custom HTML in <head> section of every page:"

<script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [["$$","$$"],["$","$"],["\\(","\\)"]]
        }
      });
    </script>
    <script type="text/javascript"
      src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full">
    </script>

This piece of code above works well.

So, I removed this piece of code and I am trying to add that using a plugin in order to use the js file, instead having to access cdn.mathjax.org:

class qa_html_theme_layer extends qa_html_theme_base {
    
    public function head_script()
    {
            if (!isset($this->content['script'])) {
                $this->content['script'] = array();
            }            
            
        $jsMathjax =QA_PLUGIN_DIR.'/Caju-add-Mathjax/MathJax.js';
            
        $this->content['script'][] = '<script type="text/javascript" src="'.$jsMathjax.'"></script>';
            $this->content['script'][] = '<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$$","$$"],["$","$"],["\\(","\\)"]] }}); </script>';
        parent::head_script();
    }    
}

I saved the file MathJax.js in this folder. What am I doing wrong? It must not be a copy error, since I copied the code and included between ' and '.

Q2A version: 1.7.0

1 Answer

+2 votes
by
selected by
 
Best answer

Well, I'm not sure what error you're getting. However, you're using something the core should only use and that is the QA_PLUGIN_DIR constant. In the context of a layer you should use QA_HTML_THEME_LAYER_URLTOROOT as explained here. Then omit your plugin directory name as it would be implicit.

You can check this before and after the change by looking at the generated HTML code of the page.

...