-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFE: Add mechanisms for customizing automatic section numbering #4133
Comments
I have an approach that "works for me", here. However, it only supports HTML builders for now, and on further consideration, is probably not the best approach. The "right" way to do this is possibly to have the user supply a Python function that turns the number tuple into a string, with some way to select different convertors or pass through an identifier (which the user specifies per |
Add a hook to allow users to set a custom function to format section numbers. Modify TOC parser and builders to invoke this. This provides a mechanism for users to change the formatting of automatic section numbers, for example, to use a different number style, different separator between numbers for different levels, and/or to insert additional text around the numbers. Implements sphinx-doc#4133.
@mwoehlke Suggestion: in your def number2letter(n):
l = ''
if (n > 26):
l = chr(64 + (n - 1) / 26)
l += chr(65 + (n - 1) % 26)
return l This gives A, B, C, etc for the first 26 chapters, followed by AA, AB, AC etc, up until ZZ for the 702nd chapter. |
@jessetan, what about numbers and/or letters in other languages? In my current approach, I abandoned trying to build in such cases, and instead I just invoke a user-supplied function. That way the user can implement whatever code they need. |
Yes, that is indeed much more flexible. |
...but in what combinations? The user-supplied function takes the stack of section numbers. How do I express that I want (That said, I could see having a 'number to letter' utility function, as per your previous comment, in Sphinx, that users could use in their supplied numbering function. I don't know that I'd bother with one for Roman numerals, though; the value vs. the one you get from |
I'm working on a document (more particularly, I'm [ab]using sphinx to write a novel) that has rather particular requirements for section names:
Right now, Sphinx only supports the last item. I would like to see automatic section numbering improved to support these features.
In particular, my TOC looks like:
As chapter numbers are subject to change, I would really prefer to use automatic numbering rather than hard-coding everything into the actual headings. I can almost get there with Sphinx's current features; what I am missing is the ability to add prefix text to the section numbers (needs to be per
toctree
directive), and ability to choose the number style (likewise). The latter in particular seems like it really ought to be added as a feature, since someone might want to use other numbering styles depending on their language.The text was updated successfully, but these errors were encountered: