WordPress Math Publisher Plugin Home Page
Description
The “WP Math Pub” plugin for WordPress, or wpmathpub for short, displays mathematical equations within your posts, comments, and pages. It’s a simple plugin that takes advantage of Pascal Brachet’s PHP Math Publisher version 0.3 library - bundled with this plugin.
How it works
Put your plain text mathmatical expressions between custom tags that look like this:
[pmath size=xx]…[/pmath]
The optional size attribute controls how large the images will be displayed. Useful xx integer values range from 8 to 24. Size defaults to 12 when the size attribute is omitted.
I created the first version of the plugin by starting with Matteo Bertini’s wpmathpublisher version 1.0.3 WordPress plugin source code. This is why my first version (v. 1.0.4) was just a plus 1 increment to Matteo’s version; while, my current version is still backward compatible with his tagging scheme too.
Here’s an example:
-
-
[pmath](a^2+b^2)=a^2+2ab+b^2[/pmath]
Results in:
In the example above, pmath is the tag to indicate to my plugin that the text that follows up to the /pmath tag, should be automatically submitted to Pascal’s PHP Math Publisher library for creation of a transparent graphic image. Finally, the tags and its encompassed text are replaced by the graphic image for display in this blog post.
I built upon Matteo’s pmath tag by adding an optional size attribute. Pascal’s PHP Math Publisher Library supports a size parameter as shown on his demo page: here>
Here is a simple continuation of Matteo’s example - with size attribute included:
-
[pmath size=16](a^2+b^2)=a^2+2ab+b^2[/pmath]
-
-
where:
-
[pmath size=12]~a[/pmath] is defined as a
-
[pmath size=12]~b[/pmath] is defined as b
Results in:
where:
is defined as a
is defined as b
But perhaps this is a more stunning example:
-
[pmath size=8]f(x)~left~ sum{kappa=1}{infty}{delim{[}{{1/(x_kappa)^kappa}}{]}}[/pmath] ; size=8
-
-
[pmath size=12]f(x)~left~ sum{kappa=1}{infty}{delim{[}{{1/(x_kappa)^kappa}}{]}}[/pmath] ; size=12 (same as default)
-
-
[pmath size=16]f(x)~left~ sum{kappa=1}{infty}{delim{[}{{1/(x_kappa)^kappa}}{]}}[/pmath] ; size=16
-
-
[pmath size=24]f(x)~left~ sum{kappa=1}{infty}{delim{[}{{1/(x_kappa)^kappa}}{]}}[/pmath] ; size=24
Results in:
; size=8
; size=12 (same as default)
; size=16
; size=24
Source code for version 1.0.7
-
< ?php
-
/***************************************************************************************
-
Plugin Name: WP Math Publisher
-
Plugin URI: http://www.embeddedcomponents.com/blogs/wordpress/wpmathpub/
-
Description: Display mathematical equations within your posts and comments. Put your plain text <a href="http://www.xm1math.net/phpmathpublisher/doc/help.html">mathmatical expressions between [pmath size=xx]…[/pmath] tags. The optional size attribute controls how large the images will be displayed. Useful xx integer values range from 8 to 24. Size defaults to 12 when attribute omitted. Pascal Brachet’s PHP Math Publisher <a href="http://www.xm1math.net/phpmathpublisher/">library</a> is included.
-
Version: 1.0.7
-
Date: Sept. 6, 2008
-
Author: Ron Fredericks, Embedded Components
-
Author URI: http://www.embeddedcomponents.com/blogs/
-
-
Easy install notes:
-
Just copy the wpmathpub directory and all its contents into your WordPress plugins directory.
-
-
Platforms tested:
-
1) Linux Apache web server, php 4.4.4, WordPress 2.0.4, default theme, installed in subdirectory,
-
2) Linux Apache web server, php 4.4.4, WordPress 2.3.3, clasic theme, installed in root directory,
-
3) Linux Apache web server, php 4.4.4, WordPress 2.6.2, default theme, installed in subdirectory.
-
-
References:
-
Pascal Brachet’s phpmathpublisher
-
Home: http://www.xm1math.net/phpmathpublisher/
-
Usage: http://www.xm1math.net/phpmathpublisher/doc/help.html
-
Matteo Bertini’s WordPress plugin called PHP Math Publisher
-
http://www.slug.it/naufraghi/programmazione-web/wpmathpublisher
-
Randy Morrow’s WordPress plugin called Axiom
-
http://wordpress.org/extend/plugins/axiom/#post-2794
-
-
***************************************************************************************/
-
/***************************************************************************************
-
-
Copyright 2008 Ron Fredericks, Embedded Components, Inc. (email : ronf@EmbeddedComponents.com)
-
-
GNU General Public License
-
This program is free software; you can redistribute it and/or modify
-
it under the terms of the GNU General Public License as published by
-
the Free Software Foundation; either version 2 of the License, or
-
(at your option) any later version.
-
-
This program is distributed in the hope that it will be useful,
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
GNU General Public License for more details.
-
-
You should have received a copy of the GNU General Public License
-
along with this program; if not, write to the Free Software
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
***************************************************************************************/
-
// ** Begin wpmathpub Code **
-
-
//
-
// Control automatic test and set feature for write access to ‘img’ directory.
-
// Automatic test and set feature when define("AUTOCHMOD", true);
-
// Manual automatic test and set feature when define("AUTOCHMOD", false);
-
-
// Control support for [pmath] tag in blog comments
-
// Engage the [pmath] tag support in blog comments when define("ENGAGECOMMENTS", true);
-
// Disengage the [pmath] tag support in blog comments when define("ENGAGECOMMENTS", false);
-
-
// Include Pascal’s php math publisher library.
-
require_once(PHPMATHLIB.‘/mathpublisher.php’) ;
-
-
// Determine depth of relative addressing based on location of current running script: default value is that of WordPress install directory.
-
-
// Overwrite mathpublisher.php’s default pointers to /img and /fonts subdirectories with a flexible relative addressing scheme.
-
$dirfonts=$depth.$basedir.‘/fonts’;
-
$dirimg=$depth.$basedir.‘/img’;
-
-
// Create a seperate absolute pointer to the phpmathpublisher /img/ subdirectory because our relative address scheme won’t work when called from the "apply filter" php module within the WordPress Loop.
-
$abs_dirimg = get_bloginfo(‘url’).$basedir.‘/img/’;
-
-
// test for proper installation and a known run-time environment
-
-
// Attempt to make $dirimg writable if it is not writable already.
-
$abs_use_mathfilter = true;
-
if (AUTOCHMOD && $abs_dirimg_readable) {
-
$abs_use_mathfilter = false;
-
}
-
}
-
}
-
-
// Returns with <img src=http://www.yoursite.com/yourblog/wp-content/pluglins/wpmathpub/phpmathpublisher/img/some_unique_image.png/> HTML tag.
-
// Makes reference to mathfilter function included from PHPMATHLIB/mathpublisher.php code.
-
function wpmathfilter($ascii_math, $size_math)
-
{
-
global $abs_dirimg;
-
global $abs_use_mathfilter;
-
global $abs_dirimg_readable;
-
-
// Define the default font size.
-
-
if ($abs_use_mathfilter && $abs_dirimg_readable) {
-
// html_entity_decode() converts HTML entities like ">" back to standard text like ">", when present.
-
} else if ($abs_dirimg_readable) {
-
$phpmath = ‘<span style="color: red">Error:</span>’." $abs_dirimg must have write access".‘ <a href="http://wordpress.org/extend/plugins/wpmathpub/faq/" title="use ‘."’chmod 755 img’".‘ to attempt to manually fix this problem on your server">Read the official wpmathpub plugin FAQ for more details</a>’;
-
} else {
-
$phpmath = ‘<span style="color: red">Error:</span>’." wpmathpub plugin not usable under these conditions: $abs_dirimg";
-
}
-
return $phpmath;
-
}
-
-
// Create a WordPress text filter
-
function to_phpmath($content)
-
{
-
// Add an new optional font size attribute size=xx to Matteo’s original preg_replace.
-
$content = preg_replace(‘#\[pmath(\s+size=|\s?)(\d*)(\])(.*?)\[/pmath\]#sie’, ‘wpmathfilter(\’\\4\’, \’\\2\’);’, $content);
-
return $content;
-
}
-
-
// action function for above hook
-
function mt_add_pages() {
-
// Add a new submenu under Manage:
-
add_management_page(‘wpmathpub’, ‘wpmathpub’, 8, ‘wpmathpubmanage’, ‘wpmathpub_manage_page’);
-
}
-
-
// wpmathpub_manage_page() displays the page content for the Test Manage submenu
-
function wpmathpub_manage_page() {
-
global $abs_dirimg;
-
global $dirimg;
-
global $abs_use_mathfilter;
-
global $abs_dirimg_readable;
-
global $abs_addfilter_test;
-
-
if ($abs_use_mathfilter)
-
-
$arraytemp = gd_info(); // collect details on server’s support of GD graphics library
-
-
$tabcnt = 0;
-
echo "<table width=’700′ border=’0′ cellspacing=’1′ cellpadding=’1′>";
-
-
echo "<tr>";
-
echo "<th scope=’col’> </th><th scope=’col’><span style=’color: blue’><h3>wpmathpub plugin status: ".WPMATHPUBVERSION."</h3></span></th>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>Operating system:</span></th>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>PHP version:</span></th>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>PHP GD library:</span></th>";
-
echo "<td bgcolor=".$tabcolor[$tabcnt++ %2].">".((strlen($arraytemp["GD Version"])>1) ? ("version ".$arraytemp["GD Version"]) : "<span style=’color: red’> ERROR: GD library not found on this server</span>") .(($arraytemp["PNG Support"]===true) ? " with PNG format supported" : "<span style=’color: red’> ERROR: PNG format not supported</span>")."</td>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>Ownership:</span></th>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>Blog’s url:</span></th>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>WordPress version:</span></th>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>WordPress plugin name:</span></th>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>Relative img path:</span></th>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>Working directory:</span></th>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>Absolute img path:</span></th>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>img directory readable:</span></th>";
-
echo "<td bgcolor=".$tabcolor[$tabcnt++ %2].">".(($abs_dirimg_readable) ? "yes" : "<span style=’color: red’>error</span>")."</td>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>img directory writable:</span></th>";
-
echo "<td bgcolor=".$tabcolor[$tabcnt++ %2].">".(($abs_use_mathfilter) ? "yes" : "<span style=’color: red’>error</span>")."</td>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>img directory executable:</span></th>";
-
echo "<td bgcolor=".$tabcolor[$tabcnt++ %2].">".(($abs_dirimg_executable) ? "yes" : "<span style=’color: red’>error</span>")."</td>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>Content filter added:</span></th>";
-
echo "<td bgcolor=".$tabcolor[$tabcnt++ %2].">".(($abs_addfilter_test) ? "yes" : "<span style=’color: red’>error</span>")."</td>";
-
echo "</tr>";
-
-
echo "<tr>";
-
echo "<th scope=’row’ width=’240′ align=’right’><span style=’color: blue’>mathfilter(y=mx^2+b):</span></th>";
-
echo "<td bgcolor=".$tabcolor[$tabcnt++ %2].">".mathfilter("<m>".html_entity_decode("y=mx^2+b")."</m>", ‘12′, $abs_dirimg)."</td>";
-
echo "</tr>";
-
-
echo "</table>";
-
}
-
-
// Register our WordPress text filter, to_phpmath, into the two hook routines, the_content and comment_text.
-
if (!ENGAGECOMMENTS) {
-
// Register comment_text updates after all priorty comment processing filters.
-
// Note: calling the comment filter first, before the content filter, fixed comment_RSS feed errors.
-
remove_filter(‘comment_text’, ‘to_phpmath’);
-
} else {
-
add_filter(‘comment_text’, ‘to_phpmath’);
-
}
-
// Register the_content updates after all priorty content processing filters.
-
$abs_addfilter_test = add_filter(‘the_content’, ‘to_phpmath’, 5);
-
-
// Hook for adding admin menus
-
add_action(‘admin_menu’, ‘mt_add_pages’);
-
//
-
// ** End wpmathpub Code **
-
?>
Changes in version 1.0.7
- Improve compatibility with streaming video plugins that would otherwise monopolize the WordPress built-in add_filter() function which in turn cause wpmathpub [ pmath ] tagging to fail
- Add a new menu into for the WordPress blogger using the Site Admin -> Manage menu to display operating status of the wpmathpub plugin
Download plugin
The wpmathpub math publisher plugin for WordPress.org blogs is now available directly from WordPress.org’s plugin site. The WordPress.org hosted version manages several promotional and support features:
- Overview of the plugin here>
- Overview of the PHP Math Publisher library here>
- Installation instructions here>
- Example of how wpmathpub works, and how to install it here>
- Frequently Asked Questions and their answers too here>
- Metrics here>
- Download from WordPress.org here>
Support:
Share your problems, thoughts, or success with the community here:
www.embeddedcomponents.com/blogs/2008/03/wpmathpubsupport/
Donations accepted
Do you like the engineering work we do in creating better components for your reuse? Are you satisfied with this plugin? Are you using this effort to help you or your company make profit? If the answer is yes to any of these questions, perhaps you might consider making a voluntary donation.








May 20th, 2008 at 2:30 pm
This is a test of an open ended start tag embedded in a comment [pmath size=14] along with some text…
May 20th, 2008 at 2:31 pm
…and some more text e=sum{infty}{n=0}{1/{n!}}[/pmath] with an end tag to insure the new comments-enabled feature works without breaking something.
May 20th, 2008 at 2:38 pm
Comments seem to work fine, even when the tag is not used correctly. But it works even better when the math text and end tag from the previous comment are used together like this:
[ pmath size=14 ]e=sum{infty}{n=0}{1/{n!}}[ /pmath ]
or with the spaces removed from around the pmath brackets to form valid tags, like this:
to create a real equation.
May 20th, 2008 at 3:28 pm
Comments on this page are limited to Admin Team. To post a comment related to this plugin, please use this link:
http://www.embeddedcomponents.com/blogs/2008/03/wpmathpubsupport/
May 23rd, 2008 at 7:28 am
Well done job, the size attribute are great.
Still testing,
Keep the work!
June 27th, 2008 at 3:54 am
Hi all great information here and good thread to comment on.
Can I ask though - how did you get this picked up and into google news?
Very impressive that this blog is syndicated through Google and is it something that is just up to Google or you actively created?
Obviously this is a popular blog with great data so well done on your seo success..
July 24th, 2008 at 1:07 am
This is a great plug in
July 27th, 2008 at 6:36 am<