Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

References to figures without captions: errors in both HTML and LaTeX #6914

Closed
eudoxos opened this issue Dec 10, 2019 · 1 comment
Closed

Comments

@eudoxos
Copy link

eudoxos commented Dec 10, 2019

Describe the bug
Using figures without captions causes errors in both HTML (though these are properly reported when source is processed) and in LaTeX (they are not reported until LaTeX says there were undefined references).

This was the test document, compiled with sphinx 2.2.2 from pypi; numfig=True was added to conf.py, the project was otherwise generated with sphinx-build with no other changes. It is attached here: sphinx-captions.zip

Welcome to foo's documentation!
===============================

References:

* figure without caption

   * plain reference :ref:`fig-sample-nocaption` (error: HTML, LaTeX)
   * named reference :ref:`figure without caption <fig-sample-nocaption>` (error: LaTeX)
   * numbered reference :numref:`fig-sample-nocaption` (error: LaTeX)

* figure with caption

   * plain reference :ref:`fig-sample-caption`
   * named reference :ref:`figure without caption <fig-sample-caption>`
   * numbered reference :numref:`fig-sample-caption`

.. _fig-sample-nocaption:
.. figure:: sample.png


.. _fig-sample-caption:
.. figure:: sample.png
   
   This is some caption.

and these are the results:

  1. misleading warning: index.rst:8: WARNING: undefined label: fig-sample-nocaption (if the link has no caption the label must precede a section header)
  2. this is HTML output (the error highlighted corresponds to the warning mentioned above):
    html output
  3. this is LaTeX (pdflatex) output:
LaTeX Warning: Hyper reference `index:fig-sample-nocaption' on page 1 undefined
 on input line 99.
LaTeX Warning: Hyper reference `index:fig-sample-nocaption' on page 1 undefined
 on input line 102.

latex output

Expected behavior
I expect

  1. sphinx to produce valid LaTeX input without undefined references;
  2. uncaptioned figures to be referencable in LaTeX (this could be an optional setting perhaps causing uncaptioned figured to produce only "Figure 4.1." caption);
  3. warning about figure not being captioned to be more meaningful -- I understand that non-numbered figure cannot be referenced via :ref:label (as the label will not resolve to any text) but the warning is not pointing to how to fix the issue.

Environment info

  • OS: Ubuntu 18.04 LTS
  • Python version: 3.6.8
  • Sphinx version: 2.2.2
  • Sphinx extensions: none
  • Extra tools: pdflatex TeXLive
@tk0miya tk0miya added this to the 3.3.0 milestone Aug 8, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 8, 2020
…ref:

To be clear the ambiguous warning for missing-reference :ref:,
this separates the warning to missing-label and missing-caption.

To emit a warning dynamically, this also adds a new event:
`warn-missing-reference` to customize warning messages via event
handlers.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 8, 2020
…ref:

To be clear the ambiguous warning for missing-reference :ref:,
this separates the warning to missing-label and missing-caption.

To emit a warning dynamically, this also adds a new event:
`warn-missing-reference` to customize warning messages via event
handlers.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 8, 2020
…ref:

To be clear the ambiguous warning for missing-reference :ref:,
this separates the warning to missing-label and missing-caption.

To emit a warning dynamically, this also adds a new event:
`warn-missing-reference` to customize warning messages via event
handlers.
@tk0miya
Copy link
Member

tk0miya commented Aug 8, 2020

Thank you for reporting.

sphinx to produce valid LaTeX input without undefined references;

Yes, it would be better to do that by disabling the broken hyperlinks.

uncaptioned figures to be referencable in LaTeX (this could be an optional setting perhaps causing uncaptioned figured to produce only "Figure 4.1." caption);

I think this is a bug of the figure-number assignment logic. The figure having caption should have "Fig.1" in HTML output. And the :numref: reference to the uncaptioned figure should be warned.

warning about figure not being captioned to be more meaningful -- I understand that non-numbered figure cannot be referenced via :ref:label (as the label will not resolve to any text) but the warning is not pointing to how to fix the issue.

Agreed. I just posted #8075 to make the warning message meaningful.

tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 8, 2020
…ptioned items

The figure numbers should be assigned to items only having captions or
titles.  This uses `get_numfig_title()` to ensures it on assign numbers.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 8, 2020
…ref:

To be clear the ambiguous warning for missing-reference :ref:,
this separates the warning to missing-label and missing-caption.

To emit a warning dynamically, this also adds a new event:
`warn-missing-reference` to customize warning messages via event
handlers.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 8, 2020
…ptioned items

The figure numbers should be assigned to items only having captions or
titles.  This uses `get_numfig_title()` to ensures it on assign numbers.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 10, 2020
…ptioned items

The figure numbers should be assigned to items only having captions or
titles.  This uses `get_numfig_title()` to ensures it on assign numbers.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Oct 4, 2020
…ref:

To be clear the ambiguous warning for missing-reference :ref:,
this separates the warning to missing-label and missing-caption.

To emit a warning dynamically, this also adds a new event:
`warn-missing-reference` to customize warning messages via event
handlers.
@tk0miya tk0miya closed this as completed in 66dda1f Oct 4, 2020
tk0miya added a commit that referenced this issue Oct 4, 2020
Fix #6914: figure numbers are unexpectedly assigned to uncaptioned items
@tk0miya tk0miya reopened this Oct 4, 2020
@tk0miya tk0miya modified the milestones: 3.3.0, 3.4.0 Nov 1, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Nov 2, 2020
…ref:

To be clear the ambiguous warning for missing-reference :ref:,
this separates the warning to missing-label and missing-caption.

To emit a warning dynamically, this also adds a new event:
`warn-missing-reference` to customize warning messages via event
handlers.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Nov 2, 2020
…ref:

To be clear the ambiguous warning for missing-reference :ref:,
this separates the warning to missing-label and missing-caption.

To emit a warning dynamically, this also adds a new event:
`warn-missing-reference` to customize warning messages via event
handlers.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Nov 2, 2020
…ref:

To be clear the ambiguous warning for missing-reference :ref:,
this separates the warning to missing-label and missing-caption.

To emit a warning dynamically, this also adds a new event:
`warn-missing-reference` to customize warning messages via event
handlers.
@tk0miya tk0miya closed this as completed in 0e98e9b Nov 3, 2020
tk0miya added a commit that referenced this issue Nov 3, 2020
…ng_ref

Fix #6914: Emit a detailed warning when failed to resolve :ref:
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants