Commits

Akihiro Uchida committed a7d581e

enable javascript macro and texcommand preamble for MathJax

Comments (0)

Files changed (1)

sphinx/ext/mathjax.py

         raise ExtensionError('mathjax_path config value must be set for the '
                              'mathjax extension to work')
     app.add_javascript(app.config.mathjax_path)
+    if app.config.mathjax_macropath:
+        app.add_javascript(app.config.mathjax_macropath)
 
+def html_page_context(app, pagename, templatename, context, doctree):
+    if app.config.mathjax_preamble and 'body' in context:
+        preamble = ''.join(['<div id="preamble" style="display:none">',
+                            app.config.mathjax_inline[0],
+                            app.config.mathjax_preamble,
+                            app.config.mathjax_inline[1], '</div>\n'])
+        context['body'] = preamble + context['body']
 
 def setup(app):
     mathbase_setup(app, (html_visit_math, None), (html_visit_displaymath, None))
     app.add_config_value('mathjax_path',
                          'http://cdn.mathjax.org/mathjax/latest/MathJax.js?'
                          'config=TeX-AMS-MML_HTMLorMML', False)
+    app.add_config_value('mathjax_macropath', False, 'html')
+    app.add_config_value('mathjax_preamble', False, 'html')
     app.add_config_value('mathjax_inline', [r'\(', r'\)'], 'html')
     app.add_config_value('mathjax_display', [r'\[', r'\]'], 'html')
     app.connect('builder-inited', builder_inited)
+    app.connect('html-page-context', html_page_context)