Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include a local table of contents into Sphinx doc?

How to include a local table of contents into Sphinx doc?

I tried

.. toc::  

But that doesn't seem to have any effect: nothing is inserted in the document.

Basically I need links to the sections in the current page to be placed at a certain location of each page.

Is this possible?

like image 452
Edy Bourne Avatar asked Jun 09 '14 21:06

Edy Bourne


People also ask

What is Toctree Sphinx?

The toctree directive is the central element. Note. Simple “inclusion” of one file in another can be done with the include directive.

Does Sphinx support markdown?

To support Markdown-based documentation, Sphinx can use MyST-Parser. MyST-Parser is a Docutils bridge to markdown-it-py, a Python package for parsing the CommonMark Markdown flavor.


2 Answers

I'm not 100% sure this is what you're looking for, but the .. contents:: directive may help. By default, it'll give you the headings for the whole page, wherever you put the directive. With :local: specified, it will generate a local TOC for the headings below where you put the directive (handy for sub-section tocs).

.. contents:: Table of Contents     :depth: 3 

More details here: http://docutils.sourceforge.net/docs/ref/rst/directives.html#table-of-contents

like image 127
morric Avatar answered Nov 07 '22 07:11

morric


I had more luck with:

.. contents:: Table of Contents    :depth: 1    :local:    :backlinks: none 

The backlinks gets rid of the annoying links back from the headings to the toc.

like image 39
isparks Avatar answered Nov 07 '22 05:11

isparks