Changeset 522668
- Timestamp:
- 03/23/2012 01:18:55 PM (14 years ago)
- Location:
- latex/trunk
- Files:
-
- 3 edited
-
latex-admin.php (modified) (2 diffs)
-
latex.php (modified) (5 diffs)
-
readme.txt (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
latex/trunk/latex-admin.php
r522181 r522668 47 47 <tbody> 48 48 <tr> 49 <th> 50 <label><input name="latex_img_server" type="radio" value="" class="tog" 51 <?php echo get_option('latex_img_server')!=""?"":"checked='checked'";?>> 52 Turn off Images </label> 53 </th> 54 <td> 55 MathJax is enough for me, I don't want to display formula as images. 56 </td> 57 </tr> 58 <tr> 49 59 <th><label><input name="latex_img_server" type="radio" 50 60 value="<?php echo $latex_img_servers[0];?>" class="tog" … … 81 91 <th> 82 92 <label><input name="latex_img_server" type="radio" value="custom" class="tog" 83 <?php echo in_array(get_option('latex_img_server'), $latex_img_servers)?"":"checked='checked'";?>>93 <?php echo (in_array(get_option('latex_img_server'), $latex_img_servers)||get_option('latex_img_server')=="")?"":"checked='checked'";?>> 84 94 Custom Service </label> 85 95 </th> -
latex/trunk/latex.php
r522223 r522668 4 4 Plugin URI: http://wordpress.org/extend/plugins/latex/ 5 5 Description: Using MathJax and LaTex image service, this plugin provides a general solution to add and display your mathematical fourmula, no matter the visitors are visiting your blog or read from Google Reader. 6 Version: 3. 316 Version: 3.4 7 7 Author: zhiqiang 8 8 Author URI: http://zhiqiang.org … … 66 66 // if (get_option("latex_cache_path") == FALSE ) 67 67 update_option("latex_cache_path", ABSPATH."wp-content/plugins/latex/cache/"); 68 update_option("latex_turnoff", true); 68 69 update_option("latex_mathjax_config", '<script type="text/x-mathjax.config"> \n'. 69 70 ' MathJax.Hub.Config({ \n' . … … 131 132 $formula_text=substr($formula_text, 1); 132 133 } 133 134 $formula_hash = md5($formula_text); 135 $formula_filename = 'tex_'.$formula_hash.'.gif'; 136 137 $cache_path = ABSPATH . '/wp-content/plugins/latex/cache/'; 138 $cache_formula_path = $cache_path . $formula_filename; 139 $cache_url = get_bloginfo('wpurl') . '/wp-content/plugins/latex/cache/'; 140 $cache_formula_url = $cache_url . $formula_filename; 141 142 if ( !is_file($cache_formula_path) || filesize($cache_formula_path) < 10) { 143 if (!class_exists('Snoopy')) 144 require_once (ABSPATH.'/wp-includes/class-snoopy.php'); 145 146 $snoopy = new Snoopy; 147 $formula_text_html = str_replace('%C2%A0', '%20', 148 rawurlencode(html_entity_decode(preg_replace('/\\\\label{.*?}/', '', $formula_text)))); 149 $snoopy->fetch(get_option('latex_img_server').$formula_text_html); 150 if (strlen($snoopy->results) < 10) 151 $snoopy->fetch('http://www.quantnet.com/cgi-bin/mathtex.cgi?'.rawurlencode(($formula_text))); 152 $cache_file = fopen($cache_formula_path, 'w'); 153 fputs($cache_file, $snoopy->results); 134 if (get_option('latex_img_server') != "") { 135 $formula_hash = md5($formula_text); 136 $formula_filename = 'tex_'.$formula_hash.'.gif'; 137 138 $cache_path = ABSPATH . '/wp-content/plugins/latex/cache/'; 139 $cache_formula_path = $cache_path . $formula_filename; 140 $cache_url = get_bloginfo('wpurl') . '/wp-content/plugins/latex/cache/'; 141 $cache_formula_url = $cache_url . $formula_filename; 142 143 if ( !is_file($cache_formula_path) || filesize($cache_formula_path) < 10) { 144 if (!class_exists('Snoopy')) 145 require_once (ABSPATH.'/wp-includes/class-snoopy.php'); 146 147 $snoopy = new Snoopy; 148 $formula_text_html = str_replace('%C2%A0', '%20', 149 rawurlencode(html_entity_decode(preg_replace('/\\\\label{.*?}/', '', $formula_text)))); 150 $snoopy->fetch(get_option('latex_img_server').$formula_text_html); 151 if (strlen($snoopy->results) < 10) 152 $snoopy->fetch('http://www.quantnet.com/cgi-bin/mathtex.cgi?'.rawurlencode(($formula_text))); 153 $cache_file = fopen($cache_formula_path, 'w'); 154 fputs($cache_file, $snoopy->results); 155 156 fclose($cache_file); 157 } 154 158 155 fclose($cache_file); 159 $size = getimagesize($cache_formula_path); 160 $height = $size[1]; 161 $padding = ""; 162 if ($height <= 10) $padding = "padding-bottom:2px;"; 163 else if ($height <= 14) $padding = "padding-bottom:1px;"; 164 } else { 165 156 166 } 157 158 $size = getimagesize($cache_formula_path); 159 $height = $size[1]; 160 $padding = ""; 161 if ($height <= 10) $padding = "padding-bottom:2px;"; 162 else if ($height <= 14) $padding = "padding-bottom:1px;"; 163 global $iflatexexists; 167 168 169 global $iflatexexists; 164 170 $iflatexexists = true; 165 171 $formula_text = decode_entities_latex(utf8_decode(html_entity_decode($formula_text))); … … 167 173 168 174 // returning the image-tag, referring to the image in your cache folder 169 if($imgtext) return "<p style='text-align:center;'><span class='MathJax_Preview'><img src='$cache_formula_url' style='".get_option('latex_imgcss')."' class='tex' alt=\"".($formula_text)."\" /></span>".(get_option("mathjax_server") != ""?"<script type='math/tex; mode=display'>".($formula_text)."</script>":"")."</p>"; 170 else return "<span class='MathJax_Preview'><img src='$cache_formula_url' style='".get_option('latex_imgcss')." $padding' class='tex' alt=\"".($formula_text)."\" /></span>".(get_option("mathjax_server") != ""?"<script type='math/tex'>".($formula_text)."</script>":""); 175 if($imgtext) return "<p style='text-align:center;'><span class='MathJax_Preview'>".(get_option('latex_img_server')==""?"\[".($formula_text)."\]":"<img src='$cache_formula_url' style='".get_option('latex_imgcss')."' class='tex' alt=\"".($formula_text)."\" />")."</span>".(get_option("mathjax_server") != ""?"<script type='math/tex; mode=display'>".($formula_text)."</script>":"")."</p>"; 176 177 else return "<span class='MathJax_Preview'>".(get_option('latex_img_server')==""?"\(".($formula_text)."\)":"<img src='$cache_formula_url' style='".get_option('latex_imgcss')." $padding' class='tex' alt=\"".($formula_text)."\" />")."</span>".(get_option("mathjax_server") != ""?"<script type='math/tex'>".($formula_text)."</script>":""); 171 178 } 172 179 } … … 183 190 global $iflatexexists; 184 191 185 if($iflatexexists ){192 if($iflatexexists && get_option("mathjax_server") !=""){ 186 193 echo stripcslashes(get_option('latex_mathjax_config')); 187 194 -
latex/trunk/readme.txt
r522182 r522668 1 === La texfor WordPress ===1 === LaTeX for WordPress === 2 2 Contributors: zhiqiang 3 3 Donate link: 4 Tags: latex, formatting, mimetex,tex, math, equations, mathematics, formula4 Tags: LaTeX, formatting, mimetex,tex, math, equations, mathematics, formula 5 5 Requires at least: 2.3 6 Tested up to: 3.3 6 Tested up to: 3.31 7 7 Stable tag: trunk 8 8 … … 11 11 == Description == 12 12 13 verion logs: 14 15 ver 3.4: Now you can turn off displaying formula as images. Use this when your server has problem to fetch LaTeX images. 16 17 ver 3.3: Fix the bug to display LaTeX source code. 18 19 ver 3.2: Load MathJax only when needed. 20 21 ver 3.0: Using MathJax and Images to display LaTeX formula. 22 13 23 Using MathJax and images, this plugin provides a general and elegant solution to add and display your mathematical fourmula, no matter the visitors are visiting your blog or read from Google Reader. 14 24 15 You can type the formula in LaTe x, in title, posts, pages and comments:25 You can type the formula in LaTeX, in title, posts, pages and comments: 16 26 17 27 * `\(\alpha+\beta\geq\gamma\)` or `$$\alpha+\beta\geq\gamma$$` add an inline formula 18 * `\[\alpha+\beta\geq\gamma\]` or `$$!\alpha+\beta\geq\gamma$$` add an latexequation in math mode(it will be displayed centerly in a single line).19 * `\(\alpha+\beta\geq\gamma!\)` display the source of the latexformula. Just add a `!` before `\)` or `\]`.28 * `\[\alpha+\beta\geq\gamma\]` or `$$!\alpha+\beta\geq\gamma$$` add an LaTeX equation in math mode(it will be displayed centerly in a single line). 29 * `\(\alpha+\beta\geq\gamma!\)` display the source of the LaTeX formula. Just add a `!` before `\)` or `\]`. 20 30 21 31 This plugin provides (and recommend) you a choice to use MathJax to display formula in your blog. MathJax is an open source JavaScript display engine for mathematics that works in all modern browsers. It uses modern CSS and web fonts, instead of equation images or Flash, so equations scale with surrounding text at all zoom levels. I would say that MathJax turns the previous ugly mathematics fourmula on web into arts. You can check it in <a href='mathjax.org'>mathjax.org</a> or <a href='http://zhiqiang.org/blog/finance/school/risk-aversion-in-portfolio-optimization.html'>zhiqiang.org</a>. … … 23 33 The plugin uses copy of Mathjax from their CDN Service by default, you can also install your own MathJax. It's easy, just following the link in the setting page of this plugin. 24 34 25 However, MathJax is not perfect. It's somewhat slow to load in the first time; It requires the users turn on their browsers' JavaScript; The fourmula don't work on Google Reader. To complement this, The plugin also uses the LaTe ximage service to generate images for your mathematical fourmula. In the case of the MathJax was not loading, the plugin displays the images instead. So it provide seamless solution to display mathematical formula of your posts everywhere.35 However, MathJax is not perfect. It's somewhat slow to load in the first time; It requires the users turn on their browsers' JavaScript; The fourmula don't work on Google Reader. To complement this, The plugin also uses the LaTeX image service to generate images for your mathematical fourmula. In the case of the MathJax was not loading, the plugin displays the images instead. So it provide seamless solution to display mathematical formula of your posts everywhere. 26 36 27 There are lots of websites provide such services, for example, wordpress.com and Google Charts. The plugin provide four candidates for you, and you can choose any of them or customize it to use your own LaTe ximage generating service.37 There are lots of websites provide such services, for example, wordpress.com and Google Charts. The plugin provide four candidates for you, and you can choose any of them or customize it to use your own LaTeX image generating service. 28 38 29 39 Other features are added in version 3.2+: … … 32 42 33 43 34 Chinese document: http://zhiqiang.org/blog/it/ latex-for-wordpress.html44 Chinese document: http://zhiqiang.org/blog/it/LaTeX-for-wordpress.html 35 45 36 46 … … 38 48 = Installation instruction = 39 49 40 1. Upload ` latex` fold to the `/wp-content/plugins/` directory41 1. Activate the plugin `La texfor WordPress` through the 'Plugins' menu in WordPress42 1. The diretory `/wp-content/plugins/ latex/cache` should be writable by your webserver (chmod 777 will do the trick).50 1. Upload `LaTeX` fold to the `/wp-content/plugins/` directory 51 1. Activate the plugin `LaTeX for WordPress` through the 'Plugins' menu in WordPress 52 1. The diretory `/wp-content/plugins/LaTeX/cache` should be writable by your webserver (chmod 777 will do the trick). 43 53 1. done 44 54 … … 51 61 In most cases, you don't need any more configurations. However, you have lots of choices in the setting page of this plugin if you like. 52 62 53 In the setting page, you can choose or customize the LaTe ximage server and the MathJax server, or you can turn off the MathJax if you don't like the slow MathJax.63 In the setting page, you can choose or customize the LaTeX image server and the MathJax server, or you can turn off the MathJax if you don't like the slow MathJax. 54 64 55 65 56 = Install your own lateximage service =66 = Install your own LaTeX image service = 57 67 58 68 As I known, MimeTex is the easiest one to build up: … … 67 77 = The background of my blog is black and the words are black. The equation by this plugin is black and the backgound is white. How can I make them consistent? = 68 78 69 When the generated images are transparent, they are fit to any background. Otherwise, you need to use a La tex image service which supports custom background and foreground color. `http://l.wordpress.com/latex.php?bg=ffffff&fg=000000&latex=` is a good candidate. The bg parameter defines background color and fg parameter defines foreground color, you can customize them to any RGB colors.79 When the generated images are transparent, they are fit to any background. Otherwise, you need to use a LaTeX image service which supports custom background and foreground color. `http://l.wordpress.com/LaTeX.php?bg=ffffff&fg=000000&LaTeX=` is a good candidate. The bg parameter defines background color and fg parameter defines foreground color, you can customize them to any RGB colors. 70 80 71 81 == Screenshots ==
Note: See TracChangeset
for help on using the changeset viewer.