Skip to content

Commit 9b2aac6

Browse files
committed
LaTeX: extend to all projects the sphinx-doc#3742 fix for PDF builds at RTD
Refs: readthedocs/readthedocs.org#2857
1 parent 1140e81 commit 9b2aac6

File tree

6 files changed

+43
-16
lines changed

6 files changed

+43
-16
lines changed

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ Features added
143143
for mathjax
144144
* #4362: latex: Don't overwrite .tex file if document not changed
145145
* #1431: latex: Add alphanumeric enumerated list support
146+
* Extend to all projects not using the Sphinx LaTeX Makefile a workaround for
147+
`issue rtfd/readthedocs.org#2857`__ about insufficient number of
148+
``pdflatex`` runs for index to show up in PDF bookmarks (refs: #3742)
149+
150+
__ https://github.com/rtfd/readthedocs.org/issues/2857
146151

147152
Bugs fixed
148153
----------

doc/conf.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@
6464
'passoptionstopackages': '\\PassOptionsToPackage{svgnames}{xcolor}',
6565
'preamble': '\\DeclareUnicodeCharacter{229E}{\\ensuremath{\\boxplus}}',
6666
'fvset': '\\fvset{fontsize=auto}',
67-
# fix missing index entry due to RTD doing only once pdflatex after makeindex
68-
'printindex': r'''
69-
\IfFileExists{\jobname.ind}
70-
{\footnotesize\raggedright\printindex}
71-
{\begin{sphinxtheindex}\end{sphinxtheindex}}
72-
''',
67+
'printindex': '\\footnotesize\\raggedright\\sphinxprintindex',
7368
}
7469
latex_show_urls = 'footnote'
7570

doc/latex.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ example::
5555
\setlength{\cftsecnumwidth}{1.25cm}
5656
''',
5757
'fncychap': r'\usepackage[Bjornstrup]{fncychap}',
58-
'printindex': r'\footnotesize\raggedright\printindex',
58+
'printindex': r'\footnotesize\raggedright\sphinxprintindex',
5959
}
6060
latex_show_urls = 'footnote'
6161

@@ -399,6 +399,21 @@ Macros
399399
:file:`sphinxmanual.cls` and :file:`sphinxhowto.cls`.
400400
- the citation reference is typeset via ``\sphinxcite`` which is a wrapper
401401
of standard ``\cite``.
402+
- regarding the general index, the :confval:`latex_elements` dictionary has a
403+
``'printindex'`` key which defaults to ``'\\sphinxprintindex'``. It often
404+
proves advantageous to use::
405+
406+
'printindex': '\\footnotesize\\raggedright\\sphinxprintindex',
407+
408+
especially if the index contains long entries. The LaTeX class for Japanese
409+
``'manual'``-type documents already does the font size and text
410+
justification change, so the above is not needed then.
411+
412+
.. tip::
413+
414+
Advanced LaTeX users can also, via :confval:`latex_additional_files`, use
415+
a custom :file:`python.ist` style file for :program:`makeindex` to modify
416+
the looks of the general index.
402417

403418
Environments
404419
~~~~~~~~~~~~
@@ -453,7 +468,8 @@ Environments
453468
- the bibliography uses ``sphinxthebibliography`` and the Python Module index
454469
as well as the general index both use ``sphinxtheindex``; these environments
455470
are wrappers of the ``thebibliography`` and respectively ``theindex``
456-
environments as provided by the document class (or packages).
471+
environments, needed mainly to insert a corresponding entry in the PDF
472+
bookmarks and table of contents.
457473

458474
.. versionchanged:: 1.5
459475
formerly, the original environments were modified by Sphinx.

doc/usage/configuration.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,8 +1727,8 @@ the `Dublin Core metadata <http://dublincore.org/>`_.
17271727
Options for LaTeX output
17281728
------------------------
17291729

1730-
These options influence LaTeX output. Refer to :doc:`/latex` for more
1731-
information.
1730+
These options influence LaTeX output. For customization of LaTeX
1731+
macros and environments, see also :doc:`/latex`.
17321732

17331733
.. confval:: latex_engine
17341734

@@ -2108,11 +2108,14 @@ information.
21082108
Remove unneeded ``{}`` after ``\\hrule``.
21092109

21102110
``'printindex'``
2111-
"printindex" call, the last thing in the file, default
2112-
``'\\printindex'``. Override if you want to generate the index
2113-
differently or append some content after the index. For example
2114-
``'\\footnotesize\\raggedright\\printindex'`` is advisable when the
2115-
index is full of long entries.
2111+
"printindex" call, the last thing in the file.
2112+
2113+
.. versionchanged:: 1.8
2114+
Former default ``'\\printindex'`` now ``'\\sphinxprintindex'``.
2115+
This macro works around an issue__ with PDF builds at RTD doing too
2116+
few ``pdflatex`` runs.
2117+
2118+
__ https://github.com/rtfd/readthedocs.org/issues/2857
21162119

21172120
``'fvset'``
21182121
Customization of ``fancyvrb`` LaTeX package. Defaults to

sphinx/texinputs/sphinx.sty

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,14 @@
459459
}
460460
\fi
461461

462+
% provide \sphinxprintindex as variant of \printindex designed to workaround
463+
% rtfd/readthedocs.org#2857 regarding "Index" entry in PDF bookmarks
464+
\newcommand*{\sphinxprintindex}{%
465+
\IfFileExists{\jobname.ind}
466+
{\printindex}
467+
{\begin{sphinxtheindex}\end{sphinxtheindex}}%
468+
}%
469+
462470
% make commands known to non-Sphinx document classes
463471
\providecommand*{\sphinxtableofcontents}{\tableofcontents}
464472
\ltx@ifundefined{sphinxthebibliography}

sphinx/writers/latex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
'maketitle': '\\maketitle',
125125
'tableofcontents': '\\sphinxtableofcontents',
126126
'atendofbody': '',
127-
'printindex': '\\printindex',
127+
'printindex': '\\sphinxprintindex',
128128
'transition': '\n\n\\bigskip\\hrule\\bigskip\n\n',
129129
'figure_align': 'htbp',
130130
'tocdepth': '',

0 commit comments

Comments
 (0)