summaryrefslogtreecommitdiff
path: root/sphinx/ext/mathbase.py
diff options
context:
space:
mode:
authorshimizukawa <shimizukawa@gmail.com>2016-01-10 10:21:27 +0900
committershimizukawa <shimizukawa@gmail.com>2016-01-10 10:21:27 +0900
commite5860fd75ca38e05cf9ba465309a5f0e00849c42 (patch)
treefd9ac5ed737a55e9fafc74d3ce2eb34c67a9ed0c /sphinx/ext/mathbase.py
parent1e2fbd463b2b2d22f0ed866ec512968e39af80a5 (diff)
parent87998df9cbef2380345d436121e6bca43345d2bd (diff)
downloadsphinx-git-e5860fd75ca38e05cf9ba465309a5f0e00849c42.tar.gz
Merge with '87998df9cbef2380345d436121e6bca43345d2bd' on stable
Conflicts: tests/test_build_latex.py
Diffstat (limited to 'sphinx/ext/mathbase.py')
-rw-r--r--sphinx/ext/mathbase.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py
index 4327fba1c..3510d5006 100644
--- a/sphinx/ext/mathbase.py
+++ b/sphinx/ext/mathbase.py
@@ -56,6 +56,17 @@ def eq_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
return [node], []
+def is_in_section_title(node):
+ """Determine whether the node is in a section title"""
+ from sphinx.util.nodes import traverse_parent
+
+ for ancestor in traverse_parent(node):
+ if isinstance(ancestor, nodes.title) and \
+ isinstance(ancestor.parent, nodes.section):
+ return True
+ return False
+
+
class MathDirective(Directive):
has_content = True
@@ -91,7 +102,12 @@ class MathDirective(Directive):
def latex_visit_math(self, node):
- self.body.append('\\(' + node['latex'] + '\\)')
+ if is_in_section_title(node):
+ protect = r'\protect'
+ else:
+ protect = ''
+ equation = protect + r'\(' + node['latex'] + protect + r'\)'
+ self.body.append(equation)
raise nodes.SkipNode
@@ -214,3 +230,4 @@ def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
app.add_role('eq', eq_role)
app.add_directive('math', MathDirective)
app.connect('doctree-resolved', number_equations)
+ app.add_latex_package('amsfonts')