|
1 | | -"""PDF/LaTeX styling for sphinx-tabs directives. |
| 1 | +"""PDF/LaTeX rendering for sphinx-tabs directives. |
2 | 2 |
|
3 | 3 | sphinx-tabs only registers HTML visitors for its custom node types. For all |
4 | 4 | other builders it falls back to plain ``nodes.container`` nodes, so the tab |
|
7 | 7 | This extension inserts a ``SphinxTransform`` (LaTeX/rinoh builds only) that |
8 | 8 | rewrites the generic container tree produced by sphinx-tabs into custom |
9 | 9 | ``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. |
11 | 12 |
|
12 | 13 | Expected result in PDF:: |
13 | 14 |
|
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 … |
27 | 26 | """ |
28 | 27 |
|
29 | 28 | import re |
@@ -106,34 +105,22 @@ def apply(self, **kwargs) -> None: |
106 | 105 | # --------------------------------------------------------------------------- |
107 | 106 |
|
108 | 107 |
|
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.""" |
114 | 110 |
|
115 | 111 |
|
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.""" |
121 | 114 |
|
122 | 115 |
|
123 | 116 | 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.""" |
125 | 118 | 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") |
130 | 120 |
|
131 | 121 |
|
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.""" |
137 | 124 |
|
138 | 125 |
|
139 | 126 | def _html_skip(translator, node) -> None: |
|
0 commit comments