Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How do I set MathJax config file?

MathJax and Config file

I've using vanilla 2.0.18.10 and want to have LaTeX typesetting. Because I want to use '$' as in usual LaTeX, i didn't use LaTeX-plugin that based on Google Infographic API. After roaming in this forum, I decide to use MathJax since it's beautifully rendered. As suggested in mathjax official page, I turnoff the Markdown typesetting.

Later on, I found that MathJax didn't load the dollar sign automatically and we had to config it some way with config file as in Config-Setting MathJax.

I tried to include it in my themes by include the script in default.master.tpl but it didn't work at all. The dollar sign just didn't want to change the code into LaTeX. So I were roaming again and found this post. And I make a default.php file that mentioned in the discussion. But it didn't work.

Can anyone help me how to config mathjax in vanilla?

installed version

version : Vanilla 2.0.18.10
theme : bootstrap
site : forum

config file

MathJax.Hub.Config({ tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ], processEscapes: true } });

Comments

  • *markdown is marking down my script -_- and I cannot upload .php files, here is my script in txt

  • x00x00 MVP
    edited January 2014

    This is your code

    <?php
    if(!defined('APPLICATION')) exit();
    
    $PluginInfo['MathJaxInline'] = array(
       'Name' => 'VanillaMathjaxInline',
       'Description' => 'Adds MathJax JavaScript to forum so that your users can use LaTeX in comments, both inline and display style.',
       'Version' => '1.0',
       'Author' => "Prihandokorudi",
       'AuthorEmail' => 'mail@prihandokorudi.com',
    );
    
    class LoadMathJax extends Gdn_Plugin {
    
        public function Base_Render_Before(&$Sender) {
            $Sender->_LoadMathjax($Sender);
            $Sender->AddJsFile("redraw.js", "plugins/MathJax");
        }
    
        private function _LoadMathJax($Sender){
            $Sender->Head->AddString('
            <script type="text/x-mathjax-config">
                MathJax.Hub.Config({
                    tex2jax: {
                        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
                        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
                        processEscapes: true
                    }
                });
            </script>
            <script type="text/javascript"
            src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
            </script>
            ');
        }
    
        public function Setup(){}
    }
    

    grep is your friend.

  • x00x00 MVP
    edited January 2014

    well i can see an error in you code. You need to escape '

            $Sender->Head->AddString('
                    ....yada ....
                        inlineMath: [ [\'$\',\'$\'], ["\\(","\\)"] ],
                        displayMath: [ [\'$$\',\'$$\'], ["\\[","\\]"] ],
    

    grep is your friend.

  • edited January 2014

    sorry, I just don't get what you mean by escape '

    thanks.

  • There was an error rendering this rich post.

  • This is not valid code 'text'$'text' if you want to ' in you string you must escape it 'text\'$\'text'

    I presume you are already familiar with php and basic string manipulation?

    grep is your friend.

  • edited January 2014

    @UnderDog : thanks for the links

    @x00 : no I don't. i just copy it from the link I mentioned before, and trying figure it out my self. I never typed php language, (i think i should learn it from now on) and this is my first try to install a web. Thanks for all the expanation, i'll back again after read all the links given and mathjax code work

  • x00x00 MVP
    edited January 2014

    Definitely getting the basics of programming will help you, otherwise you are acting blind. You don't really know what it is you are copying or if it is even relevant to your problem, or how to apply it.

    grep is your friend.

  • edited January 2014

    Thanks for the advice @x00 , I read little about php by now :)

    Then I tried again as you suggested :

                        inlineMath: [ [\'$\',\'$\'], ["\\(","\\)"] ],
                        displayMath: [ [\'$$\',\'$$\'], ["\\[","\\]"] ],
    

    but got bonk.

    I tried to include it again in the default.master.tpl file since it loaded with the theme. This time i didn't get bonk. But then got nothing with the inline math.

    What i did after that was remove all the modification theme and load the script again. This time the math loaded fine as you can say in http://olimpiade.org.45019.temporaryonly.com/vanilla/index.php?p=/discussion/2/junker-paradiso#Item_8

    I want it this theme because this is the mainstream theme in my community. But still don't know why the theme won't load the mathjax script properly. :( is it because the dollar sign?

    Edit : I didn't add the config file, but inline math is working

  • if you want to include it in themes - you can add it with themehooks.

    if you want to make a plugin. zip up your whole plugin and add it as a file attachment here and we can test it.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • thank you @peregrine here is the plugin.

    I can't find plugin called themehooks, but eventually found plugin named eventi(i think this plugin cannot help my problems). Is it the same thing as themehooks?

  • peregrineperegrine MVP
    edited January 2014

    not your answer yet.

    but you have a few flaws in naming and conventions

    your zip had folder VanillaMathJaxInline

    instead of folder VanillaMathJaxInline

    change from
    
    $PluginInfo['MathJaxInline'] = array(
       'Name' => 'VanillaMathjaxInline',
       'Description' => 'Adds MathJax JavaScript to forum so that your users can use LaTeX in comments, both inline and display style.',
    
    
    
    
    TO 
    
      put your plugin in a folder called  MathJaxInline
    
    
        $PluginInfo['MathJaxInline'] = array(
           'Name' => 'Mathjax Inline',
           'Description' => 'Adds MathJax JavaScript to forum so that your users can use LaTeX in 
    comments, both inline and display style.', 
    
    
    
    
    
    name in $PluginInfo['THENAME'] = array(   should match folder Name exactly.
    
    name in 'Name'  should start with Folder Name so it is easier to find in dashboard.
    I would be looking for MathjaxInline  NOT vanilla Mathjax.
    
    I find it very cumbersome to find plugin in dashboard  when name is totally different alphabetically.
    
         public function Base_Render_Before(&$Sender) {
    
        should be 
    
    
        public function Base_Render_Before($Sender) {
    
    
    don't use ampersand.
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited January 2014

    see next comment :)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited January 2014

    tested with

    1 - I rewrote your code in default.php and the redraw.js to load js and config things properly and conform better.

    2nd image edit mode before

    3rd image - view of discussion.

    you should add it to the add-ons - if it works properly for you.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • here is the new zip - I can't add new attachments to old comments.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited June 2014

    using the zip above.

    make these changes for 2.1 using html formatting in conf/config.php

    $Configuration['Garden']['InputFormatter'] = 'Html'; or Markdown

    in default.php

       private function _mymathjax()
        {
            $html = <<<EOF
            <script type="text/javascript"
            src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
            </script>
            <script>
                MathJax.Hub.Config({
                    tex2jax: {
                                               inlineMath: [ ['$$','$$'], ['\\(','\\)'] ]
    
                    }
                });
            </script>
    EOF;
            // No WhiteSpace in front of EOF!!
    
            return $html;
    
        }
    

    and in js/redraw.js

        jQuery(document).ready(function($) {
    
        $('.Message').livequery(function () {
            //MathJaxInline.Hub.Queue(["Typeset", MathJaxInline.Hub]);
    
        MathJax.Hub.Config({
          showProcessingMessages: false,
          jax: ["input/TeX", "output/HTML-CSS"],
        });
    
        });
        });
    

    after you post a sample formula, you must refresh the browser

    an example
    
    sample 1
    
    \[{x^2-1}\]
    
    
    sample 2
    
    
    \[y = \frac{1}{x^2-1} \hbox{ when $x \ne \pm 1$.}\]
    

    or $${x^2-1} $$ using $$ delimiters

    or $$ y = \frac{1}{x^2-1} \hbox{ when $x \ne \pm 1$.} $$

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • you can also use this newly created add-on, if you don't want mess around.

    http://vanillaforums.org/addon/mathjaxcdn-plugin

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.