/MathML HOWTO - step by step instructions for adding MathML support to MoinMoin (one of several possible ways, other ways are discussed below)

If you use MathML in your wiki, you may use "MathMlSupport/HelpOnMathematicalFormulas" as help page in your wiki.

A problem of the method described in the above howto: when trying to write a help page for this syntax, constructs enclosed in { { { } } } still get rendered as math. This is because the math delimiter as used in the wiki syntax and delimiter defined in the java script are the same. Maybe we should change the delimiter in the script to something long and improbable like $ASCIIMathML$ and make the wiki parser transform $$ to $ASCIIMathML$. But this will worsen the readability for people whose browser doesn't render MathML. Another option is to write the two $ signs in help pages with a space betweed them, just the way it's done on all the moin help pages for other constructs like { { { } } }

Supporting MathML will allow MoinMoin to compete with other wikis that have texvc (a Latex-lexer that allows safe Latex execution for math-related symbols) or allow native MathML input.

I suggest to bundle ASCIImath and change its default-pattern of `markup` to something that does not trigger our parser and is shorter than four characters.

UPDATE: The latest version of ASCIIMathML doesn't need the modification in <html> tag. Adding the following to wikiconfig.py seems to be enough, no need to modify wikiutil.py.

    html_head='''
<script type="text/javascript" src="wiki/ASCIIMathML.js"></script>
'''

Older version of ASCIIMathML works by including this in the header:

<html xmlns:mml="http://www.w3.org/1998/Math/MathML">
<head>
<object id="mathplayer" classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">
</object><?import namespace="mml" implementation="#mathplayer"?>
<script type="text/javascript" src="ASCIIMathML.js"></script>
<title>your title...</title>
</head>
<body onload="translate()">

In order to install it, you can add the following line to you wikiconfig.py:

    html_head='''
<object id="mathplayer" classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">
</object><?import namespace="mml" implementation="#mathplayer"?>
<script type="text/javascript" src="ASCIIMathML.js"></script>
'''

Download ASCIIMathML.js: download ASCIIMathML.js and put it somewhere readable. For example

cp ASCIIMathML.js yourhtdocs/

and don't forget to specify the location of the javascript as well.
In this case, it should be

src="/ASCIIMathML.js".

Edit wikiutil.py:

Line ~ 1078:
output.append("""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
+<html xmlns:mml="http://www.w3.org/1998/Math/MathML">

Line ~ 1165:
- output.append('\n<body%s>\n' % ''.join(bodyattr))
+ output.append('\n<body%s onLoad="translate()">\n' % ''.join(bodyattr))

Usage

{{{`a+b`}}}

Patch for shorter markup

Note: it's a rather not elegant patch

With it the usage will be

$$a+b$$

Normal words description: It makes the wiki parser recognise  $$anything$$  in the wiki markup and replace it with  `anything`  in the HTML output.

After doing the previous edit parser.py

Line ~ 83:
before the line
(?P<ent>[<>&]) """ % {
add the line:
(?P<asciimath>\$\$.*?\$\$)


Line ~ 887:
before the     def scan(self, scan_re, line):
add:
    def _asciimath_repl(self, word):
        """Handle math in $$ $$ for AsciiMathML."""
        return self.formatter.text('`'+ word[2:-2] +'`')


var AMdelimiter1 = "$$", AMescape1 = "\\\\\\$$"; // can use other characters
var AMdelimiter2 = "$$", AMescape2 = "\\\\\\$$", AMdelimiter2regexp = "\\$$";

ToDo

There was a question on the mailing list what will happen with this. I personally don't use any math markup, so just some random thoughts that can be improved by someone really using this stuff:

Questions

Type this

See that

Comment

$$f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n$$

$$ f(x)=sum_(n=0)oo(f((n))(a))/(n!)(x-a)n $$ || `f((n))(a) must be bracketed, else the numerator is only a`

  html_head='''
<script type="text/javascript" src="wiki/ASCIIMathML.js"></script>
''' '/moin_static184'

Am I doing something wrong ? -- [[]] 2009-06-17 17:31:15

{{{ html_head= <script type="text/javascript" src="/moin_static184/ASCIIMathML.js"></script> }}} -- zelhar 2009-06-17 20:53:20

Checkout this javascript support for MathML!

I too am on a mission to accomplish this! The javascript engine below is very strong -- but I'm just starting with Moin and I don't know how to plugin javascript parsers/processors. Maybe we can help each other?

jsMath

2009-10-31 15:05:06

wiki.py missing

mathtrans parser

You could also use the mathtrans parser. This uses the action cache for already converted formulars. The devolping process isn't finished yet but it can be used already.

gives mathtran_example.png

moin2 inline mathml/svg patch

moin2-mathml.diff

Maybe someone with a clue about mathml, its entities, xml, etc. could have a look at this patch.

Also general feedback wanted. Is "inlining" mathml into html5 the way to go? Browser support aside from FF4?

Known issues

How to use

MoinMoin: MathMlSupport (last edited 2010-08-14 18:38:35 by ThomasWaldmann)