help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to renumber footnotes?


From: Andreas Röhler
Subject: Re: how to renumber footnotes?
Date: Fri, 17 Apr 2020 18:10:54 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:68.0) Gecko/20100101 Thunderbird/68.7.0


On 17.04.20 05:58, Sharon Kimble wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512


Please, can someone help me sort out an org-mode footnote problem?

I have 2 org-mode documents called 'file-a' and 'file-b', and both have
got several hundred footnotes starting with 1. I'm adding file-b on to
the end of file-a, and trying to renumber the footnotes, so that even if
file-a has 354 footnotes, and file-b has 421 footnotes, the whole file
renumbers the footnotes and continues on from 354 to 355, 356, 357, etc
and onwards.

But how can I do this please? The org-mode footnote program can't do it,
so how do I do it please?

(The footnote numbers I've shown are purely arbitrary, some files that
I'm wanting to do this with have up to 700 footnotes in their combined

Make sure there is only one footnote-section at the end of file and all fn appear in correct order:

(defun ar-org-footnote-renumber-intern ()
  (let ((c 0))
    (while (re-search-forward org-footnote-re nil t)
      (backward-char 2)
      (when (looking-at "[0-9]+")
    (replace-match (number-to-string (cl-incf c)))))))

(defun ar-org-footnote-renumber ()
  "Renumber footnotes."
  (interactive "*")
  (save-restriction
    (widen)
    (goto-char (point-min))
    (when (re-search-forward "^* Footnotes" nil t)
      ;; first renumber fns in text section, afterwards the
      ;; fn-definitions
      (save-restriction
    (narrow-to-region (point-min) (line-beginning-position))
    (goto-char (point-min))
    (ar-org-footnote-renumber-intern)
    (widen)
    (when (re-search-forward "^* Footnotes" nil t)
      (narrow-to-region (line-beginning-position) (point-max))
      (goto-char (point-min))
      (ar-org-footnote-renumber-intern))))))

HTH,

Andreas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]