Skip to content

genindex et al. inclusion in toctree directive results in a warning with the latexpdf builder #13733

@BrunoMSantos

Description

@BrunoMSantos

Describe the bug

Adding genindex (or any other special docname) works perfectly with the html builder, but, despite producing the expected output for the latexpdf builder, it always warns:

WARNING: toctree contains ref to nonexisting file 'genindex' [toc.not_readable]

Possibly an unrelated issue, I then tried this with no change, which means the only directive somehow works differently when it guards a toctree directive or maybe its block is still evaluated before being discarded.

.. only:: html
   .. toctree::
      :hidden:

      genindex

Either way I see no way of cleanly suppressing the warning, which is annoying since I wanted to compile with -W.

How to Reproduce

$ cat index.rst
.. toctree::

genindex
$ cat conf.py
$ sphinx-build -M html . html/ # this is fine
$ sphinx-build -M latexpdf . pdf/ # this is not fine

Environment Information

Platform:              linux; (Linux-6.15.6-arch1-1-x86_64-with-glibc2.41)
Python version:        3.13.5 (main, Jun 21 2025, 09:35:00) [GCC 15.1.1 20250425])
Python implementation: CPython
Sphinx version:        8.2.3
Docutils version:      0.21.2
Jinja2 version:        3.1.6
Pygments version:      2.19.2

Sphinx extensions

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions