WordPress Math Publisher Plugin Home Page


The “WP Math Pub” plugin for WordPress, or wpmathpub for short, displays mathematical equations within your posts 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 this plugin by starting with Matteo Bertini’s wpmathpublisher version 1.0.3 WordPress plugin source code. This is why my version is just a plus 1 increment to Matteo’s version and is backward compatible with his tagging scheme too.

Here’s an example:

WordPress code…

Results in:


I built upon Matteo’s tag method by adding an optional size atriibute.

Here is a simple continuation of Matteo’s example:

WordPress code…
[pmath size=16](a^2+b^2)=a^2+2ab+b^2[/pmath]
[pmath size=12]~a[/pmath] is defined as a
[pmath size=12]~b[/pmath] is defined as b

Results in:


~a is defined as a
~b is defined as b

But perhaps this is a more stunning example:

WordPress code…
[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:

f(x)~left~ sum{kappa=1}{infty}{delim{[}{{1/(x_kappa)^kappa}}{]}}, size=8

f(x)~left~ sum{kappa=1}{infty}{delim{[}{{1/(x_kappa)^kappa}}{]}}, size=12 (same as default)

f(x)~left~ sum{kappa=1}{infty}{delim{[}{{1/(x_kappa)^kappa}}{]}}, size=16

f(x)~left~ sum{kappa=1}{infty}{delim{[}{{1/(x_kappa)^kappa}}{]}}, size=24

Source code listing


Code (php)
  1. <?php
  2. /*
  3. Plugin Name: WP Math Publisher
  4. Plugin URI: http://www.embeddedcomponents.com/blogs/wordpress/wpmathpub/
  5. Description: Display mathematical equations within your posts. Put your plain text <a href="http://www.xm1math.net/phpmathpublisher/doc/help.html">mathmatical expressions</a> 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.
  6. Version: 1.0.4
  7. Author: Ron Fredericks, Embedded Components
  8. Author URI: http://www.embeddedcomponents.com/blogs/ 
  10. Easy install notes:
  11.         Just copy the wpmathpub directory and all its contents into your WordPress plugins directory. 
  13. Platforms tested:
  14.         1) Linux Apache web server, php 4.4.4, WordPress 2.0.4 installed in subdirectory,
  15.         2) Linux Apache web server, php 4.4.4, WordPress 2.3.3 installed in root directory.   
  17. References:
  18.         Pascal Brachet’s phpmathpublisher
  19.                 Home: http://www.xm1math.net/phpmathpublisher/
  20.                 Usage: http://www.xm1math.net/phpmathpublisher/doc/help.html
  21.         Matteo Bertini’s WordPress plugin called PHP Math Publisher
  22.                 http://www.slug.it/naufraghi/programmazione-web/wpmathpublisher
  23.         Randy Morrow’s WordPress plugin called Axiom
  24.                 http://wordpress.org/extend/plugins/axiom/#post-2794 
  26. */ 
  28. /*************************************************************************************** 
  30.     Copyright 2008  Ron Fredericks, Embedded Components, Inc.  (email : ronf@EmbeddedComponents.com) 
  32.         GNU General Public License
  33.     This program is free software; you can redistribute it and/or modify
  34.     it under the terms of the GNU General Public License as published by
  35.     the Free Software Foundation; either version 2 of the License, or
  36.     (at your option) any later version. 
  38.     This program is distributed in the hope that it will be useful,
  39.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  41.     GNU General Public License for more details. 
  43.     You should have received a copy of the GNU General Public License
  44.     along with this program; if not, write to the Free Software
  45.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  46. ***************************************************************************************/ 
  48. // Include Pascal’s php math publisher library.
  49. define("PHPMATHLIB", ‘phpmathpublisher’, true);
  50. require_once(PHPMATHLIB.‘/mathpublisher.php’)
  52. // Overwrite mathpublisher.php’s default pointers to /img and /fonts subdirectories with a flexible relative addressing scheme.
  53. $basedir = ‘/wp-content/plugins/’.basename(dirname(__FILE__), ".php").‘/’.PHPMATHLIB;
  54. $dirfonts=‘.’.$basedir.‘/fonts’;
  55. $dirimg=‘.’.$basedir.‘/img’
  57. // 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.
  58. $abs_dirimg = get_bloginfo(‘url’).$basedir.‘/img/’
  60. // Returns with <img src="http://www.yoursite.com/yourblog/wp-content/pluglins/wpmathpub/phpmathpublisher/img/some_unique_image.png" /> HTML tag.
  61. // Requires mathfilter function from PHPMATHLIB/mathpublisher.php code.
  62. function wpmathfilter($ascii_math, $size_math)
  63. {
  64.     global $abs_dirimg
  66.         // Define the default font size.
  67.         if (empty($size_math)) $size_math = ‘12′
  69.         $phpmath = mathfilter("<m></m>".$ascii_math."", $size_math, $abs_dirimg);
  70.         return $phpmath;
  71. } 
  73. // WordPress content filter
  74. function to_phpmath($content)
  75. {
  76.         // Add an new optional font size attribute size=xx to Matteo’s original preg_replace.
  77.         $content = preg_replace(‘#\[pmath(\s+size=|\s?)(\d*)(\])(.*?)\[/pmath\]#sie’, ‘wpmathfilter(\’\\4\’, \’\\2\’);’, $content);
  78.         return $content;
  79. } 
  81. // Register our filter, to_phpmath, into the hook routine, the_content, before any priority 6 content processing filters.
  82. add_filter(‘the_content’, ‘to_phpmath’, 5)
  84. ?>

Code Changes

Code (text)
  1. —— Change Log ——
  3. On March 17, 2008 create wpmathpub version 1.0.4 plugin for WordPress
  4. Start with Matteo Bertini’s sample code base:
  5.         Plugin Name: PHP Math Publisher
  6.         Plugin URI: http://www.slug.it/naufraghi/programmazione-web/wpmathpublisher
  7.         Version: 1.0.3
  8.         Author: Matteo Bertini
  9.         Author URI: http://www.slug.it/naufraghi/
  10. Changes made to Matteo Bertini’s Version: 1.0.3:
  11.         a) Automate the original site specific configuration
  12.         b) Add optional font size attribute to the [pmath] tag. New tag format: [pmath size=xx][/pmath], where xx represents a one or two digit font size.
  13.         c) Maintain backward compatiblility with Matteo’s original tag scheme, [pmath][/pmath], define default value for size attribute of 12.
  14.         d) Shorten plugin name and edit code comments
  15.         e) Pull in complete code tree from Pascal Brachet’s current phpmathpublisher offering: http://www.xm1math.net/phpmathpublisher/
  17. —- End Change Log —-

Download Plugin

WordPress Math Publisher Plugin is now available directly from WordPress.org’s plugin site: Download it now>

Support: 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.

5 Responses to “WordPress Math Publisher Plugin Home Page”

  1. Jennell Bertelle Says:

    Very interesting subject, thanks for posting.

  2. Felix Says:

    Well I definitely liked studying it. This article procured by you is very
    helpful for proper planning.

  3. Expert Referencement Says:

    Thanks Jamie ??, looking forward to increases performance from SEM too.Which do you prefer, SEO or SEM???

  4. Seckidsandteens.win Says:

    What i don’t understood is in fact how you are now not actually a lot more neatly-appreciated than you might be now.
    You are very intelligent. You recognize thus considerably with regards
    to this subject, produced me in my opinion imagine it from
    a lot of varied angles. Its like men and women aren’t interested except it is something to
    accomplish with Woman gaga! Your personal stuffs excellent.
    All the time take care of it up!

  5. naveen Says:

    Hi, absolutely got tons of value from your post. Please i have 2 quick questions.
    1. What is the number of plugins every blogger shouldn’t exceed? I currently have about 18 installed, would you consider that number outrageous. Please could you also check out my site and offer me a
    2. Your font is really beautiful. would you suggest plugins that would give me beautiful fonts just like yours?
    Finally, would you spare a few seconds to check this site and offer me your candid advice http://www.samozoani.com

Leave a Reply