Login  Register

Re: Section numbering with Roman Numerals

Posted by mojavelinux on Jun 09, 2019; 11:56pm
URL: https://discuss.asciidoctor.org/Section-numbering-with-Roman-Numerals-tp6948p6949.html

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

You can find a similar type of extension in the lab: https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/sectnumoffset-treeprocessor.rb

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