I have an org-mode file with more than 12000 footnotes (maybe less), I was cleaning it and found that after the conversion some footnotes weren't converted to org-mode footnotes, so I had to manually make them footnotes.

The thing is, since that addition the reference number inside the square brackets must be re-done otherwise I will end with repeated numbers, like: [12] ... [12] or [10678] ... [10678]. Is there a way to build a regexp that look for all numbers inside square brackets and replace the text inside them with their respective coincidence number (?) for instance: [12] is the coincidence number 10 and this other [12] is coincidence number 11 so [12] ... [12] becomes [10] ... [11]?

especial petition: if you are going to post an elisp snippet that solves this problem, please, please, please, comment it on detail because I want to learn elisp too!

  • They are references, so must we expect that the number references to somewhere? I.e. in your situation, there are 4 occurrences of [12], two of them (reference + footnote) should be renamed [10] and the other two should be renamed [11]? That makes the question much more difficult than the way it is currently phrased!
    – T. Verron
    Commented Dec 4, 2014 at 7:45
  • 1
    How many of your references are duplicates? If not too many, I'd suggest de-duplicating them by hand, using a different namespace (e.g. [12-2]) to avoid the numbering issue.
    – T. Verron
    Commented Dec 4, 2014 at 7:46
  • 3
    Using the [fn:name] syntax rather than hand numbering is a better long term solution. Commented Dec 4, 2014 at 7:47
  • The references will be worked on separate files to make things easy. They aren't many, though I'm worried about how will [12-2] looks after exporting the document ...
    – shackra
    Commented Dec 4, 2014 at 7:56
  • 1
    Also, if you drop your requirement about learning Elisp, you can probably employ keyboard macros together with the keyboard macro counter (if that is what it's called, see the manual) and `C-u C-s' within a macro.
    – mbork
    Commented Dec 4, 2014 at 18:13

1 Answer 1


To re-number all footnotes starting from 1 you can use M-x query-replace-regexp (or, if you're feeling confident, just M-x replace-regexp) and type in

\[[0-9]+\] as the regexp to replace and

[\,(1+ \#)] as the replacement.

Here \# is the match count starting from zero, so I used \, and a lisp form which adds one to it.

To get (most of) this information, press C-h f replace-regexp and hit RETURN.

  • Wow! This works perfectly! Is just a matter of separating the footnotes and putting it on a different file before using replace-regexp!
    – shackra
    Commented Dec 4, 2014 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.