Skip to content

Commit 6cc1177

Browse files
thfanningThomas FanningAA-Turner
authored
Allow configuring the separator used in numbering equations (#12523)
Co-authored-by: Thomas Fanning <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent 82edc3d commit 6cc1177

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ Features added
6868
and :confval:`texinfo_domain_indices`,
6969
can now be a set of strings.
7070
Patch by Adam Turner.
71+
* #12523: Added configuration option, :confval:`math_numsep`, to define the
72+
separator for math numbering.
73+
Patch by Thomas Fanning
7174

7275
Bugs fixed
7376
----------

doc/usage/configuration.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,18 @@ These options control maths markup and notation.
906906

907907
.. versionadded:: 1.7
908908

909+
.. confval:: math_numsep
910+
:type: :code-py:`str`
911+
:default: :code-py:`'.'`
912+
913+
A string that defines the separator between section numbers
914+
and the equation number when :confval:`numfig` is enabled and
915+
:confval:`numfig_secnum_depth` is positive.
916+
917+
Example: :code-py:`'-'` gets rendered as ``1.2-3``.
918+
919+
.. versionadded:: 7.4
920+
909921

910922
Options for the nitpicky mode
911923
-----------------------------

sphinx/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ class Config:
258258
'math_number_all': _Opt(False, 'env', ()),
259259
'math_eqref_format': _Opt(None, 'env', frozenset((str,))),
260260
'math_numfig': _Opt(True, 'env', ()),
261+
'math_numsep': _Opt('.', 'env', frozenset((str,))),
261262
'tls_verify': _Opt(True, 'env', ()),
262263
'tls_cacerts': _Opt(None, 'env', ()),
263264
'user_agent': _Opt(None, 'env', frozenset((str,))),

sphinx/domains/math.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def resolve_xref(self, env: BuildEnvironment, fromdocname: str, builder: Builder
106106
if docname in env.toc_fignumbers:
107107
numbers = env.toc_fignumbers[docname]['displaymath'].get(node_id, ())
108108
eqno = '.'.join(map(str, numbers))
109+
eqno = env.config.math_numsep.join(eqno.rsplit('.', 1))
109110
else:
110111
eqno = ''
111112
else:

sphinx/util/math.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def get_node_equation_number(writer: HTML5Translator, node: nodes.math_block) ->
2020

2121
id = node['ids'][0]
2222
number = writer.builder.fignumbers.get(key, {}).get(id, ())
23-
return '.'.join(map(str, number))
23+
eqno = '.'.join(map(str, number))
24+
eqno = writer.builder.config.math_numsep.join(eqno.rsplit('.', 1))
25+
return eqno
2426
else:
2527
return node['number']
2628

tests/test_extensions/test_ext_math.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ def test_mathjax_numfig_html(app, status, warning):
193193
assert html in content
194194

195195

196+
@pytest.mark.sphinx('html', testroot='ext-math',
197+
confoverrides={'extensions': ['sphinx.ext.mathjax'],
198+
'numfig': True,
199+
'math_numfig': True,
200+
'math_numsep': '-'})
201+
def test_mathjax_numsep_html(app, status, warning):
202+
app.build(force_all=True)
203+
204+
content = (app.outdir / 'math.html').read_text(encoding='utf8')
205+
html = ('<div class="math notranslate nohighlight" id="equation-math-0">\n'
206+
'<span class="eqno">(1-2)')
207+
assert html in content
208+
html = ('<p>Referencing equation <a class="reference internal" '
209+
'href="#equation-foo">(1-1)</a> and '
210+
'<a class="reference internal" href="#equation-foo">(1-1)</a>.</p>')
211+
assert html in content
212+
213+
196214
@pytest.mark.sphinx('html', testroot='ext-math',
197215
confoverrides={'extensions': ['sphinx.ext.imgmath'],
198216
'numfig': True,

0 commit comments

Comments
 (0)