Skip to content

Commit 8dd7a23

Browse files
jdillardAA-Turner
andauthored
Add warning sub-type for duplicate equation label warnings (#13929)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent e929009 commit 8dd7a23

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ Bugs fixed
120120
configuration variable ``doctest_test_doctest_blocks``.
121121
* #13885: Coverage builder: Fix TypeError when warning about missing modules.
122122
Patch by Damien Ayers.
123+
* #13929: Duplicate equation label warnings now have a new warning
124+
sub-type, ``ref.equation``.
125+
Patch by Jared Dillard.
123126

124127

125128
Testing

doc/usage/configuration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,7 @@ Options for warning control
13941394
* ``ref.any``
13951395
* ``ref.citation``
13961396
* ``ref.doc``
1397+
* ``ref.equation``
13971398
* ``ref.footnote``
13981399
* ``ref.keyword``
13991400
* ``ref.numref``

sphinx/domains/math.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def note_equation(self, docname: str, labelid: str, location: Any = None) -> Non
7474
labelid,
7575
other,
7676
location=location,
77+
type='ref',
78+
subtype='equation',
7779
)
7880

7981
self.equations[labelid] = (docname, self.env.new_serialno('eqno') + 1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extensions = ['sphinx.ext.mathjax']
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Test duplicate equation labels
2+
===============================
3+
4+
First equation with label:
5+
6+
.. math::
7+
:label: duplicated
8+
9+
a^2 + b^2 = c^2
10+
11+
Second equation with the same label:
12+
13+
.. math::
14+
:label: duplicated
15+
16+
e^{i\pi} + 1 = 0

tests/test_extensions/test_ext_math.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,19 @@ def test_mathjax_is_installed_if_included_file_has_equations_singlehtml(
566566

567567
content = (app.outdir / 'index.html').read_text(encoding='utf8')
568568
assert MATHJAX_URL in content
569+
570+
571+
@pytest.mark.sphinx(
572+
'html',
573+
testroot='ext-math-duplicate-label',
574+
confoverrides={'extensions': ['sphinx.ext.mathjax'], 'show_warning_types': True},
575+
)
576+
def test_duplicate_equation_label_warning_type(app: SphinxTestApp) -> None:
577+
"""Test that duplicate equation labels emit warnings with type ref.equation."""
578+
app.build(force_all=True)
579+
580+
from sphinx._cli.util.errors import strip_escape_sequences
581+
582+
warnings = strip_escape_sequences(app.warning.getvalue())
583+
assert 'WARNING: duplicate label of equation duplicated' in warnings
584+
assert '[ref.equation]' in warnings

0 commit comments

Comments
 (0)