Skip to content

Fix duplicate label warnings for included files (#14413)#14417

Open
FazeelUsmani wants to merge 2 commits intosphinx-doc:masterfrom
FazeelUsmani:fix-numref-include-14413
Open

Fix duplicate label warnings for included files (#14413)#14417
FazeelUsmani wants to merge 2 commits intosphinx-doc:masterfrom
FazeelUsmani:fix-numref-include-14413

Conversation

@FazeelUsmani
Copy link
Copy Markdown
Contributor

Purpose

Fix false-positive "duplicate label" warnings when files are both included via .. include:: and processed as standalone documents.

When a file containing labels (e.g., figures with :name:) is included in another document using the .. include:: directive, and that same file is also in the toctree as a standalone document, Sphinx would emit duplicate label warnings even though both labels originate from the same source file.

This fix tracks the source file path for each label and compares them when detecting duplicates. If both labels come from the same source file, the warning is suppressed and the label from the including document is preferred (for proper figure numbering with :numref:).

Real duplicates (same label defined in different source files) still produce warnings as expected.

References

@FazeelUsmani FazeelUsmani force-pushed the fix-numref-include-14413 branch from 77c50a5 to f8d1efe Compare April 29, 2026 12:57
@FazeelUsmani FazeelUsmani force-pushed the fix-numref-include-14413 branch from 17ca9b0 to c27fbad Compare April 29, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

:numref: not working in :include: directives

1 participant