Merge pull request #5852 from jfbu/latex_tableofcontentshook

LaTeX: move some hard-coded re-definitions to user hook for TOC
This commit is contained in:
Jean-François B 2018-12-23 11:45:14 +01:00 committed by GitHub
commit 60ef37ce33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 11 deletions

View File

@ -45,6 +45,11 @@ Incompatible changes
block. As a result, they are highlighted as python3 by default. block. As a result, they are highlighted as python3 by default.
* The order of argument for ``HTMLTranslator``, ``HTML5Translator`` and * The order of argument for ``HTMLTranslator``, ``HTML5Translator`` and
``ManualPageTranslator`` are changed ``ManualPageTranslator`` are changed
* LaTeX: hard-coded redefinitions of ``\l@section`` and ``\l@subsection``
formerly done during loading of ``'manual'`` docclass get executed later, at
time of ``\sphinxtableofcontents``. This means that custom user definitions
from LaTeX preamble now get overwritten. Use ``\sphinxtableofcontentshook``
to insert custom user definitions. See :ref:`latex-macros`.
Deprecated Deprecated
---------- ----------

View File

@ -365,6 +365,8 @@ Here are some macros from the package file :file:`sphinx.sty` and class files
:file:`sphinxhowto.cls`, :file:`sphinxmanual.cls`, which have public names :file:`sphinxhowto.cls`, :file:`sphinxmanual.cls`, which have public names
thus allowing redefinitions. Check the respective files for the defaults. thus allowing redefinitions. Check the respective files for the defaults.
.. _latex-macros:
Macros Macros
~~~~~~ ~~~~~~
@ -390,11 +392,18 @@ Macros
.. versionadded:: 1.6.3 .. versionadded:: 1.6.3
``\sphinxstylecodecontinued`` and ``\sphinxstylecodecontinues``. ``\sphinxstylecodecontinued`` and ``\sphinxstylecodecontinues``.
- the table of contents is typeset via ``\sphinxtableofcontents`` which is a - the table of contents is typeset via ``\sphinxtableofcontents`` which is a
wrapper (whose definition can be found in :file:`sphinxhowto.cls` or in wrapper (defined differently in :file:`sphinxhowto.cls` and in
:file:`sphinxmanual.cls`) of standard ``\tableofcontents``. :file:`sphinxmanual.cls`) of standard ``\tableofcontents``. The macro
``\sphinxtableofcontentshook`` is executed during its expansion right before
``\tableofcontents`` itself.
.. versionchanged:: 1.5 .. versionchanged:: 1.5
formerly, the meaning of ``\tableofcontents`` was modified by Sphinx. formerly, the meaning of ``\tableofcontents`` was modified by Sphinx.
.. versionchanged:: 2.0
hard-coded redefinitions of ``\l@section`` and ``\l@subsection`` formerly
done during loading of ``'manual'`` docclass are now executed later via
``\sphinxtableofcontentshook``. This macro is also executed by the
``'howto'`` docclass, but defaults to empty with it.
- a custom ``\sphinxmaketitle`` is defined in the class files - a custom ``\sphinxmaketitle`` is defined in the class files
:file:`sphinxmanual.cls` and :file:`sphinxhowto.cls` and is used as :file:`sphinxmanual.cls` and :file:`sphinxhowto.cls` and is used as
default setting of ``'maketitle'`` :confval:`latex_elements` key. default setting of ``'maketitle'`` :confval:`latex_elements` key.

View File

@ -3,7 +3,7 @@
% %
\NeedsTeXFormat{LaTeX2e}[1995/12/01] \NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{sphinxhowto}[2018/12/22 v1.8.3 Document class (Sphinx howto)] \ProvidesClass{sphinxhowto}[2018/12/23 v2.0 Document class (Sphinx howto)]
% 'oneside' option overriding the 'twoside' default % 'oneside' option overriding the 'twoside' default
\newif\if@oneside \newif\if@oneside
@ -57,15 +57,16 @@
%\gdef\@thanks{}\gdef\@author{}\gdef\@title{} %\gdef\@thanks{}\gdef\@author{}\gdef\@title{}
} }
\newcommand{\sphinxtableofcontents}{ \newcommand{\sphinxtableofcontents}{%
\begingroup \begingroup
\parskip = 0mm \parskip \z@skip
\sphinxtableofcontentshook
\tableofcontents \tableofcontents
\endgroup \endgroup
\rule{\textwidth}{1pt} \noindent\rule{\textwidth}{1pt}\par
\vspace{12pt} \vspace{12pt}%
} }
\newcommand\sphinxtableofcontentshook{}
\pagenumbering{arabic} \pagenumbering{arabic}
% Fix the bibliography environment to add an entry to the Table of % Fix the bibliography environment to add an entry to the Table of

View File

@ -3,7 +3,7 @@
% %
\NeedsTeXFormat{LaTeX2e}[1995/12/01] \NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{sphinxmanual}[2018/12/22 v1.8.3 Document class (Sphinx manual)] \ProvidesClass{sphinxmanual}[2018/12/23 v2.0 Document class (Sphinx manual)]
% chapters starting at odd pages (overridden by 'openany' document option) % chapters starting at odd pages (overridden by 'openany' document option)
\PassOptionsToClass{openright}{\sphinxdocclass} \PassOptionsToClass{openright}{\sphinxdocclass}
@ -79,6 +79,7 @@
\pagenumbering{roman}% \pagenumbering{roman}%
\begingroup \begingroup
\parskip \z@skip \parskip \z@skip
\sphinxtableofcontentshook
\tableofcontents \tableofcontents
\endgroup \endgroup
% before resetting page counter, let's do the right thing. % before resetting page counter, let's do the right thing.
@ -89,8 +90,10 @@
% This is needed to get the width of the section # area wide enough in the % This is needed to get the width of the section # area wide enough in the
% library reference. Doing it here keeps it the same for all the manuals. % library reference. Doing it here keeps it the same for all the manuals.
% %
\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{2.6em}} \newcommand{\sphinxtableofcontentshook}{%
\renewcommand*\l@subsection{\@dottedtocline{2}{4.1em}{3.5em}} \renewcommand*\l@section{\@dottedtocline{1}{1.5em}{2.6em}}%
\renewcommand*\l@subsection{\@dottedtocline{2}{4.1em}{3.5em}}%
}
% Fix the bibliography environment to add an entry to the Table of % Fix the bibliography environment to add an entry to the Table of
% Contents. % Contents.