Table of Contents
- Introduction
- What’s New In WordPress Math Publisher
- WordPress Math Publisher Plugin Download and Installation
- How To Create Math Equations
- Code Overview
- Credits
Introduction
WpMathPub is designed for anyone who would like to easily include math equations within their WordPress.org blog, pages, or even comments. It is a simple alternative to MathML or LaTex.
Mathematics is often promoted as endowing those who study it with a number of broad thinking skills … providing transferable skills which can be found across educational institutions, governments and corporations worldwide.
Cresswell C, Speelman CP (2020) https://doi.org/10.1371/journal.pone.0236153
WpMathPub equations are based on LaTeX fonts but instantiated using simple text. No LaTeX programs are needed on the web server and no MathML.
Once the plugin is installed, use the block editor’s shortcode block to enter an equation and supporting text.
Enter a shortcode block like this…
[pmath size=16](alpha+beta)^2=alpha^2+2{alpha}{beta}+beta^2[/pmath]
Where:
[pmath size=12]~alpha[/pmath] is defined as a
[pmath size=12]~beta[/pmath] is defined as b
The result looks like this …
Result
Where:
is defined as a
is defined as b
What’s New In WordPress Math Publisher
Support for gradient field operators (div, grad, curl vector math)
Several physics professors have asked for the gradient feature. Now it is available – yea.
Enter a shortcode block like this…
[pmath size=16]vec{del}f(x, ~y) ~ = ~ {partial{f}}/{partial{x}}hat{i} ~ + ~ {partial{f}}/{partial{y}} hat{j}[/pmath]
[pmath size=16]{del}f(x, ~y) ~ = ~ {partial{f}}/{partial{x}}i ~ + ~ {partial{f}}/{partial{y}} j[/pmath]
The result looks like this …
Result
Fix bug using “Greater Than” Symbol (>) in Gutenberg block editor
I found many “less than” perfect solutions to using the “greater than” symbol in shortcode blocks within the WordPress Gutenberg editor. I have chosen to fix this issue by using a new set of commands to replace >, <, >=, <=, and <>. Now users can enter these symbols using gt, lt, ge, le, and ne without any HTML conflict or potential bug in the Gutenberg block editor.
New handling of logic test symbols
WordPress Math Publisher Plugin Download and Installation
To install the wpmathpub plugin use your WordPress dashboard command “Add New” plugin menu. Find/download/install the plugin. Activate the plugin. Check the status of the plugin to ensure that your hosting environment will support wpmathpub using your dashboard command Tools > wpmathpub entry. You should see something like this:
How To Create Math Equations
To toggle to the math mode, you must use the shortcode tag. Apart from this tag, any HTML code can be used. The blocks editor has a “shortcode [/]” block that can be used to enter shortcode entries into a post.
The math commands must be separated by a space character or surrounded by {}. A size option controls the size of displayed equations ranging from 8 to 24. The math commands are translated into png graphic images using LaTeX fonts included with this plugin.
View the full list of math commands
Examples
Each of the examples below includes
- An overview of the shortcode,
- The final LaTeX-styled output,
- A link to the raw shortcode text. You can use the shortcode text as a stater-template for your own blog posts.
Example 1
Enter a shortcode block like this…
[pmath size=24/]delim{lbrace}{matrix{3}{1}{{3x-5y+z=0} {sqrt{2}x-7y+8z=0} {x-8y+9z=0}}}{ }[/pmath]
The result looks like this …
Result:
Example 2
Enter a shortcode block like this…
[pmath]delim{|}{{1/N} sum{n=1}{N}{gamma(u_n)} – 1/{2 pi} int{0}{2 pi}{gamma(t) dt}}{|} <= epsilon/3[/pmath]
The result looks like this …
Result
Example 3
Enter a shortcode block like this…
[pmath size=8]S(f)(t)=a_{0}+sum{n=1}{+infty}{a_{n} cos(n omega t)+b_{n} sin(n omega t)} [/pmath]
The result looks like this …
Result:
Example 4
Enter a shortcode block like this…
A formula : [pmath]delim{|}{{1/N} sum{n=1}{N}{gamma(u_n)} – 1/{2 pi} int{0}{2 pi}{gamma(t) dt}}{|} <= varepsilon/3[/pmath]
About pi :
- [pmath]pi=sum{n=0}{+infty}{{(n!)^2 2^{n+1}}/{(2n+1)!}}[/pmath]
- [pmath]pi=22/7-int{0}{1}{{x^4 (1-x)^4}/{1+x^2}dx}[/pmath]
- [pmath]pi=3/4 sqrt{3}+24 int{0}{1/4}{sqrt{x-x^2}dx}[/pmath]
[pmath]delim{lbrace}{matrix{3}{1}{{3x-5y+z=0} {sqrt{2}x-7y+8z=0} {x-8y+9z=0}}}{~}[/pmath] [pmath]delim{|}{matrix{3}{3}{a_{1 1} cdots a_{1 n} vdots ddots vdots a_{n 1} cdots a_{n n}}}{|}[/pmath]
The result looks like this …
Result:
A formula :
About pi :
Example 5
Suppose we wish to create a precise definition for a series that reads something like this:
The terms of U get arbitrarily close and stay arbitrarily close to l, there exists a natural number p such that if n >= p then |U(n) - l| <= epsilon.
Enter a shortcode block like this…
From now on :
Definition : [pmath size=18](u_{n})_{n in bbN}[/pmath] converges to [pmath size=18]l ~ doubleleftright ~ forall epsilon{gt}0, ~ exists p in bbN [/pmath] such that [pmath size=18] forall n{ge}p delim{|}{u_{n}-l}{|}{le}epsilon[/pmath]
Remark : in the case of a vector sequence, just replace [pmath size=18]delim{|}{u_{n}-l}{|}[/pmath] by [pmath size=18]delim{vert}{u_{n}-l}{vert}[/pmath]
Taylor series with integral remainder :
If [pmath size=18]f[/pmath] is a class, [pmath size=18]~ C^{n+1}[/pmath] is a class over the interval : [pmath size=18] f(x)=f(0)+xf{prime}(0)+{x^{2}}/{2!}f{prime prime}(0)+…+{x^{n}}/{n!}f^{n}(0)+int{0}{x}{{(x-t)^{n}}/{n!}f^{(n+1)}(t)dt}[/pmath]
Fourier series :
Definition : Then we call the Fourier series of [pmath size=18]f[/pmath] : [pmath size=18]S(f)(t)=a_{0}+sum{n=1}{+infty}{a_{n} cos(n omega t)+b_{n} sin(n omega t)}[/pmath] with [pmath size=18]omega={2pi}/{T}[/pmath]
The result looks like this …
Result
From now on :
Definition : converges to such that
Remark : in the case of a vector sequence, just replace by
Taylor series with integral remainder :
If is a class, is a class over the interval :
Fourier series :
Definition : Then we call the Fourier series of : with
Code Overview
Consists of a “wild” and Krellian IQ enhancing regex that converts LaTeX-styled text between the shortcode tags pmath…/pmath (shown without braces to avoid activating the shortcode) into a function call for use with the included PhpMathPublisher.php code base.
A short segment from wpmathpub.php showing how the math text between shortcode tags is filtered for use by PhpMathPublisher library…
// Create a WordPress math text filter suitable for PhpMathPublisher.php function to_phpmath($content) { // Add an optional font size attribute size=xx // Use preg_replace_callback instead of preg_replace /e in support of php 7 $content = preg_replace_callback('#\[pmath(\s+size=|\s?)(\d*)(\])(.*?)\[/pmath\]#si', 'wpmathfilter', $content); return $content; }
A PNG image is returned that replaces the original math-styled text during display. Because of the regex and the use of an image storage gallery for previously generated PNGs, the display of math equations is very fast.
A short segment from PhpMathPublisher.php library code base showing how PNG images are inserted into WordPress…
function mathimage($text,$size,$pathtoimg) { /* Creates the formula image (if the image is not in the cache) and returns the <img src=...></img> html code. */ global $dirimg; $nameimg = md5(trim($text).$size).'.png'; $v=detectimg($nameimg); if ($v==0) { //the image doesn't exist in the cache directory. we create it. $formula=new expression_math(tableau_expression(trim($text))); $formula->dessine($size); $v=1000-imagesy($formula->image)+$formula->base_verticale+3; //1000+baseline ($v) is recorded in the name of the image ImagePNG($formula->image,$dirimg."/math_".$v."_".$nameimg); } $valign=$v-1000; return '<img src="'.$pathtoimg."math_".$v."_".$nameimg.'" style="vertical-align:'.$valign.'px;'.' display: inline-block ;" alt="'.$text.'" title="'.$text.'"/>'; }
Credits
WordPress Math Publisher plugin – BiophysicsLab.com – Los Gatos – Copyright 2008-22
The original creator of PhpMathPublisher – Pascal Brachet – France – Copyright 2005
An Updated PhpMathPublisher php library is included in this WordPress plugin by BiophysicsLab.com
Latex fonts – Copyright (C) 1997 American Mathematical Society
FreeSerif.ttf font – Copyleft 2002-10 Free Software Foundation
This is a math equation in a comment
Here is the shortcode that created this equation (with spaces added to the pmath shortcode so the code will not be interpreted as math:
[ pmath size=24 ]delim{lbrace}{matrix{3}{1}{{3x-5y+z=0} {sqrt{2}x-7y+8z=0} {x-8y+9z=0}}}{ }[ /pmath ]