Jun 242014
 

I’ve been work­ing at Design Sci­ence for a couple of months now, as Seni­or Product Man­ager con­cen­trat­ing on the Math­Flow products. So I figured I should enable Math­ML sup­port on my blog. It’s not hard, but like everything in tech there are a few nig­gly details. Many of those issues are caused by Word­Press’s over-eager help­ful­ness, which has to be reined in on a reg­u­lar basis if you’re doing any­thing at all out of the ordin­ary. Like edit­ing your posts dir­ectly in HTML rather than using some pseudo-WYSI­WYG editor.

The­or­et­ic­ally, show­ing Math­ML in a browser is easy, at least for the sort of equa­tions that most people put in blog posts, even though not all browsers sup­port Math­ML dir­ectly. You just use the Math­Jax JavaS­cript lib­rary. On Word­Press there is even a plu­gin that adds the right script ele­ment, the Math­Jax-Latex plu­gin. You can make every page load Math­Jax, or use the [math­jax] short­code to tell it when to load.

The wrinkle comes with Word­Press’ tend­ency to “cor­rect” the markup. When you add the Math­ML, Word­Press sprinkles it with <br/> tags. Math­Jax chokes on those and shows noth­ing. Since the tags don’t show up in the edit­or view, you need some way of stop­ping Word­Press from adding them. The best way I’ve found is with the Raw HTML plugin.

But there’s a wrinkle with that too. For some reas­on if you use the short­code ver­sion of the begin and end mark­ers ([raw]) the edit­or decides that the XML char­ac­ters between those mark­ers has to be turned into the char­ac­ter entit­ies, so for example the < char­ac­ters are turned into &lt;. To stop that, you need to a) check all the check­boxes in the Raw HTML set­tings on the post, and b) use the com­ment ver­sion (<– raw –> and <– /raw –>) to mark the begin­ning and end of the sec­tion instead of the short­code version.

Once it’s done it’s easy to add equa­tions to your pages, so it’s worth the extra few minutes to set it all up.

A couple of examples taken from the Math­Jax samples page

Curl of a Vec­tor Field
×F=(FzyFyz)i+(FxzFzx)j+(FyxFxy)k
Stand­ard Deviation
σ=1Ni=1N(xiμ)2

and one from my thes­is from way back when

fλ=n!i<k(li-lk)l1!l2!lr!

  9 Responses to “MathJax, MathML, and WordPress”

  1. My brain just imploded. This is ter­ribly cool… there is some­thing awe­some about look­ing at math equa­tions I can­’t understand.

  2. More dumb­ing down (and res­ult­ant pain?).
    Note yet one more vari­ant on SGML markup? How many does that make? [tag] ..[/tag] etc.

    Odd Lauren. Using feedly, the math­ml does­n’t show up. Link through to the blog (dir­ect browser
    access I guess) and it does. 

    Enjoy­ing the job?

    • You’re right about feedly. I guess they restrict the markup that they will allow? Many people don’t think about Math­ML when they fig­ure out which markup to allow, even though it’s part of HTML5

      I under­stand Word­Press try­ing to make gen­er­al HTML edit­ing easi­er for people. ‘Easy things easy and hard things pos­sible’ and all that; just a pity they tend to go rather more over­board than I like. But, enough people have the issue that these plu­gins exist, which makes it all a rel­at­ively minor annoyance.

    • And yes, I’m enjoy­ing the job.

  3. Con­grat­u­la­tions on the job.

    Of course, if you had enabled Math­ML in the com­ments field I’d have some­thing wise to say about your thes­is equa­tions. Of course … I would.

    (Ran into Deb Lapeyre look­ing at com­ic books in the Brit­ish Museum. Had a great chat. She sends her regards.) 

    jat

    • I guess I would need to write a plu­gin to allow Math­ML markup in the com­ments. I’ll add it to the long ‘maybe one day’ list 😉

  4. i need math­mled­it­or plu­gin for wordpress ?
    how can help me?
    sajjadh1373@outlook.com

  5. i need math­mled­it­or plu­gin for wordpress ?
    who can help me?
    sajjadh1373@outlook.com

Sorry, the comment form is closed at this time.

/* ]]> */