Wordpress and MathML

This is a “showcase blog” demonstrating that Wordpress and MathML can exist in harmony together. So far, all I’ve done is:

2. Install the wordpress plugins ‘MarkdownItex’ and ‘XHTMLValidator’
3. Activate these two plugins (taking care to not activate ‘Markdown Extra’ itself)
4. Written this post.

And now, I can write mathematics! So let’s start with what is officially the most beautiful formula.

$-{e}^{-i\pi }=1$

Of course, as expected, nothing works quite so simply. The first time that itex runs, assuming that it is not running locally, it needs to create a cache in which it can store all the mathml excerpts. So having written our post, we navigate to the correct directory, allow itex to create it’s cache, and then all is well:

``````cd wp-content/plugins/MarkdownItex
chmod 777 .
chmod 755 .
``````

What we should have done at first was also modify our “theme” to display the correct “document type”. At the moment, we think that we’re just serving XHTML whereas we actually want to serve XHTML+MathML. So we need to install a “MathMLised theme”, or adapt a favourite one to MathML. This isn’t difficult, we just need to do two things: modify the DOCTYPE and serve the document as “application/xhtml+xml”. In `mytheme/header.php`, we change the DOCTYPE line to:

``````<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd" >
``````

whilst in `mytheme/functions.php` we add the lines:

``````function reset_html_type(\$tf) {
return "application/xhtml+xml";
}

``````

somewhere not in the middle of another function (there are other ways to achieve the same end as this).

Note: As we’re now serving proper XHTML, any little errors which previously were overlooked by forgiving browers will now be dealt with very strictly. So there may be other errors in the theme which only come to light upon further testing.

Further Note: As this is the first live test of the various themes and plugins, they aren’t publicly available yet. Anyone who wishes to test them is welcome to do so, just contact me for how to get hold of them.

27 Responses to “Wordpress and MathML”

1. Eric says:

${\int }_{ℳ}d\alpha ={\int }_{\partial ℳ}\alpha$
2. Eric says:

Awesomeness. You rock!

3. Eric says:
$\begin{array}{ccc}F\left(x\right)& \stackrel{F\left(f\right)}{\to }& F\left(y\right)\\ {\alpha }_{x}↓& & ↓{\alpha }_{y}\\ G\left(x\right)& \stackrel{G\left(f\right)}{\to }& G\left(y\right)\end{array}$
4. eggel boggeldonk says:

breaking away:

$\text{Itex2MML::Error}$

$\perp \top \square \blacksquare \diamond ◊⧫▵▴▾★$ $\frac{x+y}{\mathrm{xy}}$ $\left[\begin{array}{ccc}0& \cdots & 1\\ ⋮& \ddots & ⋮\\ 2& \cdots & 3\end{array}\right]$ Eyjafjallajökull from the most popular and trashiest newspaper in Germany. $\text{Itex2MML::Error}$ ${x}_{1,2}=\frac{-b±\sqrt{{b}^{2}-4\mathrm{ac}}}{2a}$
5. Tim van beek says:

Hm, I posted the last comment and created the tex stuff by copy&paste from the Tex Wikipedia article, I mean it should have worked unless I pasted it wrong

6. Eric says:

Does the “Journal” theme work? That is my favorite.

7. Eric says:

Wikipedia does not use itex

@Tim: it’s itex, not tex. I guess I ought to add the “View Source” ability to the theme. I’m not sure what the error was in the first one, but the second should have used ‘aligned’ instead of ‘alignat’. Let me try:

$\begin{array}{rlrl}L& =\underset{\mid x\mid \to \infty }{\mathrm{lim}}\frac{\mathrm{cos}\frac{1}{x}\cdot \frac{-1}{{x}^{2}}}{}\frac{-1}{{x}^{2}}& \phantom{\rule{1em}{0ex}}& \text{by me}\\ & =\underset{\mid x\mid \to \infty }{\mathrm{lim}}\mathrm{cos}\frac{1}{x}\cdot \frac{-1}{{x}^{2}}\cdot \frac{{x}^{2}}{-1}& & \text{by him}\\ & =\mathrm{cos}\frac{1}{\infty }=\mathrm{cos}0=1& & \text{Axiom 3}\end{array}$
9. Eric says:

If you could add a “Source” feature to this, you would super rock

Stick it down as “feature request”! Is there a “preview comment” plugin for wordpress?

11. Eric says:

>Is there a “preview comment” plugin for wordpress?

Not as far as I know…

Hmm, now why didn’t your comment get properly parsed?

Not as far as I know…

should be a blockquote.

13. Tim van beek says:

Andrew said:

it’s itex, not tex.

uuhhh – that’s a difference I completly ignored to this point, without problems

Is there a “preview comment” plugin for wordpress?

I’d like to have that, too. Or an “edit after posting” one.

Is there a “preview comment” plugin for wordpress?

Not as far as I know…

15. Tim van Beek says:

And one that allows me to correct the typo in my own name.

16. Eric says:

>>Is there a “preview comment” plugin for wordpress?

>Not as far as I know…

That’s what I said! (Nested quotes? )

Oh oh! A preview button!

Right, found a preview plugin. Let’s try it out with some maths as well: ${x}^{2}=\pi$. Wow! It worked “out of the box” (well, with one modification but that was already in the readme and I don’t know that it wouldn’t have worked without that change).

18. Ian Durham says:

This is really great! Now I just have to figure out how it works. Let’s try something like

$⟨x⟩={\int }_{-\infty }^{+\infty }\mid x⟩⟨x\mid \mathrm{dx}$

Sweet!

19. Ian Durham says:

By the way, how did Eric get the nice, big integrals? Mine was puny.

20. Eric Forgy says:

@Ian: Use double dollar signs

22. Eric Forgy says:
$⟨x⟩={\int }_{-\infty }^{+\infty }\mid x⟩⟨x\mid dx$
23. Eric Forgy says:

Oh, by the way. I think non-ascii wikilinks do not work.

24. John Baez says:

Let me try it out:

${\int }_{-\infty }^{+\infty }{e}^{-{x}^{2}/2}\mathrm{dx}=\sqrt{2\pi }$ so with a change of variables, ${\int }_{-\infty }^{+\infty }{e}^{-{x}^{2}}\mathrm{dx}=\sqrt{\pi }$.

Hmm, some stuff came out in boldface… it’s because there was no space between the d and the x. If I put a space in, I get

${\int }_{-\infty }^{+\infty }{e}^{-{x}^{2}/2}dx=\sqrt{2\pi }$ and then the subsequent text is not boldface.

Wait, it is! The $dx$ looks fine but the following text is boldface. Huh.

I seem to have a knack for bumping into bugs! But anyway, this is great, Andrew. Congratulations! The world will thank you.

I have just installed another plug-in (wp-math-2) and it runs quite fine except for the same an issue already displayed above: the expression below a root is actually written below … well below as the root is written as a superscript before the expression, followed by a black rectangle and the expression below the rectangle. For example : $x=\frac{-b±\sqrt{{b}^{2}-4.a.c}}{2.a}$ Is there a way to fix this or overcome it? Is it due to a wrong LaTex syntax ?