sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.39k stars 2.09k forks source link

Receive duplicate label warnings when creating multiple docs that use the same figure. Ref to figure is broken. #10202

Open tbird1965 opened 2 years ago

tbird1965 commented 2 years ago

Describe the bug

I am trying to create numerous product "howto" documents that use one common figure. I have set tuples for the various docs:

latex_documents = [ ('howto1', 'howto1.tex', 'HowTo Number 1', 'John Doe', 'howto', False), ('howto2', 'howto2.tex', 'HowTo Number 2', 'John Doe', 'howto', False), ]

During the make latex step, I receive warnings of duplicate label for the figure and the :ref: command is broken in one of the two documents.

fig.reST:7: WARNING: duplicate label logo_fig, other instance in d:\sphinx_test\howto1.rst

It appears to me that the front end Sphinx label/reference table handling does not understand the situation, because it is complaining that I already defined "logo_fig" (but in a different document). Surely it should be possible to use the same figure and label in multiple documents.

I have the figure in a file called, "fig.reST" so Sphinx does not analyze it.

In "howto1.rst", I include "fig.reST" and have a ":ref:" command to the figure. The ref link is broken in this document.

In "howto2.rst", I include "fig.reST" and have a ":ref:" command to the figure. The ref link is working in this document.

I have attached a MWE with the latex builds included. sphinx_test.zip

Even if I manually put the figure in each howto rst file instead of include, I get the same errors since both documents have a figure label called, logo_fig.

In my actual task, I am not just including a simple figure - it is more of a section that will have titles, text, a figure and some other links. So I am not only trying to avoid including this over and over, I am also really trying to avoid creating different figure labels! Right now my task has about 83 separate howtos that refer to one of six different figures.

How to Reproduce

See attached MWE in description.

Expected behavior

Sphinx should support including the same reference label in different documents that are listed in the latex_documents tuple.

Your project

MWE is attached

Screenshots

fig.reST fig

conf.py tuple tuple

howto2.rst howto2

howto1.rst howto1

OS

Win 10

Python version

3.9.10

Sphinx version

4.4.0

Sphinx extensions

none

Extra tools

none

Additional context

No response

vincentkfu commented 1 year ago

Seems to be a duplicate of https://github.com/sphinx-doc/sphinx/issues/9707

tbird1965 commented 1 year ago

I disagree. #9707 is regarding referencing a link twice within a single document, whereas #10202 is regarding links in completely different documents being built by Sphinx. I can see an argument where #9707 is "just how it is", but if #10202 is "just how it is", then my opinion would be why even allow Sphinx to build multiple documents at once? The only time a person would build multiple documents at once is if they were connected somehow, and that would often lead to some time of reference reuse. I worked around this problem by using a Python script to modify all of the links to include a sequential number, depending on which document it was. At that point, I could have scripted 83 separate Sphinx builds. Really an unnecessary effort in either case.