Skip to content

Commit cdaef12

Browse files
committed
Fix latex tabs in pdf
1 parent ade9f9d commit cdaef12

1 file changed

Lines changed: 22 additions & 35 deletions

File tree

doc/_ext/latex_tabs.py

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""PDF/LaTeX styling for sphinx-tabs directives.
1+
"""PDF/LaTeX rendering for sphinx-tabs directives.
22
33
sphinx-tabs only registers HTML visitors for its custom node types. For all
44
other builders it falls back to plain ``nodes.container`` nodes, so the tab
@@ -7,23 +7,22 @@
77
This extension inserts a ``SphinxTransform`` (LaTeX/rinoh builds only) that
88
rewrites the generic container tree produced by sphinx-tabs into custom
99
``LatexTabsGroup`` / ``LatexTabEntry`` nodes, and registers LaTeX visitors
10-
that emit a small coloured label box before each tab's content.
10+
that render each tab as an unnumbered subsection heading followed by its
11+
content.
1112
1213
Expected result in PDF::
1314
14-
┌──────────────────────────────┐
15-
│ [Git] ← coloured pill │
16-
│ content … │
17-
│ ────────────────────────── │
18-
│ [SVN] │
19-
│ content … │
20-
│ ────────────────────────── │
21-
│ [Archive] │
22-
│ content … │
23-
└──────────────────────────────┘
24-
25-
The styling uses the ``dfaccent`` and ``dfnearblack`` colours already defined
26-
in conf.py's LaTeX preamble.
15+
Linux
16+
─────
17+
content …
18+
19+
macOS
20+
─────
21+
content …
22+
23+
Windows
24+
───────
25+
content …
2726
"""
2827

2928
import re
@@ -106,34 +105,22 @@ def apply(self, **kwargs) -> None:
106105
# ---------------------------------------------------------------------------
107106

108107

109-
def visit_latex_tabs_group(translator, _node) -> None:
110-
"""Emit an opening rule before the tabs group."""
111-
translator.body.append(
112-
"\n\\vspace{4pt}\\noindent{\\color{dfaccent!40}\\rule{\\linewidth}{0.6pt}}\\vspace{-2pt}\n"
113-
)
108+
def visit_latex_tabs_group(_translator, _node) -> None:
109+
"""No-op: subsection headings on each entry provide all needed structure."""
114110

115111

116-
def depart_latex_tabs_group(translator, _node) -> None:
117-
"""Emit a closing rule after the tabs group."""
118-
translator.body.append(
119-
"\n{\\color{dfaccent!40}\\rule{\\linewidth}{0.6pt}}\\vspace{4pt}\n"
120-
)
112+
def depart_latex_tabs_group(_translator, _node) -> None:
113+
"""No-op: nothing to emit after the last tab entry."""
121114

122115

123116
def visit_latex_tab_entry(translator, node) -> None:
124-
"""Emit a coloured pill label before the tab content."""
117+
"""Emit an unnumbered subsubsection heading before the tab content."""
125118
label = _escape_latex(node["label"])
126-
translator.body.append(
127-
f"\n\\noindent\\colorbox{{dfaccent!15}}{{\\strut\\textbf{{\\small\\textcolor{{dfaccent}}{{{label}}}}}}}"
128-
f"\\par\\vspace{{2pt}}\n"
129-
)
119+
translator.body.append(f"\n\\subsubsection*{{{label}}}\n")
130120

131121

132-
def depart_latex_tab_entry(translator, _node) -> None:
133-
"""Emit a separator rule after the tab content."""
134-
translator.body.append(
135-
"\n\\vspace{2pt}\\noindent{\\color{dfaccent!25}\\rule{\\linewidth}{0.4pt}}\\vspace{-2pt}\n"
136-
)
122+
def depart_latex_tab_entry(_translator, _node) -> None:
123+
"""No-op: the next subsubsection heading provides the visual separation."""
137124

138125

139126
def _html_skip(translator, node) -> None:

0 commit comments

Comments
 (0)