sphinx-doc / sphinx-doc/sphinx
`genindex` et al. inclusion in `toctree` directive results in a warning with the `latexpdf` builder
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the warning with the provided index.rst and the html and latexpdf builders, including the guarded toctree example. Trace how the latexpdf builder handles the special docname and toctree warning, then verify that the expected output remains unchanged and the warning is absent when building with -W.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100