[Top][All Lists]

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

Fwd: Re: how to renumber footnotes?

From: Joost Kremers
Subject: Fwd: Re: how to renumber footnotes?
Date: Sat, 18 Apr 2020 09:14:26 +0200
User-agent: mu4e 1.3.10; emacs 27.0.90

Accidentally sent this message off-list. Trying again:

On Fri, Apr 17 2020, Sharon Kimble wrote:
org-footnote can't tell that footnote 1 ([fn:1]) at the beginning is in the right place when confronted with footnote 1 ([fn:1]) half-way

No, obviously, so you'll have to renumber the footnotes in the second file
before you merge the two files.

Which is why I'm looking for some other solution, and I believe
that it might be able to be achieved programmatically. Unfortunately my lisp skills are almost nil, hence my request for someone to help.

I use the following function for renumbering stuff such as footnotes:

#+begin_src emacs-lisp
(defun jk-renumber-counters (start regexp)
"Renumber counters.
Renumbering starts at START.  REGEXP describes the counters to be
renumbered.  The actual number must be enclosed in a group."
  (goto-char (point-min))
;; because we incf the counter before using it, we need to adjust:
  (let ((counter (1- start))
        (counters (make-hash-table :test 'equal))
    (while (re-search-forward regexp nil t)
      (setq fn (match-string 1))
      (replace-match (or (gethash fn counters)
                         (puthash fn (format "%s" (cl-incf
                         counter)) counters))
                     nil nil nil 1)))))

In your case, you should be able to call this function with:

  M-: (jk-renumber-footnotes 355 "\\[fn:\\([0-9]+\\)\\]") RET

Change «355» to the number you want to start the footnotes in the second file

If you already merged the two files and don't want to separate them again, you could take out the line `(goto-char (point-min))`, put point at the position where you want to start renumbering footnotes and then call the function. But I'd play it safe and renumber the footnotes before merging the files.


Joost Kremers
Life has its moments

reply via email to

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