diff --git a/CHANGES b/CHANGES index b42bd5b15..c71261032 100644 --- a/CHANGES +++ b/CHANGES @@ -65,6 +65,7 @@ Features added * #2663: Add ``--warning-is-error`` option to setup.py command * Show warnings if deprecated latex options are used * Add sphinx.config.ENUM to check the config values is in candidates +* math: Add hyperlink marker to each equations in HTML output Bugs fixed diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py index f8e402be3..927429086 100644 --- a/sphinx/ext/imgmath.py +++ b/sphinx/ext/imgmath.py @@ -22,6 +22,7 @@ from six import text_type from docutils import nodes import sphinx +from sphinx.locale import _ from sphinx.errors import SphinxError, ExtensionError from sphinx.util.png import read_png_depth, write_png_depth from sphinx.util.osutil import ensuredir, ENOENT, cd @@ -253,7 +254,9 @@ def html_visit_displaymath(self, node): self.body.append(self.starttag(node, 'div', CLASS='math')) self.body.append('

') if node['number']: - self.body.append('(%s)' % node['number']) + self.body.append('(%s)' % node['number']) + self.add_permalink_ref(node, _('Permalink to this code')) + self.body.append('') if fname is None: # something failed -- use text-only as a bad substitute self.body.append('%s

\n' % diff --git a/sphinx/ext/jsmath.py b/sphinx/ext/jsmath.py index f36e12fed..9fb790e1b 100644 --- a/sphinx/ext/jsmath.py +++ b/sphinx/ext/jsmath.py @@ -13,6 +13,7 @@ from docutils import nodes import sphinx +from sphinx.locale import _ from sphinx.application import ExtensionError from sphinx.ext.mathbase import setup_math as mathbase_setup @@ -34,8 +35,9 @@ def html_visit_displaymath(self, node): if i == 0: # necessary to e.g. set the id property correctly if node['number']: - self.body.append('(%s)' % - node['number']) + self.body.append('(%s)' % node['number']) + self.add_permalink_ref(node, _('Permalink to this code')) + self.body.append('') self.body.append(self.starttag(node, 'div', CLASS='math')) else: # but only once! diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py index bdaab55e0..420e2b312 100644 --- a/sphinx/ext/mathjax.py +++ b/sphinx/ext/mathjax.py @@ -14,6 +14,7 @@ from docutils import nodes import sphinx +from sphinx.locale import _ from sphinx.errors import ExtensionError from sphinx.ext.mathbase import setup_math as mathbase_setup @@ -35,7 +36,9 @@ def html_visit_displaymath(self, node): # necessary to e.g. set the id property correctly if node['number']: - self.body.append('(%s)' % node['number']) + self.body.append('(%s)' % node['number']) + self.add_permalink_ref(node, _('Permalink to this code')) + self.body.append('') self.body.append(self.builder.config.mathjax_display[0]) parts = [prt for prt in node['latex'].split('\n\n') if prt.strip()] if len(parts) > 1: # Add alignment if there are more than 1 equation diff --git a/sphinx/themes/basic/static/basic.css_t b/sphinx/themes/basic/static/basic.css_t index cdc703b09..585e992a5 100644 --- a/sphinx/themes/basic/static/basic.css_t +++ b/sphinx/themes/basic/static/basic.css_t @@ -585,6 +585,16 @@ span.eqno { float: right; } +span.eqno a.headerlink { + position: relative; + left: 0px; + z-index: 1; +} + +div.math:hover a.headerlink { + visibility: visible; +} + /* -- printout stylesheet --------------------------------------------------- */ @media print { diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 7a0cb7cfd..43f5d4519 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -968,8 +968,10 @@ def test_jsmath(app, status, warning): assert '
\na^2 + b^2 = c^2
' in content assert '
\n\\begin{split}a + 1 < b\\end{split}
' in content - assert ('(1)
\n' - 'e^{i\\pi} = 1
' in content) + print content + assert (u'(1)\xb6' + u'
\ne^{i\\pi} = 1
' in content) assert ('(2)
\n' 'e^{ix} = \\cos x + i\\sin x
' in content) assert '
\nn \\in \\mathbb N
' in content