Changeset 143

Show
Ignore:
Timestamp:
11/20/07 19:45:27 (1 year ago)
Author:
renato
Message:

Revision of latex plugin, now works with latest svn.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • latex/INSTALL

    r34 r143  
    1 01-13-2007 
     1Originally written: 01-13-2007 
     2Last updated: 11-20-2007 
     3(tested against svn revision 1296) 
    24 
    3 Renato Mendes Coutinho 
    4 renato@cecm.usp.br 
     5Author: Renato Mendes Coutinho 
     6mailto: renato.coutinho@gmail.com 
     7elgg.org username: renato 
     8 
    59 
    610This plugin is an adaptation of the LaTeX Rendering Class written by Benjamin 
     
    1216the University of Sao Paulo (http://stoa.usp.br).  
    1317 
    14 REQUIREMENTS: 
    15 You need to have installed latex, convert (ImageMagick), identify and dvips. You 
    16 may have to set the path to them in class.latexrender.php lines 36-39.  
     18Thanks also to Rolando, for the auto-create folder function. 
     19 
     20 
     21REQUIREMENTS:  
     22 
     23You need to have installed latex, convert (ImageMagick), ghostscript, identify 
     24and dvips. You may have to set the path to them in class.latexrender.php lines 
     2536-39 if your install paths are "unusual".  
     26 
    1727 
    1828TO INSTALL: 
     
    2434 
    2535 
    26 - create the following tree under the dataroot ($CFG->dataroot which you set in config.php): 
    27 latex/, latex/tmp/ and latex/pictures/ 
    28 all with write permission (777). 
    29  
    30  
    31 - modify elgg/units/weblogs_text_process.php: 
    32 @@ -55,6 +55,9 @@ 
    33                  $run_result = preg_replace('/<a\s+/i', '<a rel="nofollow" ', $run_result); 
    34              } 
    35               
    36 +           // plugins can process text in weblogs 
    37 +           $run_result = plugin_hook("weblog_post","process",$run_result); 
    38 +            
    39              // Text cutting 
    40              // Commented out for the moment as it seems to disproportionately increase 
    41              // memory usage / load 
    42  
    43  
    4436- In order to fix a bug that cuts the backslashes when editing a post, edit the files 
    4537 
    4638elgg/lib/displaylib.php: 
    47 @@ -152,7 +152,7 @@ 
     39 
     40@@ -228,7 +228,7 @@ 
    4841             $run_result .= "<input type=\"text\" name=\"".$parameter[0]."\" value=\"".htmlspecialchars(stripslashes($parameter[1]), ENT_COMPAT, 'utf-8')."\" style=\"width: 95%\" id=\"".$cleanid."\" />"; 
    4942             break; 
     
    5245+            $run_result .= "<textarea name=\"".$parameter[0]."\" id=\"".$parameter[0]."\" style=\"width: 95%; height: 200px\">".htmlspecialchars($parameter[1], ENT_COMPAT, 'utf-8')."</textarea>"; 
    5346             break; 
    54          } 
     47         default: 
     48             if (isset($CFG->display_field_module[$parameter[2]])) { 
    5549 
    56 and elgg/units/weblogs/weblogs_posts_edit.php: 
    57 @@ -38,7 +38,7 @@ 
     50 
     51and elgg/mod/blog/lib/weblogs_posts_edit.php: 
     52 
     53@@ -85,7 +85,7 @@ 
    5854     $body .= templates_draw(array( 
    5955                                 'context' => 'databoxvertical', 
     
    6561 
    6662 
    67 - To add a button to the tinymce menu, copy the files in 
    68   elgg/_tinymce/jscripts/tiny_mce/plugins/latex and add "latex" to 
    69   elgg/units/tinymce/tinymce_js.php: 
     63- Optionally, you can add a button to the tinymce menu. Just copy the files in 
     64  the folder tinymce/latex to elgg/mod/tinymce/lib/jscripts/tiny_mce/plugins 
     65  and add "latex" to elgg/mod/tinymce/tinymce_js.php: 
    7066 
    71 circa line 48: theme_advanced_buttons1 : 
    72 circa line 58: plugins : 
     67circa line 36: $plugins = ... 
     68circa line 73: theme_advanced_buttons1 : ... 
    7369 
    74 Note that the button description is translated only to brazilian portuguese 
    75 (besides english, of course). 
     70(this feature is not that much tested in all browsers, but ideally it should work) 
    7671 
    7772 
  • latex/lib.php

    r63 r143  
    22 
    33function latex_init() { 
    4         global $CFG
     4        global $CFG, $function
    55 
    6         include_once($CFG->dirroot . "mod/latex/class.latexrender.php"); 
     6    latex_setup(); 
     7 
     8//      include_once($CFG->dirroot . "mod/latex/class.latexrender.php"); 
     9    $function['weblogs:text:process'][] = $CFG->dirroot . "mod/latex/latex_render.php"; 
    710         
    8         listen_for_event("weblog_post","process","latex_render"); 
     11        //listen_for_event("weblog_post","process","latex_render"); 
    912} 
    1013 
     
    1215} 
    1316 
    14 function latex_render($object_type,$event,$text) { 
     17function latex_setup() { 
     18    $dirs = array('latex/tmp', 'latex/pictures'); 
    1519 
    16     global $CFG; 
    17      
    18     $latexrender_path = $CFG->dataroot . "latex"; 
    19     $latexrender_path_http = $CFG->wwwroot . "_latex"; 
    20      
    21     preg_match_all("#\[tex\](.*?)\[/tex\]#si",$text,$tex_matches); 
    22  
    23     $latex = new LatexRender($latexrender_path."/pictures",$latexrender_path_http,$latexrender_path."/tmp"); 
    24  
    25     for ($i=0; $i < count($tex_matches[0]); $i++) { 
    26         $pos = strpos($text, $tex_matches[0][$i]); 
    27  
    28                 // get formula and replace blank spaces 
    29                 $latex_formula = str_replace('&nbsp;', ' ', $tex_matches[1][$i]); 
    30  
    31                 // convert to new-line <p> and <br> 
    32                 $latex_formula = preg_replace('#<p\\s*?/??>#i', '', $latex_formula); 
    33                 $latex_formula = preg_replace('#</p\\s*?/??>#i', "\n", $latex_formula); 
    34                 $latex_formula = preg_replace('#<br\\s*?/??>#i', "\n", $latex_formula); 
    35                  
    36                 // decode html entities 
    37                 $latex_formula = html_entity_decode($latex_formula); 
    38                  
    39         $url = $latex->getFormulaURL($latex_formula); 
    40  
    41                 $alt_latex_formula = htmlentities($latex_formula, ENT_QUOTES); 
    42                 $alt_latex_formula = str_replace("\r","&#13;",$alt_latex_formula); 
    43                 $alt_latex_formula = str_replace("\n","&#10;",$alt_latex_formula); 
    44  
    45         if ($url != false) { 
    46             $text = substr_replace($text, "<img src='".$url."' title='".$alt_latex_formula."' alt='".$alt_latex_formula."' align='absmiddle'>",$pos,strlen($tex_matches[0][$i])); 
    47         } else { 
    48             // unparseable or potentially dangerous latex formula 
    49             //$text = substr_replace($text, $tex_matches[1][$i],$pos,strlen($tex_matches[0][$i])); 
     20    foreach ($dirs as $dir) { 
     21        if (!file_exists($dir)) { 
     22            make_upload_directory($dir); 
    5023        } 
    5124    } 
    52     return $text; 
    5325} 
    5426 
  • latex/tinymce/latex/langs/en.js

    r34 r143  
    44 
    55tinyMCE.addToLang('',{ 
    6 template_desc : 'Insert LaTeX tags
     6template_desc : 'LaTeX
    77});