Rinohtype: How to force chapter numbering to start from 0?

Created on 1 May 2020  路  4Comments  路  Source: brechtm/rinohtype

For html on sphinx, using the following snippet works, but rinohtype seems to ignore it

.. sectnum::
   :start: 0
   :suffix: .

The version of sphinx and rinohtype are:

rinoh-typeface-dejavuserif==0.1.1
rinoh-typeface-texgyrecursor==0.1.1
rinoh-typeface-texgyreheros==0.1.1
rinoh-typeface-texgyrepagella==0.1.1
rinohtype==0.4.0
Sphinx==2.4.4

question

All 4 comments

Yes, rinohtype ignores this since it implements it's own numbering logic which can be customized using a style sheet (prefix, suffix, separator, number style). Setting a start index is currently not supported, however.

I'm interested to learn why you want to start numbering at zero. Perhaps a solution is to suppress numbering for the first chapter? You can suppress numbering for certain sections/chapters by setting _number_format_ to 麓None`. In case you don't know how to do this, I can try to show you if you can share your Sphinx project.

If you feel up to it, you're welcome to have a shot at implementing support for this. I would suggest adding a _start_number_ style property to the _NumberStyle_ class and go from there. Note that this should also work for other elements with a style class that inherits from NumberStyle.

Thanks @brechtm, that is an amazing rersponse time, really! Suppressing numbering for the first chapter would certainly do the trick. The use was that the first version of a document was released and now for the second release we need to add a new chapter, but we don't want to change the numbering for the existing chapters. Suppressing or starting from 0 would solve that

The project didn't go public yet, so I cant just send you the document just yet, but the example below shows my scenario. "What is new in V2" was added by I dont want that chapter to be numbered!

conf.py

import os
import sys
sys.path.insert(0, os.path.abspath('../myproject'))

project = 'My project v2'
copyright = '2020, Me'
author = 'Me'

release = 'Design Version 2'

extensions = [ "sphinx.ext.intersphinx", "rinoh.frontend.sphinx", "sphinx.ext.autodoc", 'sphinx.ext.napoleon' ]
templates_path = ['_templates']
exclude_patterns = []

def setup(app):
    app.add_stylesheet('custom.css')

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']

rinoh_documents = [('index',                                  # top-level file (index.rst)
                    'myproject',                              # output (.pdf)
                    'My Functional and Design specification', # document title
                    'Me')]                                    # document author
# Remove empty pages
latex_elements = {
  'extraclassoptions': 'openany,oneside'
}
autoclass_content = 'both'

index.rst

.. toctree::
   :caption: Contents:

   content

contents.rst

.. sectnum::
   :start: 0
   :suffix: .

This document aims to describe a high level API...

What is new in V2
=================

#. News 1
#. News 2
#. News 3
#. News 4

Functional spec
===============

Use cases
---------

foo

Design spec
===========

foo

Add the following to conf.py:

rinoh_stylesheet = 'unnumbered.rts'

Create unnumbered.rts:

[STYLESHEET]
name = unnumbered
base = sphinx

[unnumbered chapter : Section(has_class='unnumbered') / Heading(level=1)]
base = chapter
number_format = none

Change contents.rst:


.. rst-class:: unnumbered

What is new in V2
=================

#. News 1
#. News 2
#. News 3
#. News 4

Functional spec
===============

Use cases
---------

foo

Design spec
===========

foo

This sets the class _unnumbered_ on the first level-1 section (chapter) so that the selector in the stylesheet can single it out to set the _number_format_ to _none_.

Worked like a charm! THANK YOU!

Was this page helpful?
0 / 5 - 0 ratings