We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5683
    • 96 Posts
    Hello,

    this plugin allows you to render LaTeX code into your document contents, in a similar way as in Wikipedia.
    Just wrap your LaTeX code in double dollars, like that: $\sum_{i=0}^n 2^i = 2^{n+1} - 1$.

    But please note that:

    • you must download and install the mimeTeX cgi program in your /cgi-bin directory. Obviously, you must have rights to do that. You can download the program here: http://www.forkosh.com/mimetex.html
    • there is an issue with backslashes in MODx. Every backslash is ignored unless it is quoted with another backslash. Thus, you should double all the backslashes in your LaTeX, like that: $\\sum_{i=0}^n 2^i = 2^{n+1} - 1$. The issue is described in this thread: http://modxcms.com/forums/index.php/topic,4156.0.html. I fixed the problem with a hack of /manager/includes/document.parser.class.inc.php: search for stripslashes and replace the line where it occurs with
      $replace[$i] = $value;
      and the need to double backslashes will be gone; however, I don’t recommend this hack because I don’t know what is the purpose of the stripslashes function call that I removed!

    Here is the plugin code:

    /**
     *	mimeTeX Plugin 0.1 for MODx
     *	by Luca Allulli, April 2006
     *
     *	Event: OnLoadWebDocument
     *
     *	Download and install mimeTeX from http://www.forkosh.com/mimetex.html
     *
     *	License: GNU GPL
     *
     */
     
    //Begin configuration
    	global $mimetexPath;
    	$mimetexPath="/cgi-bin/mimetex.cgi";
    //End configuration 
     
    
    function replaceCodeMimetex($matches) {
    	global $mimetexPath;
    	return '<img src="'.$mimetexPath.'?'.$matches[1].'" align="middle" style="margin-bottom: 7px;" />';
    }
    
    
    $e = &$modx->Event;
    
    
    switch ($e->name) {
    	case "OnLoadWebDocument":
    
    		$modx->documentObject['content']=preg_replace_callback("#\\$\\$(.*?)\\$\\$#s", "replaceCodeMimetex", $modx->documentObject['content']);
    
    		break;
    		
    	default:	// stop here
    		break;	
    }
    
      • 6726
      • 7,075 Posts
      Man you sure have been busy lately !!

      I won’t personnally need this, but many people will be interrested in having LaTeX implemented, it will open new doors to MODx, thanks for this !
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l&#39;outil id
        • 26382
        • 4 Posts
        I want to use mimetex on my modx site. Unfortunately the snippet above doesnt’ work alright.

        1) I think I installed the mimetex-cgi properly, I can get this the interpreted gifs if I call it directly in the browser.

        2) In modx included (Just tried the sample above), I only get the source code, as it’s not interpreted.
        However, I get some errors in the modx-manager. Every time I request a webpage, I get the following error 2 times:

        syntax error, unexpected T_FUNCTION


        Parse error: syntax error, unexpected T_FUNCTION in /srv/www/htdocs/web204/html/moxbeta/manager/includes/document.parser.class.inc.php(724) : eval()’d code on line 19
          • 5683
          • 96 Posts
          Have you modified the configuration string $mimetexPath? Is the modification correct?
          It looks like PHP doesn’t expect a function definition in line 19... which however should work fine (an it does in my installation).
            • 17895
            • 209 Posts
            First of all: you say "double dollars", but you write a single dollar in your post... second: to work on my MODx, I have to write \\\sum instead of \\sum as you say... is there anything to do with MODx 0.95 or is it a mistake?
              Daniele "MadMage" Calisi
              • 17895
              • 209 Posts
              Quote from: madmage at Feb 07, 2007, 05:23 AM

              First of all: you say "double dollars", but you write a single dollar in your post... second: to work on my MODx, I have to write \\\sum instead of \\sum as you say... is there anything to do with MODx 0.95 or is it a mistake?

              Ah sorry... this is not true... you have to use ONLY ONE backslash... maybe MODx 0.95 doesn’t strip backslashes?
                Daniele "MadMage" Calisi
                • 17895
                • 209 Posts
                I changed a bit your plugin: I put the class attribute to the images, so that their style can be changed via CSS (I removed the inline style attribute), and I also put the replacement of the single dollars (i.e. inline math formulas). Here is the code of the modified plug-in:

                /**
                 *	mimeTeX Plugin 0.2 for MODx
                 *	by Luca Allulli, April 2006
                 *	modified by Daniele Calisi, February 2007
                 *
                 *	Event: OnLoadWebDocument
                 *
                 *	Download and install mimeTeX from http://www.forkosh.com/mimetex.html
                 *
                 *	License: GNU GPL
                 *
                 */
                 
                //Begin configuration
                	global $mimetexPath;
                	$mimetexPath="cgi-bin/mimetex.cgi";
                //End configuration 
                 
                
                function replaceCodeMimetexDD($matches) {
                	global $mimetexPath;
                	return '<img class="ddlatexmath" src="'.$mimetexPath.'?'.$matches[1].'" align="middle" />';
                }
                
                function replaceCodeMimetexSD($matches) {
                	global $mimetexPath;
                	return '<img class="sdlatexmath" src="'.$mimetexPath.'?\small '.$matches[1].'" align="middle" />';
                }
                
                $e = &$modx->Event;
                
                
                switch ($e->name) {
                	case "OnLoadWebDocument":
                
                		$modx->documentObject['content']=preg_replace_callback("#\\$\\$(.*?)\\$\\$#s", "replaceCodeMimetexDD", $modx->documentObject['content']);
                		$modx->documentObject['content']=preg_replace_callback("#\\$(.*?)\\$#s", "replaceCodeMimetexSD", $modx->documentObject['content']);
                		break;
                		
                	default:	// stop here
                		break;	
                }
                
                  Daniele "MadMage" Calisi
                  • 5683
                  • 96 Posts
                  Great, thank you smiley
                  Good to know that MODx 0.9.5 doesn’t strip backslashes (I wonder why the old versions did).
                  Actually, the double-dollar was meant to give to the user the possibility to insert (easily) single dollars in the HTML...
                    • 5892
                    • 10 Posts
                    I got i to work smiley
                    but there is a bounding box around the equations
                    is there any way to remove that?

                    look here:
                    http://www.netcr.dk/index.php?id=58

                    greetings
                    Christoph
                      • 25663 MODX Staff
                      • 12,272 Posts
                      Yes Christoph, in your css after the "img" selector on line 247, add this:

                      img.ddlatexmath { border: 0 }


                      In other words, it was all in the CSS! I used firebug in Firefox to quickly figure that out ... it’s an indispensible add-on for problems like this because it’s way too easy to see the forest for the trees lots of times.
                        Ryan Thrash, MODX Co-Founder
                        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me