Skip to content

Commit

Permalink
Handle change in math node structure in Sphinx 1.8.0
Browse files Browse the repository at this point in the history
Sphinx 1.8 changes math nodes from <displaymath latex="f(x) = x^2" />
to <math_block>f(x) = x^2</math_block>, so accessing the 'latex'
attribute of the node no longer works.
  • Loading branch information
speth authored and hagenw committed Sep 27, 2018
1 parent 946133c commit 20d45ba
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sphinxcontrib/katex.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,25 @@ def latex_defs_to_katex_macros(defs):
return macros


def get_latex(node):
if 'latex' in node.attributes:
return node['latex'] # for Sphinx < 1.8.0
else:
return node.astext() # for Sphinx >= 1.8.0


def html_visit_math(self, node):
self.body.append(self.starttag(node, 'span', '', CLASS='math'))
self.body.append(self.builder.config.katex_inline[0] +
self.encode(node['latex']) +
self.encode(get_latex(node)) +
self.builder.config.katex_inline[1] + '</span>')
raise nodes.SkipNode


def html_visit_displaymath(self, node):
self.body.append(self.starttag(node, 'div', CLASS='math'))
if node['nowrap']:
self.body.append(self.encode(node['latex']))
self.body.append(self.encode(get_latex(node)))
self.body.append('</div>')
raise nodes.SkipNode

Expand All @@ -90,7 +97,7 @@ def html_visit_displaymath(self, node):
self.add_permalink_ref(node, _('Permalink to this equation'))
self.body.append('</span>')
self.body.append(self.builder.config.katex_display[0])
self.body.append(node['latex'])
self.body.append(get_latex(node))
self.body.append(self.builder.config.katex_display[1])
self.body.append('</div>\n')
raise nodes.SkipNode
Expand Down

0 comments on commit 20d45ba

Please sign in to comment.