This version is for older Moin versions, you might need ../inline-1.7.

   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 Johannes Berg <johannes@sipsolutions.net>
   9 
  10 Released under GPLv2.
  11 
  12 """
  13 
  14 from MoinMoin.parser import wiki
  15 from MoinMoin import wikiutil
  16 
  17 class Parser(wiki.Parser):
  18 
  19     def __init__(self, raw, request, **kw):
  20         self.formatting_rules += r'|(?P<latex_formula>\$[^$].*?(?<!\\)\$)'
  21         self.formatting_rules += r'|(?P<latex_formula_para>\$\$.*?(?<!\\)\$\$)'
  22         wiki.Parser.__init__(self, raw, request, **kw)
  23 
  24     _latex_plugin = None
  25     def _aquire_latex_plugin(self):
  26         if self._latex_plugin is None:
  27             # get an exception? for moin before 1.3.2 use the following line instead:
  28             # self._latex_plugin = wikiutil.importPlugin('parser', 'latex', 'Parser', self.cfg.data_dir)
  29             self._latex_plugin = wikiutil.importPlugin(self.cfg, 'parser', 'latex', 'Parser')
  30 
  31     def _latex_formula_repl(self, text, **kw):
  32         self._aquire_latex_plugin()
  33         if self._latex_plugin is None:
  34             return self.formatter.text("<<please install the latex parser>>")
  35         return self._latex_plugin('', self.request).get(self.formatter, text, '')
  36 
  37     def _latex_formula_para_repl(self, text, **kw):
  38         self._aquire_latex_plugin()
  39         if self._latex_plugin is None:
  40             return self.formatter.text("<<please install the latex parser>>")
  41         return self.formatter.paragraph(1) + \
               self._latex_plugin('', self.request).get(self.formatter, text, '') + \
               self.formatter.paragraph(0)