Plugin Directory

Changeset 522668


Ignore:
Timestamp:
03/23/2012 01:18:55 PM (14 years ago)
Author:
mathzqy
Message:

now you can turn off images

Location:
latex/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • latex/trunk/latex-admin.php

    r522181 r522668  
    4747        <tbody>
    4848        <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>
    4959            <th><label><input name="latex_img_server" type="radio"
    5060            value="<?php echo $latex_img_servers[0];?>" class="tog"
     
    8191            <th>
    8292                <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'";?>>
    8494                Custom Service          </label>
    8595            </th>
  • latex/trunk/latex.php

    r522223 r522668  
    44Plugin URI: http://wordpress.org/extend/plugins/latex/
    55Description: 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.31
     6Version: 3.4
    77Author: zhiqiang
    88Author URI: http://zhiqiang.org
     
    6666//  if (get_option("latex_cache_path") == FALSE )   
    6767        update_option("latex_cache_path", ABSPATH."wp-content/plugins/latex/cache/");
     68        update_option("latex_turnoff", true);
    6869        update_option("latex_mathjax_config", '<script type="text/x-mathjax.config"> \n'.
    6970'        MathJax.Hub.Config({ \n' .
     
    131132            $formula_text=substr($formula_text, 1);
    132133        }
    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            }
    154158           
    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       
    156166        }
    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;
    164170        $iflatexexists = true;
    165171        $formula_text = decode_entities_latex(utf8_decode(html_entity_decode($formula_text)));
     
    167173       
    168174        // 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>":"");
    171178    }
    172179}
     
    183190global $iflatexexists;
    184191
    185     if($iflatexexists){
     192    if($iflatexexists && get_option("mathjax_server") !=""){
    186193echo stripcslashes(get_option('latex_mathjax_config'));
    187194
  • latex/trunk/readme.txt

    r522182 r522668  
    1 === Latex for WordPress ===
     1=== LaTeX for WordPress ===
    22Contributors: zhiqiang
    33Donate link:
    4 Tags: latex, formatting, mimetex,tex, math, equations, mathematics, formula
     4Tags: LaTeX, formatting, mimetex,tex, math, equations, mathematics, formula
    55Requires at least: 2.3
    6 Tested up to: 3.3
     6Tested up to: 3.31
    77Stable tag: trunk
    88
     
    1111== Description ==
    1212
     13verion logs:
     14
     15ver 3.4: Now you can turn off displaying formula as images. Use this when your server has problem to fetch LaTeX images.
     16
     17ver 3.3: Fix the bug to display LaTeX source code.
     18
     19ver 3.2: Load MathJax only when needed.
     20
     21ver 3.0: Using MathJax and Images to display LaTeX formula.
     22
    1323Using 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.
    1424
    15 You can type the formula in LaTex, in title, posts, pages and comments:
     25You can type the formula in LaTeX, in title, posts, pages and comments:
    1626
    1727* `\(\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 latex equation in math mode(it will be displayed centerly in a single line).
    19 * `\(\alpha+\beta\geq\gamma!\)` display the source of the latex formula. 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 `\]`.
    2030
    2131This 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>.
     
    2333The 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.
    2434
    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 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.
     35However, 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.
    2636
    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 LaTex image generating service.
     37There 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.
    2838
    2939Other features are added in version 3.2+:
     
    3242
    3343
    34 Chinese document: http://zhiqiang.org/blog/it/latex-for-wordpress.html
     44Chinese document: http://zhiqiang.org/blog/it/LaTeX-for-wordpress.html
    3545
    3646
     
    3848= Installation instruction =
    3949
    40 1. Upload `latex` fold to the `/wp-content/plugins/` directory
    41 1. Activate the plugin `Latex for WordPress` through the 'Plugins' menu in WordPress
    42 1. The diretory `/wp-content/plugins/latex/cache` should be writable by your webserver (chmod 777 will do the trick).
     501. Upload `LaTeX` fold to the `/wp-content/plugins/` directory
     511. Activate the plugin `LaTeX for WordPress` through the 'Plugins' menu in WordPress
     521. The diretory `/wp-content/plugins/LaTeX/cache` should be writable by your webserver (chmod 777 will do the trick).
    43531. done
    4454
     
    5161In 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.
    5262
    53 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.
     63In 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.
    5464
    5565
    56 = Install your own latex image service =
     66= Install your own LaTeX image service =
    5767
    5868As I known, MimeTex is the easiest one to build up:
     
    6777= 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? =
    6878
    69 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.
     79When 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.
    7080
    7181== Screenshots ==
Note: See TracChangeset for help on using the changeset viewer.