summaryrefslogtreecommitdiff
path: root/sphinx/ext/mathbase.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-09-23 11:03:23 +0200
committerGeorg Brandl <georg@python.org>2011-09-23 11:03:23 +0200
commit75606c01aab9d04574114e994f420c3619c7f71b (patch)
tree370b12cba4f2d19a7405c4efef31c408108def8f /sphinx/ext/mathbase.py
parentb03a49a513b97643b13f751350606400ee97af44 (diff)
parent90ee1df433d7e6443eba29a5a0da9d49f7493cee (diff)
downloadsphinx-75606c01aab9d04574114e994f420c3619c7f71b.tar.gz
Merge with 1.0
Diffstat (limited to 'sphinx/ext/mathbase.py')
-rw-r--r--sphinx/ext/mathbase.py50
1 files changed, 37 insertions, 13 deletions
diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py
index fc849584..6d080b4b 100644
--- a/sphinx/ext/mathbase.py
+++ b/sphinx/ext/mathbase.py
@@ -57,6 +57,7 @@ class MathDirective(Directive):
final_argument_whitespace = True
option_spec = {
'label': directives.unchanged,
+ 'name': directives.unchanged,
'nowrap': directives.flag,
}
@@ -66,7 +67,9 @@ class MathDirective(Directive):
latex = self.arguments[0] + '\n\n' + latex
node = displaymath()
node['latex'] = latex
- node['label'] = self.options.get('label', None)
+ node['label'] = self.options.get('name', None)
+ if node['label'] is None:
+ node['label'] = self.options.get('label', None)
node['nowrap'] = 'nowrap' in self.options
node['docname'] = self.state.document.settings.env.docname
ret = [node]
@@ -126,6 +129,24 @@ def man_visit_eqref(self, node):
raise nodes.SkipNode
+def texinfo_visit_math(self, node):
+ self.body.append('@math{' + self.escape_arg(node['latex']) + '}')
+ raise nodes.SkipNode
+
+def texinfo_visit_displaymath(self, node):
+ if node.get('label'):
+ self.add_anchor(node['label'], node)
+ self.body.append('\n\n@example\n%s\n@end example\n\n' %
+ self.escape_arg(node['latex']))
+def texinfo_depart_displaymath(self, node):
+ pass
+
+def texinfo_visit_eqref(self, node):
+ self.add_xref(node['docname'] + ':' + node['target'],
+ node['target'], node)
+ raise nodes.SkipNode
+
+
def html_visit_eqref(self, node):
self.body.append('<a href="#equation-%s">' % node['target'])
@@ -152,20 +173,23 @@ def number_equations(app, doctree, docname):
def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
app.add_node(math,
- latex=(latex_visit_math, None),
- text=(text_visit_math, None),
- man=(man_visit_math, None),
- html=htmlinlinevisitors)
+ latex=(latex_visit_math, None),
+ text=(text_visit_math, None),
+ man=(man_visit_math, None),
+ texinfo=(texinfo_visit_math, None),
+ html=htmlinlinevisitors)
app.add_node(displaymath,
- latex=(latex_visit_displaymath, None),
- text=(text_visit_displaymath, None),
- man=(man_visit_displaymath, man_depart_displaymath),
- html=htmldisplayvisitors)
+ latex=(latex_visit_displaymath, None),
+ text=(text_visit_displaymath, None),
+ man=(man_visit_displaymath, man_depart_displaymath),
+ texinfo=(texinfo_visit_displaymath, texinfo_depart_displaymath),
+ html=htmldisplayvisitors)
app.add_node(eqref,
- latex=(latex_visit_eqref, None),
- text=(text_visit_eqref, None),
- man=(man_visit_eqref, None),
- html=(html_visit_eqref, html_depart_eqref))
+ latex=(latex_visit_eqref, None),
+ text=(text_visit_eqref, None),
+ man=(man_visit_eqref, None),
+ texinfo=(texinfo_visit_eqref, None),
+ html=(html_visit_eqref, html_depart_eqref))
app.add_role('math', math_role)
app.add_role('eq', eq_role)
app.add_directive('math', MathDirective)