Reputation: 177
I am writing a book using Sphinx Documentation and I have a special admonition
that is used quite often. But for better communicating with the other authors, I would like to have an automatic number in each of these special admonitions.
Say I input this:
Section
=======
.. admonition:: Observation
text
.. admonition:: Observation
text
I would like to get something like this for the HTML build:
<h2>Section</h2>
<div class="admonition-observation admonition">
<p class="first admonition-title">Observation 1</p>
<p>text</p>
<div class="admonition-observation admonition">
<p class="first admonition-title">Observation 2</p>
<p>text</p>
Or anything that gives me automatic numbering in the HTML source (and analogously for the latex source).
Upvotes: 0
Views: 320
Reputation: 740
One way to do this is to use an extension, like https://github.com/rhopfer/sphinx-numbered-blocks
Once installed, a conf.py
for your approach might look like this:
...
numbered_blocks = [
{'name': 'observation'},
]
...
Then, in your source, you'd write this:
.. observation::
This is an observation
Resulting in HTML:
<div class="numbered-block observation" id="observation-0">
<span class="title">
<span class="label">Observation 1.1</span><p>This is an observation</p></span>
</div>
(your exact output may differ slightly)
See https://git.io/vHQzJ for more configuration examples and how to modify the labels.
Upvotes: 1