1 """
2 inline_latex is a parser that allows regular moin moin wiki syntax,
3 but also latex style inline formulas like $...$ and latex style
4 paragraph formulas like $$...$$. Note that in the latter case, you
5 are (unlike in latex) limited to a single line. If you absolutely
6 need multiple lines, use the parser directly.
7
8 Copyright 2005-2008 Johannes Berg <johannes@sipsolutions.net>
9
10 Released under GPLv2.
11
12 """
13
14 import re
15
16 from MoinMoin.parser import text_moin_wiki
17 from MoinMoin import wikiutil
18
19 class Parser(text_moin_wiki.Parser):
20
21 def __init__(self, raw, request, **kw):
22 self.scan_rules += r'|(?P<latex_formula>\$[^$].*?(?<!\\)\$)'
23 self.scan_rules += r'|(?P<latex_formula_para>\$\$.*?(?<!\\)\$\$)'
24 self.scan_re = re.compile(self.scan_rules, re.UNICODE|re.VERBOSE)
25 text_moin_wiki.Parser.__init__(self, raw, request, **kw)
26
27 _latex_plugin = None
28 def _aquire_latex_plugin(self):
29 if self._latex_plugin is None:
30 self._latex_plugin = wikiutil.importPlugin(self.cfg, 'parser', 'latex', 'Parser')
31
32 def _latex_formula_repl(self, text, groups):
33 self._aquire_latex_plugin()
34 if self._latex_plugin is None:
35 return self.formatter.text("<<please install the latex parser>>")
36 return self._latex_plugin('', self.request).get(self.formatter, text, '')
37
38 def _latex_formula_para_repl(self, text, groups):
39 self._aquire_latex_plugin()
40 if self._latex_plugin is None:
41 return self.formatter.text("<<please install the latex parser>>")
42 return self.formatter.paragraph(1) + \
43 self._latex_plugin('', self.request).get(self.formatter, text, '') + \
44 self.formatter.paragraph(0)