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

LaTeX: wrong internal links in pdf to captioned code-blocks when numfig is not True #8735

Closed
jfbu opened this issue Jan 23, 2021 · 0 comments · Fixed by #8736
Closed

LaTeX: wrong internal links in pdf to captioned code-blocks when numfig is not True #8735

jfbu opened this issue Jan 23, 2021 · 0 comments · Fixed by #8736

Comments

@jfbu
Copy link
Contributor

jfbu commented Jan 23, 2021

Describe the bug

Captioned code-blocks in distinct sections which are numbered the same confuse the internal links inside pdf output.

To Reproduce
Steps to reproduce the behavior:

Use sphinx-quickstart to create fresh project then use following index.rst file

Welcome to FOO's documentation!
===============================

Section One
-----------

This link: :ref:`last` fails to jump to last code-block in pdf output
(if ``numfig`` not set).

.. code-block:: none
   :caption: first

   a

.. code-block:: none
   :caption: second
   :name: II

   b


.. code-block:: none
   :caption: third

   c

Section Two
-----------

.. code-block:: none
   :caption: last one
   :name: last

   d

.. See also :numref:`II`.

The pdf link :ref:`last` brings us back to first code-block in first section.

Execute make latexpdf and open pdf output in some viewer. The internal hyperlinks are wrong. Also the latex log file contains following warnings:

Chapter 2.
pdfTeX warning (ext4): destination with the same identifier (name{literalblock.
1}) has been already used, duplicate ignored

Expected behavior

Internal links in pdf work.

Environment info

  • Python version: 3.6.8 (CPython)
  • Sphinx version: tested with v2.0.0 as well as current 3.x
  • Extra tools: TeXLive 2020

Additional context
With numfig = True in conf.py, the issue does not show.

@jfbu jfbu added this to the 3.5.0 milestone Jan 23, 2021
jfbu added a commit to jfbu/sphinx that referenced this issue Jan 23, 2021
It is hard to provide a unit test, because the problem only raises a
LaTeX warning and show only as broken internal links in pdf output.

As the fix moves some LaTeX code to the end of preamble, user or
extension code may have to be moved to.  However, a large part of it
already was delayed.  I checked that sphinxmessages.tex does not
introduce code in preamble which would be broken from missing macros due
to this change.
jfbu added a commit to jfbu/sphinx that referenced this issue Jan 23, 2021
It is hard to provide a unit test, because the problem only raises a
LaTeX warning and shows as broken internal links in pdf output.

As the fix moves some LaTeX code to the end of preamble, user or
extension code may have to be moved there too.  However, a large part of
it already was delayed.  I checked that sphinxmessages.tex does not
introduce preamble code which would be broken from missing macros due
to this change.
@jfbu jfbu mentioned this issue Jan 23, 2021
tk0miya added a commit that referenced this issue Jan 23, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant