mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
parent
9669f2a48b
commit
eac142f8b8
@ -56,6 +56,17 @@ def eq_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
|
|||||||
return [node], []
|
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):
|
class MathDirective(Directive):
|
||||||
|
|
||||||
has_content = True
|
has_content = True
|
||||||
@ -91,7 +102,12 @@ class MathDirective(Directive):
|
|||||||
|
|
||||||
|
|
||||||
def latex_visit_math(self, node):
|
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
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Test math extensions
|
Test math extensions :math:`E = m c^2`
|
||||||
====================
|
======================================
|
||||||
|
|
||||||
This is inline math: :math:`a^2 + b^2 = c^2`.
|
This is inline math: :math:`a^2 + b^2 = c^2`.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user