Skip to content

LaTeX: reST label before a module (or automodule) sphinx.ext.autodoc directive causes pdf build to report multiply defined reference #11093

@jfbu

Description

@jfbu

Describe the bug

As said in the title, the PDF build reports multiply-defined references.

How to Reproduce

Use

import os
import sys
sys.path.insert(0, os.path.abspath('.'))

extensions = ['sphinx.ext.autodoc']

in conf.py

file index.rst:

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

.. toctree::

   testfile

file testfile.rst:

.. _somelabel:

.. module:: testmodule

Some title
==========

Some text.

.. autofunction:: foo

file testmodule.py

"""not much here
"""

def foo():
    "I do not do much and simply return ``None``"

    return None

(the autofunction part is not part of the problem).

Then run make latexpdf.

Console output ends with

Latexmk: ====List of undefined refs and citations:
  Label `testfile:somelabel' multiply defined

This is not a serious problem (meaning it does not cause build failure).

But it happens in real life, see numpy/numpy#22930 (comment) and the

LaTeX Warning: Label `reference/maskedarray.generic:maskedarray-generic' multip
ly defined.

is an instance of the present issue. I have not yet checked but expect the others reported there as well.

Environment Information

Platform:              darwin
Python version:        3.10.9 (v3.10.9:1dd9be6584, Dec  6 2022, 14:37:36) [Clang 13.0.0 (clang-1300.0.29.30)])
Python implementation: CPython
Sphinx version:        6.2.0+/6e6b9ad45
Docutils version:      0.19
Jinja2 version:        3.1.2
Pygments version:      2.14.0

Sphinx extensions

``["sphinx.ext.autodoc"]``

Edit: all NumPy instances from building their numpy-ref.pdf are of this nature: numpy/numpy#22930 (comment)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions