Can a directive add to the toctree?

38 views
Skip to first unread message

Carl Gay

unread,
Jun 12, 2023, 3:47:18 PM6/12/23
to sphinx-users
Hi, I'm using a custom domain for the Dylan programming language and I would like to include all the functions, constants, etc defined with directives in the table of contents at the correct level. Is it possible to have the domain directives themselves add entries to the toctree?

From what I know so far, I'm thinking that I should be able to introspect the generated object graph to figure out the current ToC depth and (somehow) insert nodes at the next level. To be a little more concrete, if my document looks like this:

My Library
**********

My Module 1
===========

.. function:: foo

   foo is ferocious

My Module 2
===========

.. constant:: bar

   bar is best

I would like to see this table of contents in the right sidebar (I'm using the Furo theme, if it's important):

My Module 1
  foo
My Module 2
  bar

I'm hoping that someone can tell me whether I'm heading in the right direction by trying to do this with the Dylan domain code, or if I need to look at some other way to accomplish it, so that I don't spend too much time going down the wrong path.

Thanks.

Support

unread,
Jun 13, 2023, 12:47:33 AM6/13/23
to sphinx...@googlegroups.com
Greetings Carl,

when using Java/Javadoc I found its better to go the route JavaDoc --> XML --> XSLT --> RST | MD | ADOC | Docbook.
It gives you much better control over the document, e. g. what shall be a heading, what a paragraph.

For the sidebar, I use a Java Script since the Furo Sidebar does not work well for very long TOCs (and your TOC will be very long).
Also, my Java Script TOC supports simple search and hiding.

It's not exactly what you need, but it may provide you with templates or guidance.

Good luck
Andreas
--
You received this message because you are subscribed to the Google Groups "sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/db4ef36b-d326-47fa-ab9d-6e28b87ab2e9n%40googlegroups.com.

Carl Gay

unread,
Mar 2, 2025, 11:30:38 AMMar 2
to sphinx-users
I finally got around to looking into the source code myself to fix this.  For the record, here's my solution (the final commit in this PR): https://github.com/dylan-lang/sphinx-extensions/issues/23

Thanks to whichever Sphinx dev wrote the long comments on the _toc_entry_name method and related methods.

-Carl

Carl Gay

unread,
Mar 2, 2025, 11:33:18 AMMar 2
to sphinx-users
Sigh, wrong link.  It's the final commit in https://github.com/dylan-lang/sphinx-extensions/pull/38/commits
Reply all
Reply to author
Forward
0 new messages