We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 476
    • 14 Posts
    This is an auto-generated support/comment thread for mimeTeX.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    This plugin lets you easily embed LaTeX math in your MODx documents.
      • 6705
      • 79 Posts
      Does anybody know if the mimeTeX plugin (0.5.1) will still work with current MODx versions (ie, 0.9.6.3)?

      I have tried to install the plugin, and it seems to work as follows:

      * It recognises that there is text within the <tex> tags.
      * It converts that part of my page to an image link, to a file in the assets/cache folder.
      * It (presumably) triggers the mimetex.cgi to create a corresponding file in the folder, however this file has zero size (and therefore, obviously, no content).

      I can run mimetex.cgi directly (passing appropriate TeX to it), and it works as expected. It seems that it is the plugin that is stumbling somewhere, and not calling the cgi correctly?

      Is there anybody using mimeTeX, who might have any ideas?
        Please don't PM me unless it's absolutely essential: if a technical question is worth asking, it's worth asking in public, so that others can share their experience, and so that all can learn from the answers.
        • 32998
        • 3 Posts
        The issues I found with this plugin were that the rich text editor included with MODx will strip the invalid <tex> tag. The other being that it doesn’t set alt attribute. The updated code now uses the <pre class="math"> tag and also sets the alt attribute.

        The updated code is as follows, and it can also be found here

        /*
        mimeTeX Plugin
        ===================
        
        This plugin lets you easily embed LaTeX math in your html pages.
        Version: 0.2, 2007-04-01, Luca Allulli
        Version: 0.2.1, 2007-02-01, Daniele "MadMage" Calisi
        Version: 0.5.1, 2007-06-08, Americo Dias
        Version: 0.5.2, 2007-11-01, Yacoby
        
        Authors: Luca Allulli, Americo Dias
                http://www.amdias.com
        
        License: CC-GNU LGPL
                http://creativecommons.org/licenses/LGPL/2.1/
        
        MODx version: 0.9.5
        
        See mimeTeX.txt for details.
         */
         
        /* <?php */
        
        // Please install mimetex CGI on your own server and update the following line.
        $mimetex_url = 'http://www.example.com/cgi-bin/mimetex.cgi';
        
        // Change the following line if you want to change the cache formulas. Don't forget to have write permitions!
        $cache_folder = 'assets/cache/';
        
        // Grab and evluate the document event.
        $mdStrEvent = &$modx->Event;
        
        if ( $mdStrEvent->name == "OnWebPagePrerender" ){
                                
                // Grab the raw document output.
                $mdStrDocOutput = $modx->documentOutput;
        
                // Search the raw document output for blocks to be parsed. Those blocks are marked with <markdown> and </markdown> tags.
                preg_match_all( "|<pre class=\"math\">(.*)</pre>|Uis", $mdStrDocOutput, $mdArrParseBlocks);
        
                // Get the parsed output for each block.
        
                // If no blocks found, exit
                if( count($mdArrParseBlocks) == 0 ){
                        return;
                }
                                                        
                // Process the formulas...
                for ( $i=0; $i<count( $mdArrParseBlocks[0] ); $i++ ){
                        $mdBlock = $mdArrParseBlocks[0][$i];
                                
                        // Create a unique formula filename using the formula text and MD5
                        $formula_text = $mdArrParseBlocks[1][$i];
                        $formula_hash = md5($formula_text);
                        $formula_filename = 'etx_'.$formula_hash.'.gif';
                                
                        $cache_formula_path = $modx->config['base_path'] . $cache_folder . $formula_filename;
                        $cache_formula_url = $modx->config['site_url'] . $cache_folder . $formula_filename;
                                
                        // Is the formula image cached?
                        if (!is_file($cache_formula_path)){
                                // If not, create the image
                                $mimetex_host = curl_init($mimetex_url . '?formdata=' . urlencode($formula_text));
        
                                // and save it to the cache path
                                $cache_file = fopen($cache_formula_path, 'w');
                                curl_setopt($mimetex_host, CURLOPT_FILE, $cache_file);
                                curl_setopt($mimetex_host, CURLOPT_HEADER, 0);
                                curl_exec($mimetex_host);
                                curl_close($mimetex_host);
                                fclose($cache_file);
                        }
                                
                        $mdBlockText = '<img src="' . $cache_formula_url . '" alt="'.$formula_text.'"  border=0 align=middle>';
                        $mdStrDocOutput = str_replace( $mdBlock, $mdBlockText, $mdStrDocOutput );
                }
        
                // Overwrite the raw document output with parsed one.
                $modx->documentOutput = $mdStrDocOutput;
        }
        /* ?> */