* Sharon Kimble <[email protected]> [2025-07-20 16:14]:
> Hi folks.
>
> I've written a book and just created a new chapter by splitting one in half.
>
> They are numbered Chapter 1, Chapter 2, etc, and they're all level one
> headings.
>
> So how can I auto-renumber them please?
#+TITLE: My Book
#+OPTIONS: num:t
* Chapter 1
:PROPERTIES:
:CHAPTER: 1
:END:
This is my first chapter content...
* Chapter 2
:PROPERTIES:
:CHAPTER: 2
:END:
Second chapter content...
* Chapter 3
:PROPERTIES:
:CHAPTER: 3
:END:
Second chapter content...
* Chapter 3
:PROPERTIES:
:CHAPTER: 3
:END:
Second chapter content...
* Chapter 3
:PROPERTIES:
:CHAPTER: 3
:END:
Second chapter content...
* Chapter 4
:PROPERTIES:
:CHAPTER: 4
:END:
Third chapter content...
Put this function in your init file:
(defun org-update-chapter-numbers ()
"Update all chapter numbers sequentially in the current buffer."
(interactive)
(save-excursion
(goto-char (point-min))
(let ((counter 0))
(while (re-search-forward "^\* " nil t)
(when (= (org-current-level) 1)
(setq counter (1+ counter))
;; Update the property
(org-set-property "CHAPTER" (number-to-string counter))
;; Update the heading text
(org-edit-headline (format "Chapter %d" counter)))))))
Now you can do M-x org-update-chapter-numbers to update numbers of chapters.
--
Jean Louis