From: Joost Kremers <joostkremers@fastmail.fm>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: Fwd: Re: how to renumber footnotes?
Date: Sat, 18 Apr 2020 09:14:26 +0200 [thread overview]
Message-ID: <87imhxnu3x.fsf@fastmail.fm> (raw)
In-Reply-To: 87d086s8q3.fsf@fastmail.fm
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
> through!
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."
(save-excursion
(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))
fn)
(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)))))
#+end_src
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
with.
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.
HTH
--
Joost Kremers
Life has its moments
next parent reply other threads:[~2020-04-18 7:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87v9lyvk3z.fsf@skimble.plus.com>
[not found] ` <87mu7aycm5.fsf@ebih.ebihd>
[not found] ` <mailman.453.1587096748.3066.help-gnu-emacs@gnu.org>
[not found] ` <87a73aaar5.fsf@hillenius.net>
[not found] ` <87a73av34s.fsf@skimble.plus.com>
[not found] ` <87d086s8q3.fsf@fastmail.fm>
2020-04-18 7:14 ` Joost Kremers [this message]
2020-04-18 15:53 ` Fwd: Re: how to renumber footnotes? Kyle Meyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87imhxnu3x.fsf@fastmail.fm \
--to=joostkremers@fastmail.fm \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).