Hello, I've tried to write a MathJax extension, but I've run into the following problem: MathJax needs a non-empty script tag whose contents are used for configuration options. For example, the script tag could look like this:
<script type="text/javascript" src="/MathJax/MathJax.js"> MathJax.Hub.Config({ config: ["MMLorHTML.js"], extensions: [], jax: ["input/TeX"], MMLorHTML: {prefer: "MML"} }); </script> if the preprocessor should be disabled (which is reasonable because Sphinx replaces the preprocessor), and MathML output should be used if possible (increases speed in Firefox). But add_javascript doesn't seem to let one specify these contents. Also, I don't know how to implement the nowrap option or numbered equations, maybe someone with a better understanding of Sphinx and MathJax could help out. This is my first attempt (untested because of the configuration problem): # -*- coding: utf-8 -*- """ sphinx.ext.mathjax ~~~~~~~~~~~~~~~~~~ Set up everything for use of MathJax to display math in HTML via JavaScript. :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ from docutils import nodes from sphinx.application import ExtensionError from sphinx.ext.mathbase import setup_math as mathbase_setup def html_visit_math(self, node): code = self.encode(node['latex']) self.body.append(self.starttag(node, 'span', CLASS='MathJax_Preview')) self.body.append(code + '</span>') self.body.append(self.starttag(node, 'script', TYPE='math/tex')) self.body.append(code + '</script>') raise nodes.SkipNode def html_visit_displaymath(self, node): if node['nowrap'] or node['number']: # TODO: how to implement this raise NotImplementedError code = self.encode(node['latex']) self.body.append(self.starttag(node, 'span', CLASS='MathJax_Preview')) self.body.append(code + '</span>') self.body.append(self.starttag(node, 'script', TYPE='math/tex; mode=display')) self.body.append(code + '</script>\n') raise nodes.SkipNode def builder_inited(app): if not app.config.mathjax_path: raise ExtensionError('mathjax_path config value must be set for the ' 'mathjax extension to work') app.add_javascript(app.config.mathjax_path) # TODO: MathJax needs a non-empty script tag def setup(app): mathbase_setup(app, (html_visit_math, None), (html_visit_displaymath, None)) app.add_config_value('mathjax_path', '', False) app.connect('builder-inited', builder_inited) -- You received this message because you are subscribed to the Google Groups "sphinx-dev" group. To post to this group, send email to sphinx-...@googlegroups.com. To unsubscribe from this group, send email to sphinx-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sphinx-dev?hl=en.