Debian Codegraph @

docs/user_guide/theme-elements.md

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # Theme-specific elements
2
3 There are a few elements that are unique or particularly important to this theme.
4 Some of these are triggered with configuration or Markdown syntax that is unique to the theme, and we cover them below.
5
6 ## Mathematics
7
8 Most Sphinx sites support math, but it is particularly important for scientific computing, so we illustrate support here as well.
9
10 Here is an inline equation: {math}`X_{0:5} = (X_0, X_1, X_2, X_3, X_4)` and {math}`another` and {math}`x^2 x^3 x^4` another. And here's one to test vertical height {math}`\frac{\partial^2 f}{\partial \phi^2}`.
11 Here is a block-level equation:
12
13 ```{math}
14 :label: My label
15
16 \nabla^2 f =
17 \frac{1}{r^2} \frac{\partial}{\partial r}
18 \left( r^2 \frac{\partial f}{\partial r} \right) +
19 \frac{1}{r^2 \sin \theta} \frac{\partial f}{\partial \theta}
20 \left( \sin \theta \, \frac{\partial f}{\partial \theta} \right) +
21 \frac{1}{r^2 \sin^2\theta} \frac{\partial^2 f}{\partial \phi^2}
22 ```
23
24 And here is a really long equation with a label!
25
26 ```{math}
27 :label: My label 2
28
29 \nabla^2 f =
30 \frac{1}{r^2} \frac{\partial}{\partial r}
31 \left( r^2 \frac{\partial f}{\partial r} \right) +
32 \frac{1}{r^2 \sin \theta} \frac{\partial f}{\partial \theta}
33 \left( \sin \theta \, \frac{\partial f}{\partial \theta} \right) +
34 \frac{1}{r^2 \sin^2\theta} \frac{\partial^2 f}{\partial \phi^2}
35 \nabla^2 f =
36 \frac{1}{r^2} \frac{\partial}{\partial r}
37 \left( r^2 \frac{\partial f}{\partial r} \right) +
38 \frac{1}{r^2 \sin \theta} \frac{\partial f}{\partial \theta}
39 \left( \sin \theta \, \frac{\partial f}{\partial \theta} \right) +
40 \frac{1}{r^2 \sin^2\theta} \frac{\partial^2 f}{\partial \phi^2}
41 ```
42
43 You can add a link to equations like the one above {eq}`My label` and {eq}`My label 2`.
44
45 ## Code blocks
46
47 Code block styling is inspired by [GitHub's code block style](https://primer.style/product/getting-started/rails/components/markdown/) and also has support for Code Block captions/titles.
48 See [the Sphinx documentation on code blocks](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-code-block) for more information.
49
50 ```python
51 print("A regular code block")
52 print("A regular code block")
53 print("A regular code block")
54 ```
55
56 You can also provide captions with code blocks, which will be displayed right above the code.
57 For example, the following code:
58
59 ``````{tab-set}
60 `````{tab-item} rST
61 ````rst
62 .. code-block:: python
63 :caption: `python.py`
64
65 print("A code block with a caption.")
66 ````
67 `````
68 `````{tab-item} Markdown
69 ````md
70 ```{code-block} python
71 :caption: `python.py`
72
73 print("A code block with a caption.")
74 ```
75 ````
76 `````
77 ``````
78
79 results in:
80
81 ```{code-block} python
82 :caption: `python.py`
83
84 print("A code block with a caption.")
85 ```
86
87 You can also display line numbers.
88 For example, the following code:
89
90 ``````{tab-set}
91 `````{tab-item} rST
92 ````rst
93 .. code-block:: python
94 :caption: `python.py`
95 :linenos:
96
97 print("A code block with a caption and line numbers.")
98 print("A code block with a caption and line numbers.")
99 print("A code block with a caption and line numbers.")
100 ````
101 `````
102 `````{tab-item} Markdown
103 ````md
104 ```{code-block} python
105 :caption: `python.py`
106 :linenos:
107
108 print("A code block with a caption and line numbers.")
109 print("A code block with a caption and line numbers.")
110 print("A code block with a caption and line numbers.")
111 ```
112 ````
113 `````
114 ``````
115
116 results in:
117
118 ```{code-block} python
119 :caption: `python.py`
120 :linenos:
121
122 print("A code block with a caption and line numbers.")
123 print("A code block with a caption and line numbers.")
124 print("A code block with a caption and line numbers.")
125 ```
126
127 ## Inline code
128
129 When used directly, the `code` role just displays the text without syntax highlighting, as a literal. As mentioned in the [Sphinx documentation](https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#inline-code-highlighting) you can also enable syntax highlighting by defining a custom role. It will then use the same highlighter as in the `code-block` directive.
130
131 ``````{tab-set}
132 `````{tab-item} rst
133 ````rst
134 .. role:: python(code)
135 :language: python
136
137 In Python you can :python:`import sphinx`.
138 ````
139 `````
140 `````{tab-item} markdown
141 ````md
142 ```{role} python(code)
143 :language: python
144 ```
145
146 In Python you can {python}`import sphinx`.
147 ````
148 `````
149 ``````
150
151 ```{role} python(code)
152 :language: python
153 ```
154
155 In Python you can {python}`import sphinx`.
156
157 ## Code execution
158
159 This theme has support for Jupyter execution libraries so that you can programmatically update your documentation with each build.
160 For examples, see [](../examples/pydata.ipynb).
161
162 ## Admonition sidebars
163
164 ```{admonition} A sidebar admonition!
165 :class: sidebar note
166 I was made with the `{admonition}` directive and a `sidebar` class.
167 ```
168
169 ```{sidebar} Sidebar title
170 I was made with the `{sidebar}` directive.
171 ```
172
173 This theme supports a shorthand way of making **admonitions behave like sidebars**.
174 This can be a helpful way of highlighting content without interrupting the vertical flow as much.
175
176 For example, on the right are an "admonition sidebar" and a traditional Sphinx sidebar.
177
178 To make an admonition behave like a sidebar, add the `sidebar` class to its list of classes.
179 The admonition sidebar in this section was created with the following Markdown:
180
181 ``````{tab-set}
182 `````{tab-item} rST
183 ````rst
184 .. admonition:: A sidebar admonition!
185 :class: sidebar note
186
187 Some sidebar content.
188 ````
189 `````
190 `````{tab-item} Markdown
191 ````md
192 ```{admonition} A sidebar admonition!
193 :class: sidebar note
194 Some sidebar content.
195 ```
196 ````
197 `````
198 ``````
199
200 ## Footnotes
201
202 Here's a numeric footnote[^1], another one (preceded by a space) [^2], a named footnote[^named], and a symbolic one[^*].
203 All will end up as numbers in the rendered HTML, but in the source they look like `[^1]`, `[^2]`, `[^named]` and `[^*]`.
204
205 [^1]: Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar.
206
207 [^2]: Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar.
208
209 [^named]: Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar.
210
211 [^*]: Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar.
212
213 ## Link shortening for git repository services
214
215 Many projects have links back to their issues / PRs hosted on platforms like **GitHub** or **GitLab**.
216 Instead of displaying these as raw links, this theme does some lightweight formatting for these platforms specifically.
217
218 In **reStructuredText**, URLs are automatically converted to links, so this works automatically.
219
220 In **MyST Markdown**, by default, you must define a standard Markdown link and duplicate the URL in the link text.
221 You may skip the need to manually define the link text by [activating the MyST Linkify extension](https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#linkify).
222
223 Link shortening is enabled by default. To disable it, set the following option in your `conf.py`:
224
225 ```python
226 html_theme_options = {
227 "shorten_urls": False,
228 }
229 ```
230
231 For example:
232
233 - **reStructuredText**
234 - `https://github.com/pydata/pydata-sphinx-theme/pull/1012`
235 - https://github.com/pydata/pydata-sphinx-theme/pull/1012
236
237 - **MyST Markdown (default)**
238 - `[https://github.com/pydata/pydata-sphinx-theme/pull/1012](https://github.com/pydata/pydata-sphinx-theme/pull/1012)`
239 - [https://github.com/pydata/pydata-sphinx-theme/pull/1012](https://github.com/pydata/pydata-sphinx-theme/pull/1012)
240
241 - **MyST Markdown with [MyST Linkify](https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#linkify)**
242 - `https://github.com/pydata/pydata-sphinx-theme/pull/1012`
243 - https://github.com/pydata/pydata-sphinx-theme/pull/1012
244
245 There are a variety of link targets supported, here's a table for reference:
246
247 **GitHub**
248
249 - `https://github.com`: https://github.com
250 - `https://github.com/pydata`: https://github.com/pydata
251 - `https://github.com/pydata/pydata-sphinx-theme`: https://github.com/pydata/pydata-sphinx-theme
252 - `https://github.com/pydata/pydata-sphinx-theme/pull/1012`: https://github.com/pydata/pydata-sphinx-theme/pull/1012
253 - `https://github.com/orgs/pydata/projects/2`: https://github.com/orgs/pydata/projects/2
254
255 **GitLab**
256
257 - `https://gitlab.com`: https://gitlab.com
258 - `https://gitlab.com/gitlab-org`: https://gitlab.com/gitlab-org
259 - `https://gitlab.com/gitlab-org/gitlab`: https://gitlab.com/gitlab-org/gitlab
260 - `https://gitlab.com/gitlab-org/gitlab/-/issues/375583`: https://gitlab.com/gitlab-org/gitlab/-/issues/375583
261
262 Links provided with a text body won't be changed.