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: Stephen Berman
Subject: Re: how to renumber footnotes?
Date: Fri, 17 Apr 2020 14:45:41 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

On Fri, 17 Apr 2020 14:10:33 +0200 Gijs Hillenius <gijs@hillenius.net> 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! 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.
>
> Ah!
>
> Suppose file A has 372 footnotes, and B has another x. I would create a
> macro that I start just ahead of the second [fn:1], and that adds 372 to
> [fn:1] so it becomes [fn:373] and repeat that to x.
>
> It might take you a few tries, but something like put point at the
> second [fn:1] c-X ( to start recording the macro, search for [fn: copy
> the 1 (+ "yank" 273) paste (<-- I'm missing a step here, I bet), and
> then end the macro-recording with C-x ).

You could also use query-replace-regexp (`C-M-%') with a Lisp expression
in the replacement.  E.g., if this is the result of appending file-b to
file-a, with point at the position indicated with `^':

----------------------------------------------------------------------
This is a test.[fn:1]  This is a test.[fn:2]  This is a test.[fn:3]

* Footnotes

[fn:3] Note 3a 

[fn:2] Note 2a 

[fn:1] Note 1a 

This is a test.[fn:1]  This is a test.[fn:2]  This is a test.[fn:3]
^
* Footnotes

[fn:3] Note 3b 

[fn:2] Note 2b 

[fn:1] Note 1b 
----------------------------------------------------------------------

then type C-M-% and at the prompt enter this for the search string:

\(\[fn:\)\([0-9]+\)\(\]\)

then RET, then at the next prompt enter this for the replacement string:

\1\,(+ \#2 3)\3

then RET and then `!' to make all replacements without confirmation.
The result is this:

----------------------------------------------------------------------
This is a test.[fn:1] This is a test.[fn:2] This is a test.[fn:3]

* Footnotes

[fn:3] Note 3a 

[fn:2] Note 2a 

[fn:1] Note 1a 

This is a test.[fn:4]  This is a test.[fn:5]  This is a test.[fn:6]

* Footnotes

[fn:6] Note 3b 

[fn:5] Note 2b 

[fn:4] Note 1b 
----------------------------------------------------------------------

(In the replacement string you should replace `3' in `(+ \#2 3)' with
the last footnote number of file-a.)

Steve Berman



reply via email to

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