Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It cannot change the width of the index in the table of contents #10858

Closed
domr2695 opened this issue Sep 24, 2022 · 6 comments
Closed

It cannot change the width of the index in the table of contents #10858

domr2695 opened this issue Sep 24, 2022 · 6 comments

Comments

@domr2695
Copy link

Describe the bug

sphinx ver. 5.1.1

When building tableofcontents, the index of the table of contents 14.100 fits on the table of contents row.:

14.100Release 1.4.1 (released Apr 12, 2016)

But there is no way to allocate more space for the width. Only with your hands in "sphinxmanual.cls"

In line 105 or 106 you can correct this by increasing the size of the field. You also have to insert lines with your hands for:
\renewcommand*\l@chapter{@dottedtocline{1}{2.0em}{2.6em}}
\renewcommand*[l@subsubsection](mailto:l@subsubsection){@dottedtocline{1}{2.0em}{2.6em}}
and re-create *.pdf by "make all"

The documentation says:
“tableofcontents” call. The default of '\sphinxtableofcontents' is a wrapper of unmodified \tableofcontents, which may itself be customized by user loaded packages. Override if you want to generate a different table of contents or put content between the title page and the TOC.
Default: '\sphinxtableofcontents'
Changed in version 1.5: Previously the meaning of \tableofcontents itself was modified by Sphinx. This created an incompatibility with dedicated packages modifying it also such as “tocloft” or “etoc”.

An attempt to disable '\sphinxtableofcontents' and use the 'tocloft' package did not lead to anything, unless you replace the string in the *.tex file:
\sphinxtableofcontents
per line
\tableofcontents
and execute «make all».

Neither
tableofcontents = '\tableofcontents'
nor
tableofcontents = '\tableofcontents'
allow using '\tableofcontents'. Line:
\sphinxtableofcontents
in the *.tex file remains and in the *.pdf file the header numbers fit on their text.

How to Reproduce

You can see yourself in https://www.sphinx-doc.org/_/downloads/en/master/pdf/
in table of contents lines:

14.58 Release 2.0.1 (released Apr 08, 2019) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
14.59 Release 2.0.0 (released Mar 29, 2019) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
14.60 Release 1.8.6 (released Nov 18, 2021) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
14.61 Release 1.8.5 (released Mar 10, 2019) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
14.62 Release 1.8.4 (released Feb 03, 2019) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
14.63 Release 1.8.3 (released Dec 26, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
14.64 Release 1.8.2 (released Nov 11, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
14.65 Release 1.8.1 (released Sep 22, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
14.66 Release 1.8.0 (released Sep 13, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
14.67 Release 1.7.9 (released Sep 05, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
14.68 Release 1.7.8 (released Aug 29, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
14.69 Release 1.7.7 (released Aug 19, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
14.70 Release 1.7.6 (released Jul 17, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
14.71 Release 1.7.5 (released May 29, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
14.72 Release 1.7.4 (released Apr 25, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
14.73 Release 1.7.3 (released Apr 23, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
14.74 Release 1.7.2 (released Mar 21, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
14.75 Release 1.7.1 (released Feb 23, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
14.76 Release 1.7.0 (released Feb 12, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
14.77 Release 1.6.7 (released Feb 04, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
14.78 Release 1.6.6 (released Jan 08, 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
14.79 Release 1.6.5 (released Oct 23, 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
14.80 Release 1.6.4 (released Sep 26, 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
14.81 Release 1.6.3 (released Jul 02, 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
14.82 Release 1.6.2 (released May 28, 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
14.83 Release 1.6.1 (released May 16, 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
14.84 Release 1.6 (unreleased) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
14.85 Release 1.5.6 (released May 15, 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
14.86 Release 1.5.5 (released Apr 03, 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
14.87 Release 1.5.4 (released Apr 02, 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
14.88 Release 1.5.3 (released Feb 26, 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
14.89 Release 1.5.2 (released Jan 22, 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
14.90 Release 1.5.1 (released Dec 13, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
14.91 Release 1.5 (released Dec 5, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
14.92 Release 1.4.9 (released Nov 23, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
14.93 Release 1.4.8 (released Oct 1, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
14.94 Release 1.4.7 (released Oct 1, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
14.95 Release 1.4.6 (released Aug 20, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
14.96 Release 1.4.5 (released Jul 13, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
14.97 Release 1.4.4 (released Jun 12, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
14.98 Release 1.4.3 (released Jun 5, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
14.99 Release 1.4.2 (released May 29, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
14.100Release 1.4.1 (released Apr 12, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
14.101Release 1.4 (released Mar 28, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
14.102Release 1.3.6 (released Feb 29, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
14.103Release 1.3.5 (released Jan 24, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
14.104Release 1.3.4 (released Jan 12, 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
14.105Release 1.3.3 (released Dec 2, 2015) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
14.106Release 1.3.2 (released Nov 29, 2015) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
14.107Release 1.3.1 (released Mar 17, 2015) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
14.108Release 1.3 (released Mar 10, 2015) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
14.109Release 1.3b3 (released Feb 24, 2015) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
14.110Release 1.3b2 (released Dec 5, 2014) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
14.111Release 1.3b1 (released Oct 10, 2014) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544
ix
14.112Release 1.2.3 (released Sep 1, 2014) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
14.113Release 1.2.2 (released Mar 2, 2014) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
14.114Release 1.2.1 (released Jan 19, 2014) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
14.115Release 1.2 (released Dec 10, 2013) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
14.116Release 1.2 beta3 (released Oct 3, 2013) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
14.117Release 1.2 beta2 (released Sep 17, 2013) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
14.118Release 1.2 beta1 (released Mar 31, 2013) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556
14.119Release 1.1.3 (Mar 10, 2012) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
14.120Release 1.1.2 (Nov 1, 2011) – 1.1.1 is a silly version number anyway! . . . . . . . . . . . . . . . . . 563
14.121Release 1.1.1 (Nov 1, 2011) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
14.122Release 1.1 (Oct 9, 2011) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
14.123Release 1.0.8 (Sep 23, 2011) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
14.124Release 1.0.7 (Jan 15, 2011) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
14.125Release 1.0.6 (Jan 04, 2011) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
14.126Release 1.0.5 (Nov 12, 2010) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
14.127Release 1.0.4 (Sep 17, 2010) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
14.128Release 1.0.3 (Aug 23, 2010) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
14.129Release 1.0.2 (Aug 14, 2010) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570
14.130Release 1.0.1 (Jul 27, 2010) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570
14.131Release 1.0 (Jul 23, 2010) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
14.132Previous versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574

Expected behavior

No response

Your project

file:///media/u1/s1/Linux/Publishing/md_to_rst/test/0/test.zip

Screenshots

No response

OS

Linux A1 5.19.0-1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.19.6-1 (2022-09-01) x86_64 GNU/Linux

Python version

Python 3.10.7

Sphinx version

5.1.1

Sphinx extensions

No response

Extra tools

No response

Additional context

No response

@AA-Turner
Copy link
Member

cc @jfbu

A

@jfbu
Copy link
Contributor

jfbu commented Sep 24, 2022

Try adding this to conf.py

latex_elements = {
    'preamble': r'''
\makeatletter
\renewcommand{\sphinxtableofcontentshook}{%
  \renewcommand*\l@section{\@dottedtocline{1}{1.5em}{3em}}%
  \renewcommand*\l@subsection{\@dottedtocline{2}{4.5em}{4em}}%
}
\makeatother
''',
}

With this I obtain
Capture d’écran 2022-09-24 à 17 13 17

By the way we should probably do indeed something like this and perhaps I should increase the 3em for such sections in TOC, the 4.5em for subsections should be increased by the same delta to keep entries aligned for example as in this:
Capture d’écran 2022-09-24 à 17 13 40

If you are familiar with tocloft and want to use its interface, (which avoids having to be careful about \makeatletter/\makeatother) you can do something like this

latex_elements = {
    'preamble': r'''
\usepackage{tocloft}
\setlength{\cftsecnumwidth}{3em}
\setlength{\cftsubsecindent}{4.5em}
\setlength{\cftsubsecnumwidth}{4em}
\renewcommand{\sphinxtableofcontentshook}{}% else it will overwrite tocloft!
''',
}

You might see in console output during latex build:

Package tocloft Warning: \@starttoc has already been redefined; tocloft bailing
 out. on input line 1156.

tocloft interface still works... the message is (almost) a bug of tocloft that you can ignore.
It has nothing to do with Sphinx.

(I think I remember it is package parskip which triggers this and that I reported to tocloft maintainers some years ago)

@jfbu
Copy link
Contributor

jfbu commented Sep 24, 2022

Thanks for reporting, possibly our document should be improved (both to explain and to avoid the collisions in the TOC).

@domr2695
Copy link
Author

domr2695 commented Sep 24, 2022

Thank you so much for your reply. It completely solves the problems that I outlined above.

Many thanks to AA-Turner (Adam Turner) for bringing my question to you.

This information must be included in the Sphinx documentation.
Your answer should also be brought to those who create Sphinx pdf, so that they correct the cutting of indexes into lines of text in the table of contents.

It's nice that the choice has been preserved: use sphinxtableofcontentshook or tocloft. or something else.
And most importantly, nothing needs to be changed, just used correctly.

One question remains: so the tableofcontents parameter in conf.py works or not. If it works, then it does not work as described in the documentation. If it doesn't work, then it should be excluded from the documentation.

@jfbu
Copy link
Contributor

jfbu commented Sep 24, 2022

@domr2695 Glad it worked!

The 'tableofcontents' works as designed and documented. If for example you use

latex_elements = {
    'tableofcontents': r'\tableofcontents',
}

and do make latex you can check that the produced .tex file will contain

\pagestyle{empty}
\sphinxmaketitle
\pagestyle{plain}
\tableofcontents

where \tableofcontents has replaced \sphinxtableofcontents. In that case the \sphinxtableofcontentshook macro is not all executed because it is only part of \sphinxtableofcontents.

The documentation also contains
Capture d’écran 2022-09-24 à 22 31 12
and does not look wrong. I will add a note regarding the necessity to renewcommand \sphinxtableofcontentshook to do nothing in case tocloft is used.

@jfbu
Copy link
Contributor

jfbu commented Sep 24, 2022

I will merge #10859 once testing completes, which will close this issue.

@jfbu jfbu closed this as completed in 89a656d Sep 24, 2022
jfbu added a commit that referenced this issue Sep 24, 2022
LaTeX: improve doc of \sphinxtableofcontents (closes #10858)
jfbu added a commit to jfbu/sphinx that referenced this issue Sep 24, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants