mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
use numfig for numbering equations by section rather than page
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -37,6 +37,7 @@ Features added
|
||||
* #4052: viewcode: Sort before highlighting module code
|
||||
* #1448: qthelp: Add new config value; :confval:`qthelp_namespace`
|
||||
* #4140: html themes: Make body tag inheritable
|
||||
* #3991, #4080: Add :confval:`math_numfig` for equation numbering by section
|
||||
|
||||
|
||||
Features removed
|
||||
|
||||
@@ -44,6 +44,14 @@ or use Python raw strings (``r"raw"``).
|
||||
|
||||
Example: ``'Eq.{number}'`` is rendered as ``Eq.10``
|
||||
|
||||
.. confval:: math_numfig
|
||||
|
||||
If ``True``, displayed math equations are numbered across pages using numfig.
|
||||
The :confval:`numfig` config value must be enabled and
|
||||
:confval:`numfig_secnum_depth` is respected. The ``:eq:`` role must be used
|
||||
to refererence these equation numbers, not the ``:numref:`` role.
|
||||
Default is ``False``.
|
||||
|
||||
:mod:`.mathbase` defines these new markup elements:
|
||||
|
||||
.. rst:role:: math
|
||||
|
||||
@@ -30,6 +30,7 @@ from sphinx.util.png import read_png_depth, write_png_depth
|
||||
from sphinx.util.osutil import ensuredir, ENOENT, cd
|
||||
from sphinx.util.pycompat import sys_encoding
|
||||
from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath
|
||||
from sphinx.ext.mathbase import get_node_equation_number
|
||||
|
||||
if False:
|
||||
# For type annotation
|
||||
@@ -333,7 +334,8 @@ 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)' % node['number'])
|
||||
number = get_node_equation_number(self.builder.env, node)
|
||||
self.body.append('<span class="eqno">(%s)' % number)
|
||||
self.add_permalink_ref(node, _('Permalink to this equation'))
|
||||
self.body.append('</span>')
|
||||
if fname is None:
|
||||
|
||||
@@ -16,6 +16,7 @@ import sphinx
|
||||
from sphinx.locale import _
|
||||
from sphinx.application import ExtensionError
|
||||
from sphinx.ext.mathbase import setup_math as mathbase_setup
|
||||
from sphinx.ext.mathbase import get_node_equation_number
|
||||
|
||||
|
||||
def html_visit_math(self, node):
|
||||
@@ -35,7 +36,8 @@ 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)' % node['number'])
|
||||
number = get_node_equation_number(self.builder.env, node)
|
||||
self.body.append('<span class="eqno">(%s)' % number)
|
||||
self.add_permalink_ref(node, _('Permalink to this equation'))
|
||||
self.body.append('</span>')
|
||||
self.body.append(self.starttag(node, 'div', CLASS='math'))
|
||||
|
||||
@@ -84,6 +84,13 @@ class MathDomain(Domain):
|
||||
newnode['target'] = target
|
||||
return newnode
|
||||
else:
|
||||
if env.config.math_numfig and env.config.numfig:
|
||||
if docname in env.toc_fignumbers:
|
||||
id = 'equation-' + target
|
||||
number = env.toc_fignumbers[docname]['displaymath'].get(id, ())
|
||||
number = '.'.join(map(str, number))
|
||||
else:
|
||||
number = ''
|
||||
try:
|
||||
eqref_format = env.config.math_eqref_format or "({number})"
|
||||
title = nodes.Text(eqref_format.format(number=number))
|
||||
@@ -126,6 +133,20 @@ class MathDomain(Domain):
|
||||
return len(targets) + 1
|
||||
|
||||
|
||||
def get_node_equation_number(env, node):
|
||||
if env.config.math_numfig and env.config.numfig:
|
||||
docname = node['docname']
|
||||
if docname in env.toc_fignumbers:
|
||||
id = node['ids'][0]
|
||||
number = env.toc_fignumbers[docname]['displaymath'].get(id, ())
|
||||
number = '.'.join(map(str, number))
|
||||
else:
|
||||
number = ''
|
||||
else:
|
||||
number = node['number']
|
||||
return number
|
||||
|
||||
|
||||
def wrap_displaymath(math, label, numbering):
|
||||
# type: (unicode, unicode, bool) -> unicode
|
||||
def is_equation(part):
|
||||
@@ -341,6 +362,7 @@ def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
|
||||
# type: (Sphinx, Tuple[Callable, Any], Tuple[Callable, Any]) -> None
|
||||
app.add_config_value('math_number_all', False, 'env')
|
||||
app.add_config_value('math_eqref_format', None, 'env', string_classes)
|
||||
app.add_config_value('math_numfig', False, 'env')
|
||||
app.add_domain(MathDomain)
|
||||
app.add_node(math, override=True,
|
||||
latex=(latex_visit_math, None),
|
||||
@@ -348,7 +370,7 @@ def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
|
||||
man=(man_visit_math, None),
|
||||
texinfo=(texinfo_visit_math, None),
|
||||
html=htmlinlinevisitors)
|
||||
app.add_node(displaymath,
|
||||
app.add_enumerable_node(displaymath, 'displaymath',
|
||||
latex=(latex_visit_displaymath, None),
|
||||
text=(text_visit_displaymath, None),
|
||||
man=(man_visit_displaymath, man_depart_displaymath),
|
||||
|
||||
@@ -17,6 +17,7 @@ import sphinx
|
||||
from sphinx.locale import _
|
||||
from sphinx.errors import ExtensionError
|
||||
from sphinx.ext.mathbase import setup_math as mathbase_setup
|
||||
from sphinx.ext.mathbase import get_node_equation_number
|
||||
|
||||
|
||||
def html_visit_math(self, node):
|
||||
@@ -36,7 +37,8 @@ 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)' % node['number'])
|
||||
number = get_node_equation_number(self.builder.env, node)
|
||||
self.body.append('<span class="eqno">(%s)' % number)
|
||||
self.add_permalink_ref(node, _('Permalink to this equation'))
|
||||
self.body.append('</span>')
|
||||
self.body.append(self.builder.config.mathjax_display[0])
|
||||
|
||||
@@ -30,6 +30,7 @@ from sphinx.util.png import read_png_depth, write_png_depth
|
||||
from sphinx.util.osutil import ensuredir, ENOENT, cd
|
||||
from sphinx.util.pycompat import sys_encoding
|
||||
from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath
|
||||
from sphinx.ext.mathbase import get_node_equation_number
|
||||
|
||||
if False:
|
||||
# For type annotation
|
||||
@@ -242,7 +243,8 @@ 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'])
|
||||
number = get_node_equation_number(self.builder.env, node)
|
||||
self.body.append('<span class="eqno">(%s)</span>' % number)
|
||||
if fname is None:
|
||||
# something failed -- use text-only as a bad substitute
|
||||
self.body.append('<span class="math">%s</span></p>\n</div>' %
|
||||
|
||||
Reference in New Issue
Block a user