How to change the name "Table of Contents" in HTML sidebars

840 views
Skip to first unread message

EMK

unread,
Jun 22, 2016, 7:55:50 PM6/22/16
to sphinx-users
I'm working on a user guide delivered in HTML and the html theme "classic". I added the overall document structure to the sidebar by using the information in the http://www.sphinx-doc.org/en/stable/config.html#confval-html_sidebars documentation.

Now I have the problem that each TOC automatically gets a <h3> title that says Table of Contents. So I have multiple Table Of Contents headers in my sidebar. 

I tried adding a custom TOC name by using the caption parameter in the TOCs, but that just gets put in after Table of Contents. (And it looks like it only gets put in on the main index page, which is not really what I want...) 

So when you look at my sidebar now, you see something like this: 

Table Of Contents         <-- mysterious header content

  Configuration Guide                  <- caption from toc (only appears on index page?)
  • About this software          <-- toc contents 
  • Configuration Overview 
  • Control Panel Settings
  •   ... 
  • Appendix B: Removing Licenses 
Table Of Contents        <-- mysterious header content

  Configuration Overview            <-- local page title 
  • Networking                      <-- local page contents from titles
  • Storage
  • ...
Previous topic
 ...

Next topic
 ...

Quick search 
 ... 


I would like to be able to change one or both of the "Table of Contents" headers to some other words. 

Also it would be great if I could control the relative size of those headers, for example to have the main table of contents header stay at a <h3> and move the page contents header down to <h4>.

Thoughts? 

Komiya Takeshi

unread,
Jun 24, 2016, 11:31:10 AM6/24/16
to sphinx-users
Hi,

You can customize the caption of ToC by template.
For example, putting following code as _templates/localtoc.html changes the title.

<h3><a href="{{ pathto(master_doc) }}">TOC</a></h3>
{{ toc }}

More details, please refer the templating: http://www.sphinx-doc.org/en/stable/templating.html

Thanks,
Takeshi KOMIYA


2016年6月23日木曜日 8時55分50秒 UTC+9 EMK:

EMK

unread,
Jun 27, 2016, 7:09:04 PM6/27/16
to sphinx-users
KOMIYAさん ありがとうございます。

Does this file extend localtoc or overwrite it? 

I figured out how to do it with globaltoc (same thing but with {{ toctree() }} at the bottom), but I am worried that I will omit important parts of the original globaltoc if _templates/globaltoc.html overwrites the built-in globaltoc. 

Komiya Takeshi

unread,
Jun 29, 2016, 11:37:01 PM6/29/16
to sphinx-users
Hi,

Yes, it overrides localtoc simply.

You can see what the original parts do in here.

For example, globaltoc only shows the header and global toctree (toctree())

<h3><a href="{{ pathto(master_doc) }}">{{ _('Table Of Contents') }}</a></h3>
{{ toctree() }}


Sphinx provides small and easily extendable parts. so you don't need to worry about omitting any features usually.

Thanks,
Takeshi KOMIYA

2016年6月28日火曜日 8時09分04秒 UTC+9 EMK:

Komiya Takeshi

unread,
Jun 29, 2016, 11:37:09 PM6/29/16
to sphinx-users
Hi,

Yes, it overrides localtoc simply.

You can see what the original parts do in here.

For example, globaltoc only shows the header and global toctree (toctree())

<h3><a href="{{ pathto(master_doc) }}">{{ _('Table Of Contents') }}</a></h3>
{{ toctree() }}


Sphinx provides small and easily extendable parts. so you don't need to worry about omitting any features usually.

Thanks,
Takeshi KOMIYA

2016年6月28日火曜日 8時09分04秒 UTC+9 EMK:
KOMIYAさん ありがとうございます。
Reply all
Reply to author
Forward
0 new messages