How can i include the `genindex` in a Sphinx TOC?
Asked Answered
A

2

22

Sphinx generates an index named genindex when building a documentation and therefore forbids to use that name for a document. Now, how would I include a link to that index in a table of contents?

I've tried this:

.. toctree::
   :maxdepth: 2

   genindex
   api


Indices and tables
==================

* :ref:`genindex`

While the last line does create a link to that index in the document, the build doesn't know the reference when creating the TOC:

WARNING: toctree contains reference to nonexisting document 'genindex'
Alodie answered 26/3, 2016 at 12:58 Comment(3)
Same as https://mcmap.net/q/520583/-how-to-add-sphinx-generated-index-to-the-sidebar-when-using-read-the-docs-theme/407651Mazzola
Does this answer your question? How can I link the generated index page in ReadTheDocs navigation bar?Courland
Can you please explain the equation: 4 years, 2 months > 4 years, 9 months @Paebbles?Moresque
D
9

Create a File genindex.rst with the following Content:

Index
=====

In your index.rst add:

.. toctree::
   :hidden:

   genindex

If you you also want to have the Link and Text "Index" on the Site and not only in the left Navigation then remove :hidden:

Decanal answered 18/2, 2017 at 3:39 Comment(3)
that's funny, the docs explicitly state not to create a file with that name.Alodie
You are right. That can cause Issues. I have one Project where the PDF Creation with rst2pdf doesn't work unless I do not remove the "genindex.rst"-Hack.Decanal
that's not so funny.Alodie
A
3

Good news, everyone! A patch has been merged and was released with Sphinx 5.2.0. Now genindex, modindex and search can be included as TOC items without further ado.

Alodie answered 9/4, 2023 at 20:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.