Changeset 3463
- Timestamp:
- 04/04/08 03:58:46 (8 months ago)
- Files:
-
- tracmathplugin/tracmath/tracmath.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tracmathplugin/tracmath/tracmath.py
r3462 r3463 1 1 """ TracMath - A trac plugin that renders latex formulas within a wiki page. 2 2 3 This has currently been tested only on trac 0.1 1.3 This has currently been tested only on trac 0.10.4 and 0.11. 4 4 """ 5 5 … … 42 42 re.compile(r'.+dvi$'), 43 43 ] 44 reLABEL = re.compile(r'\\label\{(.*?)\}') 44 45 45 46 class TracMathPlugin(Component): … … 66 67 self.max_png = self.config.get('tracmath', 'max_png') or max_png 67 68 self.max_png = int(self.max_png) 69 self.use_dollars = self.config.get('tracmath', 'use_dollars') or "False" 70 self.use_dollars = self.use_dollars.lower() in ("true", "on", "enabled") 68 71 69 72 if not os.path.exists(self.cacheDirectory): … … 93 96 return [] 94 97 98 # IWikiSyntaxProvider methods 99 # stolen from http://trac-hacks.org/ticket/248 100 101 def get_wiki_syntax(self): 102 if self.use_dollars: 103 yield (r"\$\$(?P<displaymath>.*?)\$\$", 104 lambda formatter, ns, match: "<blockquote>" + self.expand_macro(formatter, 'latex', ns) + "</blockquote>") 105 yield (r"\$(?P<latex>.*?)\$", 106 lambda formatter, ns, match: self.expand_macro(formatter, 'latex', ns)) 107 108 def get_link_resolvers(self): 109 return [] 110 95 111 # IWikiMacroProvider methods 96 112 def get_macros(self): … … 99 115 def get_macro_description(self, name): 100 116 if name == 'latex': 101 return 'LaTeX' 117 return """ 118 This plugin allows embedded equations in Trac markup. 119 Basically a port of http://www.amk.ca/python/code/mt-math to Trac. 120 121 Simply use 122 {{{ 123 {{{ 124 #!latex 125 [latex code] 126 }}} 127 }}} 128 for a block of LaTeX code. 129 130 If `use_dollars` is enabled in `trac.ini`, then you can also use 131 `$[latex formula]$` for inline math or `$$[latex formula]$$` for 132 display math. 133 """ 102 134 103 135 def internal_render(self, req, name, content): 104 136 if not name == 'latex': 105 137 return 'Unknown macro %s' % (name) 138 139 label = None 140 for line in content.split("\n"): 141 m = reLABEL.match(content) 142 if m: 143 label = m.group(1) 106 144 107 145 key = sha.new(content.encode('utf-8')).hexdigest() … … 147 185 self.manage_cache() 148 186 149 return '<img src="%s/tracmath/%s" />' % (req.base_url, imgname) 187 result = '<img src="%s/tracmath/%s" alt="%s" />' % (req.base_url, imgname, content) 188 if label: 189 result = '<a name="%s">(%s)<a/> %s' % (label, label, result) 190 return result 150 191 151 192 def manage_cache(self): … … 176 217 def expand_macro(self, formatter, name, content): 177 218 return self.internal_render(formatter.req, name, content) 219 220 # needed for Trac 0.10.4 221 def render_macro(self, req, name, content): 222 return self.internal_render(req, name, content) 178 223 179 224 # IHTMLPreviewRenderer methods
