---
title: "Modify Sphinx TOC tree"  
description: "Modify Sphinx TOC tree"  
author: "Anonymous User"  
published: 2015-11-19  
updated: 2015-11-19  
canonical: https://www.mindstick.com/forum/33611/modify-sphinx-toc-tree  
category: "python"  
tags: ["python-3.4"]  
reading_time: 2 minutes  

---

# Modify Sphinx TOC tree

I have a [Sphinx project](https://github.com/facebook/presto/tree/master/presto-docs/src/main/sphinx) with a TOC ([index](https://www.mindstick.com/blog/198/index-in-sql-server).rst) that includes :maxdepth: 2. The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is I want to reduce the [depth](https://yourviews.mindstick.com/view/84531/nepal-plane-crash-in-depth-analysis-amp-insights) to 1 for the [release](https://www.mindstick.com/news/2247/apple-plans-to-release-new-macs-in-early-2023) [section](https://yourviews.mindstick.com/view/297/reservation-for-economically-weaker-section) so that it doesn't include the list of release notes in the main TOC (the list is too [long](https://www.mindstick.com/articles/44565/white-wedding-dresses-long-prom-dresses)).\
It seems that the TOC list can be modified using a doctree-resolved [event handler](https://www.mindstick.com/forum/1371/c-sharp-dot-net-event-handler-delegate-question), but I can't [figure](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) out how to modify the TOC tree in the event handler:\

```
from sphinx import addnodesdef setup(app):    def update_toctree(app, doctree, docname):        if docname != 'index':            return        node = doctree.traverse(addnodes.toctree)[0]        toc = app.env.resolve_toctree(docname, app.builder, node)        # do something with "toc" here    app.connect('doctree-resolved', update_toctree)
```

## Replies

### Reply by Anonymous User

Perhaps not an ideal solution, but I've done something like this before using multiple toctree entries on the same page, something like:\

```
####################Presto Documentation####################.. toctree::    :maxdepth: 2    overview    installation.. toctree::    :maxdepth: 1    release
```

It's not ideal since most themes will add extra padding between the trees, but in my case that was better than having the huge list of nested items for certain pages.


---

Original Source: https://www.mindstick.com/forum/33611/modify-sphinx-toc-tree

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
