/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.
- Note: this wiki instance (the one you are reading right now) doesn't have any MathML patches installed therefore the examples on the above pages will not show up as MathML. But they will if copied to an instance with the patch.
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 (2006-09-05): Integration of asciimatml into moinmoin has been done by sciki (scientfic wiki) project. The actual code is available in their subversion repository which is web browseable here: http://project.knowledgeforge.net/sciki/svn/ and here are installation instructions.
Have you thought about porting it to 1.5 and registering on the particular CategoryMarket pages?
There is nothing to do for 1.5. I tried with moin-1.5.4 and it just works
- Nice to know, that should be mentioned in the README - and it could be listed on the market pages.
(RufusPollock: author of the sciki code) Thanks for that information about compatibility with 1.5 which I've added to the README.txt. What Category do you think this should go in (ParserMarket perhaps?)
- Nice to know, that should be mentioned in the README - and it could be listed on the market pages.
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] +'`')
- Why don't we just change two lines in ASCIIMathML.js? Change the 17 and 18th lines to this and you'd get the functionality of the patch above without changing the parser:
var AMdelimiter1 = "$$", AMescape1 = "\\\\\\$$"; // can use other characters var AMdelimiter2 = "$$", AMescape2 = "\\\\\\$$", AMdelimiter2regexp = "\\$$";
Oops, I was wrong. You did have to include the patch and the lines above. My mistake. Now I have to do WikiPenance. --AnonymousCoward
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:
we shouldn't change the <html> tag and head contents of ANY page, so there needs to be some mechanism to do this only for pages using asciimath
is it not possible to use a #pragma for this?
- the $$ method doesn't look that bad, so if nobody has a better idea, we could go that way
- we can't use a moin parser plugin because this is also used inline, right?
- We have macros for that
I think both (inline and block) should be supported. Maybe the $$ solution and the parser?
- we can't just define the body onload js function as this might be used by other stuff
But the JS can be loaded later. So macro/parser could just output a <script> tag on first use.
- we need someone testing this stuff and closely working together with moin development
- a good patch implementing this for a current moin version would help to speed this up
Questions
- As pointed out up there, we are actually changing the html header of áll'pages. This result in AsciiMathML syntax to be active on every page, even if the parser is not set to wiki_with_math. Is there a way to change that? To enable ASCCIIMathML only for pages with wiki_withmath parser? -Jyt-
I tried to make a help page for ASCIImathML in a local wiki and converted the examples from the ASCIImathML Homepage. The following does not work (third column of table is not recognized). Does anyone see the same / know a work-around? If you remove ^n it is OK. -- DavidLinke 2006-09-11 10:59:43
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` |
Maybe related to the problem above: Superscript does no longer work if the sciki stuff is installed except for underlay pages (i.e. SyntaxReference is Ok but if you use superscript elsewhere it is ignored. (this is on moin-1.5.4) [solved by code below!]
The superscript should not work with sciki since sciki specifically disables it in wiki_with_math.py. Basically, in this file there is a Parser class that inherits from the main wiki parser and replaces the function that handles superscripts with an identity function (there is nothing else in this file).
In my opinion, there must be a separate formatting rule for math in the parser. Math syntax can have all sorts of weird combinations of character which could lead to an equivalent assortment of weird effects if the wiki parser tries to interpret math as if it is normal text.
Agreed. With a minor fix in your code below I got it working. The table problem from above is solved and SyntaxReference is not negatively affected -- DavidLinke
The sciki's wiki_with_math.py can be replaced with something like the following in order to add the formatting rule. Code tested with moin-1.5.4.
1 import MoinMoin.parser.wiki 2 3 class Parser(MoinMoin.parser.wiki.Parser): 4 """ 5 Subclass default parser as long as ASCIIMathML is not directly supported 6 in MoinMoin. 7 """ 8 9 formatting_rules = (MoinMoin.parser.wiki.Parser.formatting_rules 10 + u'\n' + ur'(?P<asciimath>(\$\$.*?\$\$))') 11 12 def _asciimath_repl(self, word): 13 """Just leave the math as it is and prevent the parser 14 from messing with it.""" 15 return word
- Can someone explain how to make mathml work in moin-1.6.0? -
I've updated the instructions at /MathML HOWTO for MoinMoin 1.6.0. Hopefully I have not left out any details. Please advise if you encounter any problems. --JohnCarlson 2008-01-18 01:09:38
- I've the instructions but still it doesn't work. I believe the ASCIIMathML.js file is not recognized, because in the dos window I notice the following line: "GET wiki/ASCIIMathML.js HTTP/1.1" 404 -
whereas in the old desktop moin the number to the right in 200 rather than 404. ---~~
- Not sure, but have you checked the webserver's rights to access this file? --bace
Please make sure that the ASCIIMathML.js file is in MoinMoin's htdocs (not your webserver's http docs directory). Also, the (_static?) needs to have an alias in your httpd configuration. In my setup I have = \'\' in my wikiconfig.py and in my Apache httpd.conf I have Alias / "c:/Python25/share/moin/htdocs", but your path may be different depending where MoinMoin was installed. (Please reference HelpOnInstalling/ApacheOnWin32 if you are running Apache and Windows). --JohnCarlson 2008-01-19 01:09:00
- I've the instructions but still it doesn't work. I believe the ASCIIMathML.js file is not recognized, because in the dos window I notice the following line: "GET wiki/ASCIIMathML.js HTTP/1.1" 404 -
I your instructions from /MathML HOWTO for MoinMoin 1.6.0. Two times I faced the problem that if I want to edit a page again (after embedding some math), the editor screwed up with the $$...$$ because it also replaces those tags _inside_ the editor. --bace
Can you supply more details? As far as I know, the changes on the /MathML HOWTO do not affect the editor. I've tested with both the GUI and text editors. --JohnCarlson 2008-01-19 01:09:00
E.g. I type "$$ 1+1 $$" in the editor, press save, then it's displayed properly. But if I edit again (or pressed preview instead of save), the former statement is replaced by "<p align="center">$\displaystyle{ 1+1 }$</p> in the editor. I tried two times (fresh MoinMoin installations), and hope that this was not a typo. Regards --bace
This problem is an issue with ASCIIMathML.js version 2.0.1 which is relatively new. Please use ASCIIMathML.js version 1.4.7 available on Sourceforge and make the changes shown on the /MathML HOWTO. Be careful of old copies of the ASCIIMathML.js sitting in your browser's cache. If I can figure out the issue with 2.0.1, I will update the /MathML HOWTO. --JohnCarlson 2008-01-19 03:17:30
- Thanks John! This finally works. --bace
I have updated /MathML HOWTO with instructions for using ASCIIMathML.js version 2.0.1. --JohnCarlson 2008-01-20 03:07:19
- I tried again with versions: 1.47, 2.09, 2.02 to no avail. My python is v2.51 (the latest I belueve). would it be possible for you to attach the modified files? Have you tried to the mathml in the alone mode? --
MathML does work in alone mode, but for MoinMoin 1.6.0, in the wikiconfig.py must be defined as /moin_static160, not as stated in the /MathML HOWTO. --JohnCarlson 2008-01-20 03:07:19
Great, now it works. Thanks allot JohnCarlson. -.
Now I've discovered a weird problem: when I type $$i<j$$ then after the "i" the <j disappears. If AMdelimiter1 = "`" Then Mathml seems to work fine. I've experienced this problem with MAthml v2.09, v2.02 which are the only version I've tried so far. -
I think this can be fixed by replacing the line referenced in the /MathML HOWTO, return ("$$" + word + "$$"), with return ("$$" + wikiutil.escape(word) + "$$"). After I gain some confidence in this solution I will update /MathML HOWTO. --JohnCarlson 2008-01-20 20:42:02
Indeed it appears to function flawlessly now, thanks allot. -- Josef 2008-03-16 15:10:10
The MathML equations print correctly in Firefox, but Internet Explorer 7 (at least) with MathPlayer prints the wiki markup instead of the MathML. Does anyone have a solution? -- JohnCarlson 2008-05-17 23:17:43
For unknown reasons, for printing to work with IE7/MathPlayer it is necessary to edit the theme/__init__.py file and comments out the following lines (as shown)
#output.append('<link rel="Alternate" media="print" title="%s" href="%s/%s?action=print">\n' % ( # _('Print View', formatted=False), scriptname, pagename_quoted,))
-- JohnCarlson 2008-05-18 20:27:02
Update for Moin184: I am trying to configure moin1.84 to work on alone mode with MAthML but I have some troubles. I the istructions regarding the 'parser/text_moin_wiki.py', the 'ASCIIMathML.js' and the 'wikiconfig.py' where I think my problem lies. This is what I put in the wikiconfig.py:
html_head=''' <script type="text/javascript" src="wiki/ASCIIMathML.js"></script> ''' '/moin_static184'
Am I doing something wrong ? -- [[]] 2009-06-17 17:31:15
- Okay problem solved (thanks to moins chat support by 'thesheep':
{{{ html_head= <script type="text/javascript" src="/moin_static184/ASCIIMathML.js"></script> }}} -- zelhar 2009-06-17 20:53:20
Update for Moin192: I tried to apply the instructions on moinmo.in/MathMlSupport/MathML%20HOWTO but for the parser configurations it doesn't work and in fact I get an error and moin cannot run when I edit the parser according to the instructions. Any idea what can be done. Especially I think editing the parser file isn't very elegant a solution and it would be better to add a module instead... -- zelhar 2010-04-17 19:17:38 2010-04-17 19:17:38
Correction: I applied the parser changed as recommended on moinmo.in/MathMlSupport/MathML%20HOWTO and it works but with bugs. For example an expression of the type: $$kappa^[<kappa]$$ isn't rendered correctly.
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?
2009-10-31 15:05:06
wiki.py missing
I try to follow this guide to enable MathMLSupport (MoinMoin 1.8, DesktopEdition): http://moinmo.in/MathMlSupport/MathML%20HOWTO.
I'm told to "edit the file parser.py under MoinMoin directory"
- This file does not exist at all. What to do? -- Pida 2008-12-31
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.
- Thank you, but is there any information on the use of this parser? I tried (blanks inserted to prevent this page from being formatted)
# f o r m a t text_x_mathtran at the beginning of the page => The whole page is a code block
{ { { # ! text_x_mathtran at the beginning of a code block => The formula is not being formatted
This style: t e x : \sum_0n 2{-n}
e.g.
{{{#!mathtran \sum_0^n 2^{-n} }}}
gives
moin2 inline mathml/svg patch
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
- "inline" mathml support requires Firefox 4.0 (use e.g. beta3 or a current nightly build) or another browser with similar capabilities
- mathml entities don't work, don't know why
- the mathmlentities.py is maybe incomplete, need a better one (but first make it work)
How to use
- create a plain text item
- edit mimetype metadata so it is "text/mathml"
- paste some mathml into the editor textarea
- save
- if you have some appropriate browser, you should see it rendered now