diff --git a/CHANGES.rst b/CHANGES.rst index 67b363757f3..fcdcf2df9af 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -68,6 +68,9 @@ Features added and :confval:`texinfo_domain_indices`, can now be a set of strings. Patch by Adam Turner. +* #12523: Added configuration option, :confval:`math_numsep`, to define the + separator for math numbering. + Patch by Thomas Fanning Bugs fixed ---------- diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 614db1a336a..f67f840c326 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -906,6 +906,18 @@ These options control maths markup and notation. .. versionadded:: 1.7 +.. confval:: math_numsep + :type: :code-py:`str` + :default: :code-py:`'.'` + + A string that defines the separator between section numbers + and the equation number when :confval:`numfig` is enabled and + :confval:`numfig_secnum_depth` is positive. + + Example: :code-py:`'-'` gets rendered as ``1.2-3``. + + .. versionadded:: 7.4 + Options for the nitpicky mode ----------------------------- diff --git a/sphinx/config.py b/sphinx/config.py index 15c585a0a54..7f1138025bc 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -258,6 +258,7 @@ class Config: 'math_number_all': _Opt(False, 'env', ()), 'math_eqref_format': _Opt(None, 'env', frozenset((str,))), 'math_numfig': _Opt(True, 'env', ()), + 'math_numsep': _Opt('.', 'env', frozenset((str,))), 'tls_verify': _Opt(True, 'env', ()), 'tls_cacerts': _Opt(None, 'env', ()), 'user_agent': _Opt(None, 'env', frozenset((str,))), diff --git a/sphinx/domains/math.py b/sphinx/domains/math.py index 4583b2c060d..f136cfda106 100644 --- a/sphinx/domains/math.py +++ b/sphinx/domains/math.py @@ -106,6 +106,7 @@ def resolve_xref(self, env: BuildEnvironment, fromdocname: str, builder: Builder if docname in env.toc_fignumbers: numbers = env.toc_fignumbers[docname]['displaymath'].get(node_id, ()) eqno = '.'.join(map(str, numbers)) + eqno = env.config.math_numsep.join(eqno.rsplit('.', 1)) else: eqno = '' else: diff --git a/sphinx/util/math.py b/sphinx/util/math.py index 97b8440b67e..a0783068d09 100644 --- a/sphinx/util/math.py +++ b/sphinx/util/math.py @@ -20,7 +20,9 @@ def get_node_equation_number(writer: HTML5Translator, node: nodes.math_block) -> id = node['ids'][0] number = writer.builder.fignumbers.get(key, {}).get(id, ()) - return '.'.join(map(str, number)) + eqno = '.'.join(map(str, number)) + eqno = writer.builder.config.math_numsep.join(eqno.rsplit('.', 1)) + return eqno else: return node['number'] diff --git a/tests/test_extensions/test_ext_math.py b/tests/test_extensions/test_ext_math.py index bbff31f2c09..80a5ae71a47 100644 --- a/tests/test_extensions/test_ext_math.py +++ b/tests/test_extensions/test_ext_math.py @@ -193,6 +193,24 @@ def test_mathjax_numfig_html(app, status, warning): assert html in content +@pytest.mark.sphinx('html', testroot='ext-math', + confoverrides={'extensions': ['sphinx.ext.mathjax'], + 'numfig': True, + 'math_numfig': True, + 'math_numsep': '-'}) +def test_mathjax_numsep_html(app, status, warning): + app.build(force_all=True) + + content = (app.outdir / 'math.html').read_text(encoding='utf8') + html = ('
\n' + '(1-2)') + assert html in content + html = ('

Referencing equation (1-1) and ' + '(1-1).

') + assert html in content + + @pytest.mark.sphinx('html', testroot='ext-math', confoverrides={'extensions': ['sphinx.ext.imgmath'], 'numfig': True,