changeset 2401:101ee945a170

Use MathJax for formatting equations when math_url is set to mathjax
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Mon, 13 May 2013 13:18:12 +0200
parents 9430e08ac757
children def91dbc545d
files hatta/page.py hatta/parser.py hatta/templates/base.html hatta/wiki.py
diffstat 4 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hatta/page.py	Sun May 12 23:12:52 2013 +0200
+++ b/hatta/page.py	Mon May 13 13:18:12 2013 +0200
@@ -482,11 +482,10 @@
         return content
 
     def wiki_math(self, math_text, display=False):
-        math_url = self.config.get('math_url',
-                            'http://www.mathtran.org/cgi-bin/mathtran?tex=')
+        math_url = self.wiki.math_url
         if math_url == '':
             return werkzeug.escape(math_text)
-        elif math_url == '$':
+        elif math_url == 'mathjax':
             if display:
                 return werkzeug.escape(u"$$\n%s\n$$" % math_text)
             else:
--- a/hatta/parser.py	Sun May 12 23:12:52 2013 +0200
+++ b/hatta/parser.py	Mon May 13 13:18:12 2013 +0200
@@ -389,7 +389,7 @@
                 math_text = self.wiki_math(math_text, True)
             else:
                 math_text = werkzeug.escape(math_text)
-            yield werkzeug.html.pre(
+            yield werkzeug.html.div(
                 math_text,
                 class_="display-math",
                 id="line_%d" % self.line_no,
--- a/hatta/templates/base.html	Sun May 12 23:12:52 2013 +0200
+++ b/hatta/templates/base.html	Mon May 13 13:18:12 2013 +0200
@@ -23,6 +23,24 @@
 {% block scripts %}
     <script type="text/javascript"
             src="{{ url(None, wiki.scripts_js) }}"></script>
+    {% if wiki.math_url == 'mathjax' %}
+    <script type="text/x-mathjax-config">
+        MathJax.Hub.Config({
+            tex2jax: {
+                inlineMath: [['$','$']],
+                displayMath: [['$$','$$']],
+                ignoreClass: ".*",
+                processClass: "^(display|inline)-math$",
+                processEscapes: true
+            },
+            showMathMenu: false,
+            showMathMenuMSIE: false
+        });
+    </script>
+    <script type="text/javascript"
+        src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
+    ></script>
+    {% endif %}
 {% endblock %}
 
 {% block logo %}
--- a/hatta/wiki.py	Sun May 12 23:12:52 2013 +0200
+++ b/hatta/wiki.py	Mon May 13 13:18:12 2013 +0200
@@ -250,6 +250,8 @@
         self.icon_page = self.config.get('icon_page', None)
         self.alias_page = self.config.get('alias_page', 'Alias')
         self.help_page = self.config.get('help_page', 'Help')
+        self.math_url = self.config.get('math_url',
+            'http://www.mathtran.org/cgi-bin/mathtran?tex=')
         self.pygments_style = self.config.get('pygments_style', 'tango')
         self.subdirectories = self.config.get_bool('subdirectories', False)
         self.extension = self.config.get('extension', None)