# Getting math into the blog

## MultiMarkdown

Since I am using ikiwiki for my blog I got happy to read about Math Syntax when reading the MultiMarkdown Syntax Guide. This would let me write

```
<< e=mc^2 >>
```

when I wanted to render

$e=m{c}^{2}$The implementation of MultiMarkdown in ikiwiki did not support this syntax and could have been the end of the happiness.

## mathml directive for ikiwiki

Since
Text::ASCIIMathML
have been used for the
Math Syntax
and ikiwiki supports writing
your own plugins I got the idea to
write my own `mathml`

directive.

This directive renders a
ASCIIMathML formula into
MathML. There is just one
argument `code`

and it is passed to
Text::ASCIIMathML to get the MathML output.

### Examples

Input

```
[[!mathml code="x^2"]]
```

Output

```
<math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle><msup><mi>x</mi><mn>2</mn></msup></mstyle></math>
```

Rendered result

${x}^{2}$```
[[!mathml code="a^2+b^2=c^2"]]
```

${a}^{2}+{b}^{2}={c}^{2}$
```
[[!mathml code="
sigma(A) =
[(sigma(a_(11)),...,sigma(a_(1n))),
(,...,),
(sigma(a_(m1)),...,sigma(a_(mn)))]
"]]
```

$\sigma \left(A\right)=\left[\begin{array}{ccc}\sigma \left({a}_{11}\right)& ...& \sigma \left({a}_{1n}\right)\\ ...\\ \sigma \left({a}_{m1}\right)& ...& \sigma \left({a}_{mn}\right)\end{array}\right]$
## Get the source

If you want the source as of today it is available in mathml.pm. I
also have a Git
repository at `http://gustaf.thorslund.org/src/ikiwiki.git`

with a
branch named `mathml`

. If you are into using Git you might as well
check out the ikiwiki source and after
running the `gitremotes`

script checkout the branch
`GustafThorslund/mathml`

.

## Known issues

I am currently running Ubuntu Karmic Koala (9.10) with ikiwiki rebuilt from the Lucid Lynx (10.04) source for my blog. With this setup I have to disable scrubbing of the generated html. On my laptop running Lucid Lynx it works fine without disabling scrubbing. Since this is just a blog and directives are not allowed in comments anyway I can live with scrubbing being turned off.

Of the browsers I have triend the output looks good in:

- Firefox

While it looks bad in:

- Konqueror
- Chrome

Some answer to getting better support might be in Supporting MathML. Since Math Syntax did not look any good in Konqueror or Chrome the hope on getting it any better might be limited.

## Update 1

- I had to turn off scrubbing on my Lucid Lynx laptop too. I just had confused myself enough to not realize it.
- I have patched htmlscrubber.pm to not scrub away my MathML output and enabled scrubbing again.

If HTML is allowed, then I don't think you want to do that. Turn off scrubbing for individual pages that are locked (i.e. admin-edit-only), while leaving it on for pages like comments that can be created/edited by possibly-evil users like me.

Thanks for your comment smcv!

Just turning of scrubbing on some pages is kind of hard on a blog where same post is inlined on a number of pages and also have comments inlined on one page. I have turned on scrubbing again now after patching htmlscrubber.pm.

/Gustaf

Besides the stylesheet trick on the w3 page, you might also consider playing with the served mime type. See Calvin Smith's simple notes and Jacques Distler's more detailed approach (some JavaScript). IE users have to install MathPlayer or another MathML plugin, but that's what they deserve ;).

I don't have comments on my ikiwiki blog, so I have also disabled scrubbing, but other than that it works for me (although I use mdwn_itex to generate the MathML).