# -*- coding: utf-8 -*- """ sphinx.ext.jsmath ~~~~~~~~~~~~~~~~~ Set up everything for use of JSMath to display math in HTML via JavaScript. :copyright: Copyright 2007-2011 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): self.body.append(self.starttag(node, 'span', '', CLASS='math')) self.body.append(self.encode(node['latex']) + '') raise nodes.SkipNode def html_visit_displaymath(self, node): if node['nowrap']: self.body.append(self.starttag(node, 'div', CLASS='math')) self.body.append(node['latex']) self.body.append('') raise nodes.SkipNode for i, part in enumerate(node['latex'].split('\n\n')): part = self.encode(part) if i == 0: # necessary to e.g. set the id property correctly if node['number']: self.body.append('(%s)' % node['number']) self.body.append(self.starttag(node, 'div', CLASS='math')) else: # but only once! self.body.append('