Skip to content

Commit 23c1afc

Browse files
committed
Nearly there with the docs.
1 parent 674c453 commit 23c1afc

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

doc-source/index.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ Highlights
178178

179179
.. start links
180180
181-
View the :ref:`Function Index <genindex>` or browse the `Source Code <_modules/index.html>`__.
181+
.. only:: html
182+
183+
View the :ref:`Function Index <genindex>` or browse the `Source Code <_modules/index.html>`__.
182184

183-
`Browse the GitHub Repository <https://github.com/domdfcoding/domdf_python_tools>`__
185+
`Browse the GitHub Repository <https://github.com/domdfcoding/domdf_python_tools>`__
184186

185187
.. end links

doc-source/latex_toctree_sections.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
11
# stdlib
2-
from typing import Any, Dict, List
2+
from typing import Any, Dict, List, Tuple
33

44
# 3rd party
55
import sphinx.directives.other
66
from docutils import nodes
77
from sphinx.application import Sphinx
8+
from sphinx.domains import IndexEntry
9+
from sphinx.writers.latex import LaTeXTranslator
810

911
__all__ = ["TocTreePlusDirective", "setup"]
1012

1113

14+
def generate_indices(translator) -> str:
15+
def generate(content: List[Tuple[str, List[IndexEntry]]], collapsed: bool) -> None:
16+
ret.append("\\bookmarksetupnext{{level=part}}\n")
17+
ret.append('\\begin{sphinxtheindex}\n')
18+
ret.append('\\let\\bigletter\\sphinxstyleindexlettergroup\n')
19+
for i, (letter, entries) in enumerate(content):
20+
if i > 0:
21+
ret.append('\\indexspace\n')
22+
ret.append('\\bigletter{%s}\n' % translator.escape(letter))
23+
for entry in entries:
24+
if not entry[3]:
25+
continue
26+
ret.append('\\item\\relax\\sphinxstyleindexentry{%s}' %
27+
translator.encode(entry[0]))
28+
if entry[4]:
29+
# add "extra" info
30+
ret.append('\\sphinxstyleindexextra{%s}' % translator.encode(entry[4]))
31+
ret.append('\\sphinxstyleindexpageref{%s:%s}\n' %
32+
(entry[2], translator.idescape(entry[3])))
33+
ret.append('\\end{sphinxtheindex}\n')
34+
35+
ret = []
36+
# latex_domain_indices can be False/True or a list of index names
37+
indices_config = translator.builder.config.latex_domain_indices
38+
if indices_config:
39+
for domain in translator.builder.env.domains.values():
40+
for indexcls in domain.indices:
41+
indexname = '%s-%s' % (domain.name, indexcls.name)
42+
if isinstance(indices_config, list):
43+
if indexname not in indices_config:
44+
continue
45+
content, collapsed = indexcls(domain).generate(
46+
translator.builder.docnames)
47+
if not content:
48+
continue
49+
ret.append('\\renewcommand{\\indexname}{%s}\n' %
50+
indexcls.localname)
51+
generate(content, collapsed)
52+
53+
return ''.join(ret)
54+
1255
# TODO: The first section in a part has all sub sections nested under it in the sidebar,
1356
# The numbering is correct, and its correct in the contents
1457

@@ -42,6 +85,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
4285
"""
4386

4487
app.add_directive("toctree", TocTreePlusDirective, override=True)
88+
LaTeXTranslator.generate_indices = generate_indices
4589

4690
return {
4791
"parallel_read_safe": True,

0 commit comments

Comments
 (0)