Index ¦ Archives ¦ RSS

My hack week at Collabora: (start of) padded numbering in Writer

Estimated read time: 3 minutes

As mentioned in a previous such report, a hack week is when we are allowed to hack on anything we want in LibreOffice for a few days at Collabora. I used this time to implement core support for padded numbering in Writer.

Motivation

Padded numbering is a style where you insert 0 characters in front of an otherwise normal (Arabic) numbering, making sure that the result always has at least N characters. Up to now, you had to number your content manually to have this effect, while Word supports this feature.

OOXML supports padding up to 2, 3, 4 and 5 characters. Padding up to 2 characters is the older feature, supported in DOC and RTF as well, so I focused on that piece.

Results so far

Here is how the current, the baseline and the reference rendering of padded numbering looks like:

https://lh3.googleusercontent.com/n-XvNw0xPkBK_u9eqVraa7meGxYPX8dpKtfmHkN54y60x5HvUhQBouGEnfLX3XjzQFDjG7oWhCGVvFLnINneGZwDIjB8FW1hgwYSEpWrt3kniLGeKNFAfpa_Y9NGHNadj50ecy3FVw=s300-p-k
Figure 1. numbering-padded2.docx, current
https://lh3.googleusercontent.com/BgSZhU4WNkwTvOejqbfaKSiEQUudnDCUeVaQ62xPETwzhP0-FUPsBZMrUrgwhfi3fSou3YIQ_Yb0tuDzJmeIxHk2LhOpS9ENvxwLCr3-aCn4rIS0e9vYOh2__cHAvP82-MUJzQS-Zg=s300-p-k
Figure 2. numbering-padded2.docx, baseline
https://lh3.googleusercontent.com/TXI-klcS5xzPUX0SaV_iqhweMcUX0aN1rc7rwwAbKdulmPYZ6wcYqcQTO94aHGZl_p4FuVSt_drCI1blKRHLupNjC6j08GjdppbkJ8o72xNmjpV_X2_LcPUgZmOfGBeUJRhDKptxqg=s300-p-k
Figure 3. numbering-padded2.docx, reference

You can see how 0 is inserted before 1..9, but not before 10.

How is this implemented?

If you would like to know a bit more about how this works, continue reading… :-)

Then I found that footnote numbering needs explicit handling, so added support for padding in that case as well:

Finally I had a little bit of remaining time, so I extended support for the recently added Chicago numbering:

Future work

Padding up to 3, 4 and 5 characters would be possible to do, but it’s DOCX-only, and uses a different markup, planned to be done later.

All this is available in master (towards LibreOffice 7.0), so you can grab a daily build and try it out right now. :-)

© Miklos Vajna. Built using Pelican. Theme by Giulio Fidente on github.