Section numbering with Roman Numerals

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Section numbering with Roman Numerals

be.wood
I am trying to figure out how to number some sections with Roman Numerals (preferably lowercase, but in general). What I'm looking to do is have some early sections numbered like this:

i. Forward
ii. Glossary

and then move on to the normal section numbering

1. Introduction
2. stuff

And to have each one independently tracked (so the the Introduction wouldn't be 3 in this case, but would restart).

I can find how to add Appendices, but not how to do something like this (if it is possible).

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: Section numbering with Roman Numerals

mojavelinux
Administrator
This is not something that is supported out of the box. You can do it, but you need to manipulate the parsed document yourself. You can do so using a TreeProcessor.

What you are looking for is the `numeral` property on the section nodes. This property accepts a string, so you can set it to whatever you  want.

Here's an example:

Asciidoctor::Extensions.register do
  tree_processor do
    process do |doc|
      sections = doc.sections
      sections[0].numeral = 'i'
      sections[1].numeral = 'ii'
      (sections.slice 2, sections.length).each do |sect|
        sect.numeral = sect.numeral.to_i - 2
      end
      nil
    end
  end
end


Cheers,

-Dan

On Mon, Jun 3, 2019 at 2:57 PM be.wood [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I am trying to figure out how to number some sections with Roman Numerals (preferably lowercase, but in general). What I'm looking to do is have some early sections numbered like this:

i. Forward
ii. Glossary

and then move on to the normal section numbering

1. Introduction
2. stuff

And to have each one independently tracked (so the the Introduction wouldn't be 3 in this case, but would restart).

I can find how to add Appendices, but not how to do something like this (if it is possible).

Thank you


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Section-numbering-with-Roman-Numerals-tp6948.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux