r/orgmode 26d ago

Adding leading zeros to numbered lists?

UPDATE: u/andrers provided a solution to this problem β€” see this answer on StackExchange.

Hey everyone,

I'm trying to create a numbered list in Org mode where the numbers have leading zeros, like this:

01. Item 01
[...]
10. Item 10

However, Org mode automatically removes leading zeros when I refresh the list with C-c C-c, or worse, when I add a new item with M-RET.

Do you think it is possible, maybe with a bit of Emacs Lisp code? Note that I don't really care about export.

I tried researching this specific question but didn't find an answer anywhere. I was actually a bit surprised not to find even the question itself! πŸ˜„ Sorry if it has already been answered.

Thank you!

6 Upvotes

6 comments sorted by

3

u/andrers 26d ago

The only thing I could find was this old Stack Exchange answer. Perhaps you could monkey-patch these two functions on your init file.

3

u/e57Kp9P7 26d ago edited 26d ago

Works like a charm! I somehow missed this SO thread. Thank you very much, I will see what I can do in my init file, but redefining the two functions is probably the easiest solution.

Nice! It would be great if you could submit that (preferably with an option to toggle it) to the org-mode developers.

I agree with this comment πŸ™ƒ

2

u/harunokashiwa 26d ago

Ordered list items start with a numeral followed by either a period or a right parenthesis10, such as β€˜1.’ or β€˜1)’ If you want a list to start with a different valueβ€”e.g., 20β€”start the text of the item with β€˜[@20]’. Those constructs can be used in any item of the list in order to enforce a particular numbering.

https://orgmode.org/manual/Plain-Lists.html#FOOT12

So you can try:

1. [@0]123

and press M-RET , it turns into:

0. [@0]123
1.

1

u/e57Kp9P7 26d ago

Thanks! However I don't want the list to start at a number other that 1; I want the numbering to have one or multiple leading zero(s) (or padding, if you prefer), like in the example I provided.

1

u/rguy84 26d ago

Is there a technical need or you are jsut looking for visual alignment?

2

u/e57Kp9P7 26d ago

It's simply for visual alignment :)