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:
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:
-
-
where:
Results in:
where:
is defined as a
is defined as b
But perhaps this is a more stunning example:
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
Maybe it is good plugin,
but,the mathematics equation is wrong:(
July 27th, 2008 at 4:14 pm
Thanks for the recognition, ipang. You point out one of the key advantages to my plug-in – you can make fixes to equations very easily. I could go back and fix the original very easily by changing the math text, but then readers of my blog would not understand the value of your comment. So I will fix it here:
The fix only requires a reversal of the initial to finial summation values. from this:
[ pmath size=14 ]e=sum{infty}{n=0}{1/{n!}}[ /pmath ]
To this:
[ pmath size=14 ]e=sum{n=0}{infty}{1/{n!}}[ /pmath ]
Which then gets automatically published, like this via the wpmathpub plug-in itself:
November 2nd, 2008 at 11:41 am
Good plug-in !
but there is a mistake in your example…
(a^2+b^2)!=a^2+2ab+b^2
November 11th, 2008 at 3:01 pm
Good post.
November 12th, 2008 at 1:24 pm
Keep up the good work!
December 8th, 2008 at 2:29 pm
Good post.
December 10th, 2008 at 3:03 am
This is a great plugin
December 20th, 2008 at 1:26 am
Thanks for this plugin, that’s exactly what I was looking for. Works great with Wordpress 2.7 by the way. Keep up the great work !
January 27th, 2009 at 10:36 am
The main library is great. but when I saw that this can be used as wordpress plugin and u did that I am really happy to get this plugin. Thanks for your effort…
January 29th, 2009 at 11:37 pm
I really like the layout and colors that you chose for this website! It certainly is incredible!
February 20th, 2009 at 1:55 am
[ pmath size=14 ]e=sum{infty}{n=0}{1/{n!}}[ /pmath ]
Editor’s note: A person calling themselves “test” posted this message with a wpmathpub string that included spaces between the brackets “[" and the "pmath" / "/pmath" tags. The use of space allows a person to post the text and as such the conversion to a math graphic does not take place. Below is the same text string but without the spaces.
April 3rd, 2009 at 8:48 pm
Amazing plugin, nice work, thanks for share!
April 6th, 2009 at 11:39 am
That’s interesting and very valuable, but I would consider using WP-Latex, that’s pretty much the same thing but with a widely covered and known language.
Thanks for this plugin!
April 6th, 2009 at 1:33 pm
Hi Vinicius:
LaTEx and mathml are both official standards for publishing. Yet many I have talked to find the server overhead more complex with these all inclusive standards. So my plug-in meets the needs of mathmaticians and math enthusiasts that are not web server experts or can not afford to maintain server support for these larger tools.
That’s why wp-latex has a similar number of downloads at 2,058 total downloads compared to wpmathpub at 1,544 – as seen on the wordpress.org/extend/plugins site today.
May 6th, 2009 at 7:15 am
Good plugin, very helpful and easy to use, thanks.
May 9th, 2009 at 12:11 am
Is it compatible with WordPress 2.8?
May 11th, 2009 at 12:22 am
What WordPress 2.8? Latest version of Wordpress.org blog software is version 2.7.1.
June 25th, 2009 at 5:04 am
Great. Let me try here:
[ pmath ] {{250*(80a+1)+2b]-250} / 2 [ /pmath ]
June 26th, 2009 at 12:45 pm
Hi Kafe Chew:
Your pmath encoded equation did not work because your braces were not balanced. Here is an updated version of your equation:
In general I suggest you test your equation text before posting it into a comment since you will not be able to edit the comment once posted. You can use this help page to test your text:
http://www.xm1math.net/phpmathpublisher/examples/online_demo.php
Note: For phpmathpublisher, you would use the tag < m > and < /m > instead of [ pmath ] and [ /pmath ], without the whitespace
June 29th, 2009 at 2:55 pm
Great plugin and it seems to work with WP 2.8
July 12th, 2009 at 1:19 pm
Thanks drdee:
for the update on WP version 2.8 and your nice comment.
Ron
October 24th, 2009 at 4:26 pm
I came accross this nice little documentation page for WPmathPub.
http://www.mark-wilson.net/wp-content/uploads/2009/05/wpmathpub.pdf
Nice going Mark.
November 1st, 2009 at 2:30 am
February 26th, 2010 at 9:24 pm
Thank you for a great plugin. I’m very appreciate it. Cheers!
March 10th, 2010 at 9:06 pm
Hi , Very good plugin. It started working without additional installation, like other plugin.
I am wondering if there is way to simplify following expression.
For example.
Present value of future cash flow
If i remove space between – N, result looks odd
![Pv = A[ (1 - (1+r)^(-N))/r] Pv = A[ (1 - (1+r)^(-N))/r]](http://www.embeddedcomponents.com/blogs/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_981_8cc10264094b723a6c65f668a2575db7.png)