Skip to content
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

Allow configuring the separator used in numbering equations #12523

Merged
merged 11 commits into from
Jul 10, 2024

Conversation

thfanning
Copy link
Contributor

Subject: Sphinx configuration: math_numsep

Feature or Bugfix

  • Feature

Purpose

  • Allow users to configure the final separator used when numbering math elements.

Detail

  • When numbering equations with math_numfig and numfig_secnum_depth > 0, section number are included in the equation number. For example, Eq. 1.2.3 is the third equation in section 1.2.
  • A new Sphinx configuration option math_numsep allows users to select a different separator between the section number and the equation number.
  • For example, math_numsep='-' will result in numbering such as Eq. 1.2-3.
  • This helps visually distinguish equation number 1.2-3 from section number 1.2.3.
  • Minimal code changes.
  • Test case included for HTML. LaTeX does its own numbering.

Relates

  • None

@AA-Turner
Copy link
Member

I'm hesistant about adding new configuration values. What is the value proposition here, is it a broader request?

A

@thfanning
Copy link
Contributor Author

I'm hesistant about adding new configuration values. What is the value proposition here, is it a broader request?

Understandable given the large number of existing configuration options. However, there are only 3 options for math (and math_number_all is of questionable utility). What we propose, math_numsep, has symmetry with math_numfig and only takes effect if numfig_secnum_depth is positive.

We maintain very technical code documentation that is thousands of pages long and contains over 4000 equations across 16 chapters. Our convention (for decades) is to use Chapter.Section-Equation. Although this is something that can readily be done in LaTeX, Sphinx is limited in equation number formatting in HTML (other than the math_eqref_format which has no bearing on numbering).

This feature would bring parity with LaTeX generation.

Thanks.

@AA-Turner AA-Turner changed the title User configurable: math_numsep Allow configuring the separator used in numbering equations Jul 9, 2024
sphinx/config.py Outdated
@@ -258,6 +258,7 @@ class Config:
'math_number_all': _Opt(False, 'env', ()),
'math_eqref_format': _Opt(None, 'env', frozenset((str,))),
'math_numfig': _Opt(True, 'env', ()),
'math_numsep': _Opt(None, 'env', frozenset((str,))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably makes sense to unconditionally use math_numsep, and have a sensible default. If a user sets math_numsep to None or '', perhaps issue a warning/error, or silently use '.'.

Suggested change
'math_numsep': _Opt(None, 'env', frozenset((str,))),
'math_numsep': _Opt('.', 'env', frozenset((str,))),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented the requested default separator, added to the CHANGES, and updated the documentation.

@AA-Turner
Copy link
Member

Please can you also add an entry to CHANGES and documentation in doc/usage/configuration?

A

@AA-Turner AA-Turner merged commit 6cc1177 into sphinx-doc:master Jul 10, 2024
23 checks passed
@AA-Turner
Copy link
Member

Thanks Thomas!

A

@AA-Turner AA-Turner added this to the 7.4.0 milestone Jul 13, 2024
@thfanning thfanning deleted the math_numsep branch July 18, 2024 14:39
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants