annotate data/plugin/parser/inline_latex.py @ 360:f57de7994cf6

mathtran, inline_latex, text_x_mathtran: fixed comments
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 17 Feb 2009 23:46:42 +0100
parents fbe7054d683e
children 0fae349c457c
rev   line source
358
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 """
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 inline_latex is a parser that allows regular moin moin wiki syntax,
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3 but also latex style inline formulas like $...$ and latex style
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4 paragraph formulas like $$...$$. Note that in the latter case, you
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5 are (unlike in latex) limited to a single line. If you absolutely
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6 need multiple lines, use the parser directly.
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8 Copyright 2005 Johannes Berg <johannes@sipsolutions.net>
360
f57de7994cf6 mathtran, inline_latex, text_x_mathtran: fixed comments
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 359
diff changeset
9 2009 MoinMoin:ReimarBauer changed for 1.7.2/1.8 and the mathtran extension
358
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
10 Released under GPLv2.
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11 """
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
12 import re
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13 from MoinMoin.parser import text_moin_wiki as wiki
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14 from MoinMoin import wikiutil
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
15
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 class Parser(wiki.Parser):
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17 extensions = '*.tex'
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18 scan_rules = wiki.Parser.scan_rules
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 scan_rules += ur'|(?P<latex_formula>\$[^$].*?(?<!\\)\$)'
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20 scan_rules += ur'|(?P<latex_formula_para>\$\$.*?(?<!\\)\$\$)'
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
21
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22 scan_re = re.compile(scan_rules, re.UNICODE|re.VERBOSE)
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 def __init__(self, raw, request, **kw):
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
25 wiki.Parser.__init__(self, raw, request, **kw)
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
26 self.formatter = request.formatter
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
27 self.request = request
359
fbe7054d683e inline_latex: argument passing to text_x_mathtran added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 358
diff changeset
28 self.args = kw.get('format_args', '')
358
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29 self.mathtran_parser = wikiutil.importPlugin(self.request.cfg, 'parser', 'text_x_mathtran', 'Parser')
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31 def _latex_formula_repl(self, word, groups):
359
fbe7054d683e inline_latex: argument passing to text_x_mathtran added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 358
diff changeset
32 mp = self.mathtran_parser(word, self.request, format_args=self.args)
358
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33 if mp.init_settings:
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34 return mp.render(self.formatter)
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
35
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
36 def _latex_formula_para_repl(self, word, groups):
359
fbe7054d683e inline_latex: argument passing to text_x_mathtran added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 358
diff changeset
37 mp = self.mathtran_parser(word, self.request, format_args=self.args)
358
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
38 if mp.init_settings:
73775c708eba refactored inline_latex parser from JohannesBerg. This parser allows regular moin moin wiki syntax, but also latex style inline formulas like $...$ and latex style paragraph formulas like $$...$$.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 return "%s%s%s" % (self.formatter.paragraph(1), mp.render(self.formatter), self.formatter.paragraph(0))