We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5892
    • 10 Posts
    Hello
    I’m trying to bring the power of latex to modxcms
    it worked fine with the mimetex plugin
    but now i’ve been working with that for a log time
    and would like to move on to real latex with
    the latexrender program
    http://www.mayer.dial.pipex.com/tex.htm
    works with phpBB and others.
    All i need is a plugin similar to mimetex

    After several hours of writing phpcode which I don’t understand
    I will ask in this forum.


    as anyone can see i have used the fantastic plugin from Luca Allulli and Daniele Calsisi
    (thanx for the great work.) to start out with
    but it does not at all work

    so maybe someone can help me?

    at the moment i run the website on a local copy on 192.168.1.4

    scincerily
    Christoph

    /**
     *	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 $latexrender_path;
    	$latexrender_path="/home/cr/www/modx/mod/latexrender";
    //End configuration 
     function latex_content($text) {
        // --------------------------------------------------------------------------------------------------
        // adjust this to match your system configuration
        $latexrender_path = "/home/cr/www/modx/mod/latexrender";
        $latexrender_path_http = "http://192.168.1.4/~cr/modx/mod/latexrender";
    
    
        // --------------------------------------------------------------------------------------------------
    
        include_once($latexrender_path."/class.latexrender.php");
    
        preg_match_all("#\[tex\](.*?)\[/tex\]#si",$text,$tex_matches);
    
    
        $latex = new LatexRender($latexrender_path."/pictures",$latexrender_path_http."/pictures",$latexrender_path."/tmp");
     for ($i=0; $i < count($tex_matches[0]); $i++) {
            $pos = strpos($text, $tex_matches[0][$i]);
            $latex_formula = $tex_matches[1][$i];
            $url = $latex->getFormulaURL($latex_formula);
    
                    $alt_latex_formula = htmlentities($latex_formula, ENT_QUOTES);
                    $alt_latex_formula = str_replace("\r","
    ",$alt_latex_formula);
                    $alt_latex_formula = str_replace("\n","
    ",$alt_latex_formula);
    
            if ($url != false) {
                $text = substr_replace($text, "<img src='".$url."' title='".$alt_latex_formula."' alt='".$alt_latex_formula."' align=absmiddle>",$pos,strlen($tex_matches[0][$i]));
            } else {
                $text = substr_replace($text, "[Unparseable or potentially dangerous latex formula. Error $latex->_errorcode $latex->_errorextra]",$pos,strlen($tex_matches[0][$i]));
            }
        }
        return $text;
    }
    
    
    
    function replaceCodeMimetexDD($matches) {
    	global $latexrender_path;
    	return '<img class="ddlatexmath" src="'.$latexrender_path.'?'.$matches[1].'" align="middle" />';
    }
    
    /*
    *function replaceCodeMimetexSD($matches) {
    *	global $latexrender_path;
    *	return '<img class="sdlatexmath" src="'.$latexrender_path.'?\small '.$matches[1].'" align="middle" />';
    *}
    */
    $e = &$modx->Event;
    
    
    switch ($e->name) {
    	case "OnLoadWebDocument":
    
    		$modx->documentObject['content']=preg_replace_callback("#\[tex\](.*?)\[/tex\]#si", "replaceCodeMimetexDD", $modx->documentObject['content']);
    		//$modx->documentObject['content']=preg_replace_callback("#\\$(.*?)\\$#s", "replaceCodeMimetexSD", $modx->documentObject['content']);
    		break;
    		
    	default:	// stop here
    		break;	
    }