Debian Codegraph @

docs/user_guide/theme-elements.md

raw ◀ ▶
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
161 ## Admonition sidebars
162
163 ```{admonition} A sidebar admonition!
164 :class: sidebar note
165 I was made with the `{admonition}` directive and a `sidebar` class.
166 ```
167
168 ```{sidebar} Sidebar title
169 I was made with the `{sidebar}` directive.
170 ```
171
172 This theme supports a shorthand way of making **admonitions behave like sidebars**.
173 This can be a helpful way of highlighting content without interrupting the vertical flow as much.
174
175 For example, on the right are an "admonition sidebar" and a traditional Sphinx sidebar.
176
177 To make an admonition behave like a sidebar, add the `sidebar` class to its list of classes.
178 The admonition sidebar in this section was created with the following Markdown:
179
180 ``````{tab-set}
181 `````{tab-item} rST
182 ````rst
183 .. admonition:: A sidebar admonition!
184 :class: sidebar note
185
186 Some sidebar content.
187 ````
188 `````
189 `````{tab-item} Markdown
190 ````md
191 ```{admonition} A sidebar admonition!
192 :class: sidebar note
193 Some sidebar content.
194 ```
195 ````
196 `````
197 ``````
198
199 ## Footnotes
200
201 Here's a numeric footnote[^1], another one (preceded by a space) [^2], a named footnote[^named], and a symbolic one[^*].
202 All will end up as numbers in the rendered HTML, but in the source they look like `[^1]`, `[^2]`, `[^named]` and `[^*]`.
203
204 [^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.
205
206 [^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.
207
208 [^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.
209
210 [^*]: 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.
211
212 ## Link shortening for git repository services
213
214 Many projects have links back to their issues / PRs hosted on platforms like **GitHub** or **GitLab**.
215 Instead of displaying these as raw links, this theme does some lightweight formatting for these platforms specifically.
216
217 In **reStructuredText**, URLs are automatically converted to links, so this works automatically.
218
219 In **MyST Markdown**, by default, you must define a standard Markdown link and duplicate the URL in the link text.
220 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).
221
222 Link shortening is enabled by default. To disable it, set the following option in your `conf.py`:
223
224 ```python
225 html_theme_options = {
226 "shorten_urls": False,
227 }
228 ```
229
230 For example:
231
232 - **reStructuredText**
233 - `https://github.com/pydata/pydata-sphinx-theme/pull/1012`
234 - https://github.com/pydata/pydata-sphinx-theme/pull/1012
235
236 - **MyST Markdown (default)**
237 - `[https://github.com/pydata/pydata-sphinx-theme/pull/1012](https://github.com/pydata/pydata-sphinx-theme/pull/1012)`
238 - [https://github.com/pydata/pydata-sphinx-theme/pull/1012](https://github.com/pydata/pydata-sphinx-theme/pull/1012)
239
240 - **MyST Markdown with [MyST Linkify](https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#linkify)**
241 - `https://github.com/pydata/pydata-sphinx-theme/pull/1012`
242 - https://github.com/pydata/pydata-sphinx-theme/pull/1012
243
244 There are a variety of link targets supported, here's a table for reference:
245
246 **GitHub**
247
248 - `https://github.com`: https://github.com
249 - `https://github.com/pydata`: https://github.com/pydata
250 - `https://github.com/pydata/pydata-sphinx-theme`: https://github.com/pydata/pydata-sphinx-theme
251 - `https://github.com/pydata/pydata-sphinx-theme/pull/1012`: https://github.com/pydata/pydata-sphinx-theme/pull/1012
252 - `https://github.com/orgs/pydata/projects/2`: https://github.com/orgs/pydata/projects/2
253
254 **GitLab**
255
256 - `https://gitlab.com`: https://gitlab.com
257 - `https://gitlab.com/gitlab-org`: https://gitlab.com/gitlab-org
258 - `https://gitlab.com/gitlab-org/gitlab`: https://gitlab.com/gitlab-org/gitlab
259 - `https://gitlab.com/gitlab-org/gitlab/-/issues/375583`: https://gitlab.com/gitlab-org/gitlab/-/issues/375583
260
261 Links provided with a text body won't be changed.