mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
math: Add hyperlink marker to each equations in HTML output
This commit is contained in:
parent
b21ba65873
commit
4fbcb5bfd6
1
CHANGES
1
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
|
||||
|
@ -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('<p>')
|
||||
if node['number']:
|
||||
self.body.append('<span class="eqno">(%s)</span>' % node['number'])
|
||||
self.body.append('<span class="eqno">(%s)' % node['number'])
|
||||
self.add_permalink_ref(node, _('Permalink to this code'))
|
||||
self.body.append('</span>')
|
||||
if fname is None:
|
||||
# something failed -- use text-only as a bad substitute
|
||||
self.body.append('<span class="math">%s</span></p>\n</div>' %
|
||||
|
@ -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('<span class="eqno">(%s)</span>' %
|
||||
node['number'])
|
||||
self.body.append('<span class="eqno">(%s)' % node['number'])
|
||||
self.add_permalink_ref(node, _('Permalink to this code'))
|
||||
self.body.append('</span>')
|
||||
self.body.append(self.starttag(node, 'div', CLASS='math'))
|
||||
else:
|
||||
# but only once!
|
||||
|
@ -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('<span class="eqno">(%s)</span>' % node['number'])
|
||||
self.body.append('<span class="eqno">(%s)' % node['number'])
|
||||
self.add_permalink_ref(node, _('Permalink to this code'))
|
||||
self.body.append('</span>')
|
||||
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
|
||||
|
@ -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 {
|
||||
|
@ -968,8 +968,10 @@ def test_jsmath(app, status, warning):
|
||||
|
||||
assert '<div class="math">\na^2 + b^2 = c^2</div>' in content
|
||||
assert '<div class="math">\n\\begin{split}a + 1 < b\\end{split}</div>' in content
|
||||
assert ('<span class="eqno">(1)</span><div class="math" id="equation-foo">\n'
|
||||
'e^{i\\pi} = 1</div>' in content)
|
||||
print content
|
||||
assert (u'<span class="eqno">(1)<a class="headerlink" href="#equation-foo" '
|
||||
u'title="Permalink to this code">\xb6</a></span>'
|
||||
u'<div class="math" id="equation-foo">\ne^{i\\pi} = 1</div>' in content)
|
||||
assert ('<span class="eqno">(2)</span><div class="math">\n'
|
||||
'e^{ix} = \\cos x + i\\sin x</div>' in content)
|
||||
assert '<div class="math">\nn \\in \\mathbb N</div>' in content
|
||||
|
Loading…
Reference in New Issue
Block a user