plugin:math2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:math2 [2009-12-30 13:29] – 94.217.0.35 | plugin:math2 [2023-10-30 22:54] (current) – created Klap-in | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Maths Publisher Plugin ====== | + | The math2 plugin was renamed |
- | + | ||
- | ---- plugin ---- | + | |
- | description: | + | |
- | author | + | |
- | email : chris@jalakai.co.uk | + | |
- | type : syntax | + | |
- | lastupdate : 2008-08-13 | + | |
- | compatible : 2005-09-22 and later | + | |
- | depends | + | |
- | conflicts | + | |
- | similar | + | |
- | tags : math, formula | + | |
- | ---- | + | |
- | + | ||
- | + | ||
- | This [[plugins|plugin]] makes use of [[http:// | + | |
- | + | ||
- | This is a completely self-contained PHP solution. It requires no third party packages. It makes use of [[http:// | + | |
- | + | ||
- | There is an alternative [[plugin: | + | |
- | + | ||
- | ===== PHP Installation Requirements ===== | + | |
- | + | ||
- | To run this plugin your PHP installation needs to have: | + | |
- | * tokenizer library | + | |
- | * gd library | + | |
- | * png capabilities, | + | |
- | * freetype font library | + | |
- | + | ||
- | For full details refer to the [[http:// | + | |
- | + | ||
- | + | ||
- | + | ||
- | ===== Syntax ===== | + | |
- | + | ||
- | DokuWiki Syntax: | + | |
- | <m size> | + | |
- | + | ||
- | //size// (optional) the base glyph size in pixels - default value: 12. | + | |
- | + | ||
- | // | + | |
- | + | ||
- | [[http:// | + | |
- | + | ||
- | Example: | + | |
- | < | + | |
- | < | + | |
- | <m 8> | + | |
- | <m 32> | + | |
- | + | ||
- | Result: \\ < | + | |
- | {{http:// | + | |
- | {{http:// | + | |
- | {{http:// | + | |
- | + | ||
- | + | ||
- | You can see the plugin in action [[http:// | + | |
- | ===== Installation ===== | + | |
- | + | ||
- | Plugin sources: [[http:// | + | |
- | + | ||
- | -> FIXME: **[[http:// | + | |
- | + | ||
- | The //zip// & //tar.gz// format packages maybe installed using the [[plugin: | + | |
- | + | ||
- | To install manually, download the source to your plugin folder, '' | + | |
- | + | ||
- | The folder will contain: | + | |
- | syntax.php | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | phpmathpublisher/ | + | |
- | + | ||
- | Phpmathpublisher needs GD to render the images so please check if the GD library is installed on your system. (package php4-gd for debian users) | + | |
- | + | ||
- | The plugin is now installed. | + | |
- | + | ||
- | + | ||
- | ==== ACL & Math Plugin ==== | + | |
- | + | ||
- | This plugin stores its images in DokuWiki' | + | |
- | < | + | |
- | cache_mathplugin: | + | |
- | </ | + | |
- | + | ||
- | ===== Details ===== | + | |
- | + | ||
- | ==== Configuration ==== | + | |
- | + | ||
- | The plugin will work successfully with no changes to its configuration. | + | |
- | + | ||
- | * **'' | + | |
- | * **'' | + | |
- | * **'' | + | |
- | + | ||
- | The full details of these settings are given in the plugin source code. | + | |
- | + | ||
- | ==== Plugin Source ==== | + | |
- | <code php> | + | |
- | <?php | + | |
- | /** | + | |
- | * Math Plugin: incorporate mathematical formulae using MathPublisher into DokuWiki | + | |
- | * | + | |
- | * Syntax: | + | |
- | | + | |
- | | + | |
- | | + | |
- | * | + | |
- | * Formulae syntax: | + | |
- | * | + | |
- | * @license | + | |
- | * @author | + | |
- | * @date | + | |
- | * | + | |
- | * phpmathpublisher | + | |
- | * @link | + | |
- | * @author | + | |
- | */ | + | |
- | + | ||
- | if(!defined(' | + | |
- | if(!defined(' | + | |
- | require_once(DOKU_PLUGIN.' | + | |
- | require_once(DOKU_INC.' | + | |
- | + | ||
- | global $conf; | + | |
- | + | ||
- | // -----------------------[ math plugin globals ]--------------------------------------- | + | |
- | global $mathplugin_size, | + | |
- | + | ||
- | // default base size (pixels) of glyphs in the formulae | + | |
- | $mathplugin_size = 12; | + | |
- | + | ||
- | // base url to access images, should correspond to $dirimg below. | + | |
- | // if left at default, it will be modified to add a subfolder to avoid filling | + | |
- | // the root media folder with clutter, refer _cacheExists() | + | |
- | $mathplugin_urlimg = DOKU_URL.' | + | |
- | + | ||
- | // -----------------------[ mathpublisher settings ]------------------------------------ | + | |
- | global $dirfonts, | + | |
- | + | ||
- | // absolute path to the fonts directory (must not have '/' | + | |
- | $dirfonts=dirname(__FILE__)."/ | + | |
- | + | ||
- | // absolute path to the img directory (must not have '/' | + | |
- | // if left at default, it will be modified to add a subfolder to avoid filling | + | |
- | // the root media folder with clutter, refer _cacheExists() | + | |
- | $dirimg=$conf[' | + | |
- | + | ||
- | // ------------------------------------------------------------------------------------ | + | |
- | + | ||
- | /** | + | |
- | * All DokuWiki plugins to extend the parser/ | + | |
- | * need to inherit from this class | + | |
- | */ | + | |
- | class syntax_plugin_math extends DokuWiki_Syntax_Plugin { | + | |
- | + | ||
- | // FIXME localise | + | |
- | var $str_nopng = " | + | |
- | var $str_noft = "PHP installation missing access to freetype library"; | + | |
- | var $enable = false; | + | |
- | var $msg_disable = "math plugin disabled: "; | + | |
- | var $msg_sent = false; | + | |
- | + | ||
- | function syntax_plugin_math() { | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * return some info | + | |
- | */ | + | |
- | function getInfo(){ | + | |
- | + | ||
- | return array( | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | | + | |
- | For formulae syntax visit http:// | + | |
- | | + | |
- | ' | + | |
- | ); | + | |
- | } | + | |
- | + | ||
- | function getType(){ return ' | + | |
- | function getPType(){ return ' | + | |
- | function getSort(){ return 208; } | + | |
- | + | ||
- | /** | + | |
- | * Connect pattern to lexer | + | |
- | */ | + | |
- | function connectTo($mode) { | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | function postConnect() { | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * Handle the match | + | |
- | */ | + | |
- | function handle($match, | + | |
- | global $mathplugin_size; | + | |
- | + | ||
- | if ( $state == DOKU_LEXER_UNMATCHED ) { | + | |
- | list($size, $math) = preg_split('/>/ | + | |
- | if (!is_numeric($size)) $size = $mathplugin_size; | + | |
- | + | ||
- | if (strlen($math) > 1) { | + | |
- | $c_first = $math{0}; | + | |
- | $c_last = $math{strlen($math)-1}; | + | |
- | + | ||
- | $align = ($c_first == ' ') ? ($c_last == ' ' ? ' | + | |
- | } else { | + | |
- | $align = ' | + | |
- | } | + | |
- | + | ||
- | return (array($size, | + | |
- | } | + | |
- | return false; | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * Create output | + | |
- | */ | + | |
- | function render($mode, | + | |
- | global $mathplugin_urlimg; | + | |
- | + | ||
- | if (!$data) return; | + | |
- | list($size, $math, $align) = $data; | + | |
- | + | ||
- | if($mode == ' | + | |
- | // phpmathpublisher generates many E_NOTICE errors, ensure error_reporting doesn' | + | |
- | $error_level = error_reporting(); | + | |
- | error_reporting($error_level & ~E_NOTICE); | + | |
- | + | ||
- | // check we have ability to create png images | + | |
- | if ($this-> | + | |
- | // check we have somewhere to create our images & make them | + | |
- | if ($this-> | + | |
- | require_once(dirname(__FILE__).'/ | + | |
- | $math_html = mathimage($math, | + | |
- | + | ||
- | if ($align != ' | + | |
- | $math_html = preg_replace('/< | + | |
- | } | + | |
- | + | ||
- | $renderer-> | + | |
- | } else { | + | |
- | $this-> | + | |
- | } | + | |
- | } else { | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | // return to previous error reporting level | + | |
- | error_reporting($error_level); | + | |
- | return true; | + | |
- | } | + | |
- | return false; | + | |
- | } | + | |
- | + | ||
- | function _cacheExists() { | + | |
- | global $dirimg, $mathplugin_urlimg, | + | |
- | + | ||
- | // check for default setting | + | |
- | if (!isset($dirimg) || !$dirimg) { $dirimg = $conf[' | + | |
- | if ($dirimg == $conf[' | + | |
- | // we don't want to clutter the root media dir, so create our own subfolder | + | |
- | $dirimg .= "/ | + | |
- | $mathplugin_urlimg .= " | + | |
- | + | ||
- | if (!@is_dir($dirimg)) { | + | |
- | $this-> | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | return @is_writable($dirimg); | + | |
- | } | + | |
- | + | ||
- | // return true if php installation has required libraries/ | + | |
- | function _requirements_ok() { | + | |
- | if (!function_exists(' | + | |
- | $this-> | + | |
- | return false; | + | |
- | } | + | |
- | + | ||
- | if (!function_exists(' | + | |
- | $this-> | + | |
- | return false; | + | |
- | } | + | |
- | + | ||
- | return true; | + | |
- | } | + | |
- | + | ||
- | // used to avoid multiple messages | + | |
- | function _msg($str, $lvl=0) { | + | |
- | if ($this-> | + | |
- | + | ||
- | msg($str, $lvl); | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | // would like to see this function in io.php :) | + | |
- | function _mkdir($d) { | + | |
- | global $conf; | + | |
- | + | ||
- | umask($conf[' | + | |
- | $ok = io_mkdir_p($d); | + | |
- | umask($conf[' | + | |
- | return $ok; | + | |
- | } | + | |
- | + | ||
- | } | + | |
- | + | ||
- | //Setup VIM: ex: et ts=4 enc=utf-8 : | + | |
- | </ | + | |
- | + | ||
- | ==== php math publisher ==== | + | |
- | + | ||
- | The plugin uses slightly modified version of the phpmathpublisher version 0.3 script. Only the script and fonts (and appropriate copyright files) are included in the download. | + | |
- | + | ||
- | ===== Revision History ===== | + | |
- | * 2008-08-13 --- Update plugin URL, include earlier darcs only updates | + | |
- | * 2006-12-19 --- (darcs version only) Fix for bug in images containing root expressions longer than one character ([[http:// | + | |
- | * 2005-12-17 --- Add checking for required PHP capabilities, | + | |
- | * 2005-11-21 --- Font files updated for improved support for non-standard characters (thanks again to Matthias). | + | |
- | * 2005-11-14 --- Updated to support DokuWiki style alignment syntax, correction to PType (thanks Matthias Grimm). | + | |
- | * 2005-09-05 --- Updated to correct problem with using "/" | + | |
- | * 2005-08-19 --- Updated to phpmathpublisher v0.3, size parameter added, will create and use its own image cache, report error if image cache not writable. Single file download released. | + | |
- | * 2005-07-27 --- Released. | + | |
- | + | ||
- | + | ||
- | ===== Bugs ===== | + | |
- | + | ||
- | * **Cannot download your plugin from china** : the IP of the machine hosting http:// | + | |
- | * $conf[' | + | |
- | * direct access to media-dir is denied out of the box | + | |
- | + | ||
- | => replace | + | |
- | < | + | |
- | $renderer-> | + | |
- | </ | + | |
- | with something like that | + | |
- | < | + | |
- | $renderer-> | + | |
- | </ | + | |
- | + | ||
- | > $conf[' | + | |
- | + | ||
- | **Center alignment of images does not work** due to a CSS issue. Try this patch (--- //jmiller 2009-01-27// | + | |
- | + | ||
- | <code php> | + | |
- | if ($align != ' | + | |
- | $math_html = preg_replace('/< | + | |
- | //INSERT FOLLOWING CODE: | + | |
- | if ($align == ' | + | |
- | $math_html = preg_replace('/ | + | |
- | //END OF INSERTED CODE. | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | ===== Todo ===== | + | |
- | + | ||
- | * < | + | |
- | * < | + | |
- | * Implement ability to change the background and foreground color of rendered images. | + | |
- | * I have used the [box] plugin to help contrast the black text (if you are using a dark background). This seems to work fine, however it would be great to change he text colour. | + | |
- | ===== Discussion ===== | + | |
- | + | ||
- | Thanks for the great plugin. The only issue is that it doesn' | + | |
- | + | ||
- | > That sounds pretty sensible, I'll look into adding the image. | + | |
- | + | ||
- | >> I propose a solution: the code is in [[plugin: | + | |
- | + | ||
- | >>> | + | |
- | + | ||
- | > A simple trick to increase the resolution of the image in ODT format ONLY: triple the formula size, then scale down the display size by one-third. In the ODT rendering code, replace | + | |
- | + | ||
- | < | + | |
- | $math_html = namemathimage($math, | + | |
- | + | ||
- | $renderer-> | + | |
- | </ | + | |
- | + | ||
- | > with this: | + | |
- | + | ||
- | < | + | |
- | $size *= 3; | + | |
- | $math_html = namemathimage($math, | + | |
- | + | ||
- | $aImgInfo = getimagesize($math_html); | + | |
- | $renderer-> | + | |
- | </ | + | |
- | + | ||
- | > I hope this helps somebody who's looking for print quality in their OpenOffice files. // | + | |
- | + | ||
- | + | ||
- | ----------- | + | |
- | Hello, the plugin has been working for me perfectly, but at some point it started hanging, i.e. pages with formulae start loading but never load completely, and DokuWiki doesn' | + | |
- | ----------- | + | |
- | + | ||
- | Looks like the font-size for some symbols is ignored. In my [[https:// | + | |
- | > I don't think its DokuWiki. | + | |
- | + | ||
- | * find the math plugin image directory (normally '' | + | |
- | * change the forumlae slightly, again this will force the plugin to generate a new image | + | |
- | --- // | + | |
- | >> | + | |
- | + | ||
- | + | ||
- | ---- | + | |
- | + | ||
- | Incompatible with ACL when group ALL has no right in root namespace (20060717) ... \\ | + | |
- | Hi, " | + | |
- | If possible it should be located in data/cache dir ? | + | |
- | > ugly fix : add a line with '' | + | |
- | + | ||
- | ---- | + | |
- | \\ | + | |
- | >HI! I've just installed the plugin and the PHP 4-gd library but when I try to use < | + | |
- | >Fatal error: Call to undefined function: imagettfbbox() in home/ | + | |
- | I use apache 1.3 & php4 on a Debian Sid system | + | |
- | Thanks | + | |
- | >> It sounds you don't have the free type library. For details on installing php with the freetype library, refer to [[http:// | + | |
- | |php documentation]]. --- // | + | |
- | + | ||
- | ---- | + | |
- | * Pb with plug-in - 20060117 | + | |
- | Hello, I have installes this plugin with the currrent version of DokuWiki (Septembre 2005) by the provider FREE.FR. | + | |
- | When I make a preview, all is good -> but when I save the page -> after, I see < | + | |
- | Could you said me where is the problem ? | + | |
- | > That is very odd. Do you have a link to your wiki/ | + | |
- | + | ||
- | > I have test your solution !!! And this is very strange. I [[http:// | + | |
- | >> I took a [[http:// | + | |
- | + | ||
- | ---- | + | |
- | + | ||
- | * How to question | + | |
- | Hello, love the plugin and I have a suggestion/ | + | |
- | < | + | |
- | array( | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | </ | + | |
- | + | ||
- | I used the ' | + | |
- | + | ||
- | > [[devel: | + | |
- | + | ||
- | ---- | + | |
- | === Bug in display of root expressions === | + | |
- | + | ||
- | When a root expression is longer than one character it may overwrite the root symbol and its contained expression. e.g. | + | |
- | + | ||
- | < | + | |
- | + | ||
- | < | + | |
- | + | ||
- | see http:// | + | |
- | + | ||
- | > A patch for this problem has been added to the [[http:// | + | |
- | + | ||
- | ==== Latex ==== | + | |
- | I've had the problem, that the Plugin did not give any output to the [[http:// | + | |
- | + | ||
- | I changed the following | + | |
- | + | ||
- | <code php> | + | |
- | // syntax.php below the $mode == ' | + | |
- | + | ||
- | else if($mode == ' | + | |
- | // phpmathpublisher generates many E_NOTICE errors, ensure error_reporting doesn' | + | |
- | $error_level = error_reporting(); | + | |
- | error_reporting($error_level & ~E_NOTICE); | + | |
- | + | ||
- | // check we have ability to create png images | + | |
- | if ($this-> | + | |
- | // check we have somewhere to create our images & make them | + | |
- | if ($this-> | + | |
- | require_once(dirname(__FILE__).'/ | + | |
- | $math_html = mathimage($math, | + | |
- | + | ||
- | $renderer-> | + | |
- | } else { | + | |
- | $this-> | + | |
- | } | + | |
- | } else { | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | // return to previous error reporting level | + | |
- | error_reporting($error_level); | + | |
- | return true; | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | // file phpmathpublisher/ | + | |
- | + | ||
- | // change function mathimage($text, | + | |
- | function mathimage($text, | + | |
- | + | ||
- | // add following before the original return | + | |
- | if (!is_null($latex)) { | + | |
- | $img = new TexItImage($dirimg."/ | + | |
- | $filename = $img-> | + | |
- | + | ||
- | return " | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | That is all. DokuTexIt can now display the images. If there are any questions, feel free to contact me. I will reprovide the plugin with the changes at [[http:// | + | |
- | + | ||
- | --- // | + | |
- | + | ||
- | == sqrt Format bug == | + | |
- | + | ||
- | I have the same problem with the size of root (they are to big), and i use the formula of this page for testing. (This Page has no problems.) | + | |
- | Could it by a CSS problem? If so, is it possible to use a one CSS for the Mathe Plugin? | + | |
- | http:// | + | |
- | + | ||
- | + | ||
- | + | ||
- | ==== ODT ==== | + | |
- | Hi, I use the [[plugin: | + | |
- | + | ||
- | + | ||
- | <code php> | + | |
- | // syntax.php below the $mode == ' | + | |
- | + | ||
- | else if($mode == ' | + | |
- | // phpmathpublisher generates many E_NOTICE errors, ensure error_reporting doesn' | + | |
- | $error_level = error_reporting(); | + | |
- | error_reporting($error_level & ~E_NOTICE); | + | |
- | + | ||
- | // check we have ability to create png images | + | |
- | if ($this-> | + | |
- | // check we have somewhere to create our images & make them | + | |
- | if ($this-> | + | |
- | require_once(dirname(__FILE__).'/ | + | |
- | $math_html = namemathimage($math, | + | |
- | + | ||
- | $renderer-> | + | |
- | + | ||
- | } else { | + | |
- | $this-> | + | |
- | } | + | |
- | } else { | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | // return to previous error reporting level | + | |
- | error_reporting($error_level); | + | |
- | return true; | + | |
- | } | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | // file phpmathpublisher/ | + | |
- | // add the new function | + | |
- | + | ||
- | function namemathimage($text, | + | |
- | { | + | |
- | /* | + | |
- | Creates the formula image (if the image is not in the cache) and returns the path+filename of the image. | + | |
- | */ | + | |
- | global $dirimg; | + | |
- | $nameimg = md5(trim($text).$size).' | + | |
- | $v=detectimg($nameimg); | + | |
- | if ($v==0) | + | |
- | { | + | |
- | //the image doesn' | + | |
- | $formula=new expression_math(tableau_expression(trim($text))); | + | |
- | $formula-> | + | |
- | $v=1000-imagesy($formula-> | + | |
- | // | + | |
- | ImagePNG($formula-> | + | |
- | } | + | |
- | $valign=$v-1000; | + | |
- | + | ||
- | return $dirimg."/ | + | |
- | + | ||
- | } | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | // | + | |
- | + | ||
- | ==== Error: GD library is missing or unable to create PNG images ==== | + | |
- | + | ||
- | Hi! I'm having this error (top of page): math plugin disabled: PHP's gd library is missing or unable to create PNG images | + | |
- | + | ||
- | > Your server doesn' | + | |
- | + | ||
- | >> To check the status of the GD library, you may look for a " | + | |
- | + | ||
- | === Solution a): if you use a hosted server === | + | |
- | + | ||
- | * Contact your webmaster or web admin. Note that this kind of extension consumes resources quite easily, that's why it's sometimes disabled on free/cheap hosts. | + | |
- | > --- // | + | |
- | >>oh I'm seeing; but now I'm having a strange problem 8-o. math2 is working fine ...BUT only with admin account :-( ..how can i solve this? :) | + | |
- | >>> | + | |
- | >>> | + | |
- | >>>> | + | |
- | >>>> | + | |
- | >>>> | + | |
- | + | ||
- | === Solution b): if you're your own server administrator === | + | |
- | + | ||
- | > I have some Apache/PHP installation running on Windows (e.g. XAMPPlite), can I add those libraries? How? -- Manuel | + | |
- | + | ||
- | >> GD library should be included with all PHP distributions by default, check its installation instructions of the support materials associated with XAMPP. | + | |
- | + | ||
- | >>> | + | |
- | + | ||
- | ==== Problem With Rendering ==== | + | |
- | Hi, I have the following problem: after installation (I did not change anything) I tried the example from this page: | + | |
- | + | ||
- | < | + | |
- | <m 8> | + | |
- | <m 32> | + | |
- | + | ||
- | It does render it, but some symbols like " | + | |
- | + | ||
- | What could be the reason for that? | + | |
- | + | ||
- | P.S. As a suggestion: does it use different methods to render standard symbols (numbers, " | + | |
- | + | ||
- | ==== Correction ==== | + | |
- | http:// | + |
plugin/math2.1262176167.txt.gz · Last modified: 2009-12-30 13:29 by 94.217.0.35