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:

  1. Download and install wordpress
  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π=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 .
<reload homepage>
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";
}

add_filter('pre_option_html_type', 'reset_html_type');

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:

    How about comments?

    dα= α
  2. Eric says:

    Awesomeness. You rock! :)

  3. Eric says:
    F(x) F(f) F(y) α x α y G(x) G(f) G(y)
  4. eggel boggeldonk says:

    breaking away:

    Itex2MML::Error

    x+yxy [0 1 2 3] Eyjafjallajökull from the most popular and trashiest newspaper in Germany. Itex2MML::Error x 1,2=b±b 24ac2a
  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

  8. admin says:

    @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:

    L =lim xcos1x1x 21x 2 by me =lim xcos1x1x 2x 21 by him =cos1=cos0=1 Axiom 3
  9. Eric says:

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

  10. admin says:

    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…

  12. admin says:

    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 :-)

    admin says

    Is there a “preview comment” plugin for wordpress?

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

  14. admin says:

    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! :)

  17. admin says:

    Right, found a preview plugin. Let’s try it out with some maths as well: x 2=π. 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= +xxdx

    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

  21. admin says:

    Eric asked about wikilinks. They ought to already be here. Let’s try with a link to the nlab itself: HomePage.

  22. Eric Forgy says:
    x= +xxdx
  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:

    +e x 2/2dx=2π so with a change of variables, +e x 2dx=π.

    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

    +e x 2/2dx=2π 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.

  25. admin says:

    Firebug is fantastic. Using it, I was able to track down exactly why that’s in bold. It’s CSS, John, but not as we know it. I’ll fix it by-and-by.

  26. Ian Durham says:

    Will this work if we use Wordpress.com as host? I’d really like it for my blog since I’ve received a few complaints about the way LaTeX is implemented on WP at the moment (makes it hard to real, I guess). If so, how do I get a copy of it? Thanks!

  27. Florent says:

    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=b±b 24.a.c2.a Is there a way to fix this or overcome it? Is it due to a wrong LaTex syntax ?