• [PLUGIN] mimeTeX: bring LaTeX to MODx!#

  • Commodore64 Reply #1, 6 years ago

    Reply
    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:
      [list]
    • 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!
    [/list]

    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;	
    }
    


  • davidm Reply #2, 6 years ago

    Reply
    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 !


  • schwieni Reply #3, 5 years, 5 months ago

    Reply
    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


  • Commodore64 Reply #4, 5 years, 5 months ago

    Reply
    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).


  • madmage Reply #5, 5 years, 3 months ago

    Reply
    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?


  • madmage Reply #6, 5 years, 3 months ago

    Reply
    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?


  • madmage Reply #7, 5 years, 3 months ago

    Reply
    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;	
    }
    


  • Commodore64 Reply #8, 5 years, 3 months ago

    Reply
    Great, thank you 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...


  • cr Reply #9, 4 years, 11 months ago

    Reply
    I got i to work 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


  • rthrash Reply #10, 4 years, 11 months ago

    Reply
    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.