Yue Yi <[email protected]> writes: >> > * lisp/ox-html.el (org-html-footnote-reference): Count references >> > instead of using `org-export-get-ordinal'. >> >> It is better to fix `org-export-get-ordinal' instead. > > Attached is v2, reworked as you suggested: the fix is now in > `org-export-get-ordinal' instead of ox-html.
Thanks! > From e658943029d50219e9af62e23d78ff49de33f101 Mon Sep 17 00:00:00 2001 > From: Yue Yi <[email protected]> > Date: Mon, 9 Nov 2026 06:16:54 +0800 > Subject: [PATCH] lisp/ox.el: Fix `org-export-get-ordinal' for repeated > footnote references Nit: Probably a good idea to put a link to this thread, or, alternatively add the examples of the bug you provided in the earlier message in the docstring itself: + Link: https://orgmode.org/list/caamasz05s9h0vzc51ch_ispch+zdzxzz28qs_h6wjmp96yz...@mail.gmail.com > Return value is a list of numbers if ELEMENT is a headline or an > item. It is nil for keywords. It represents the footnote number > -for footnote definitions and footnote references. If ELEMENT is > -a target, return the same value as if ELEMENT was the closest > -table, item or headline containing the target. In any other > -case, return the sequence number of ELEMENT among elements or > -objects of the same type." > +for footnote definitions and *inline* footnote references. For a > +regular footnote reference, it is the number of the reference > +among the references pointing to the same footnote, in reading > +order. If ELEMENT is a target, return the same value as > +if ELEMENT was the closest table, item or headline containing the > +target. In any other case, return the sequence number of ELEMENT > +among elements or objects of the same type." Nit: I think the wording can be improved. See the attached diff with my suggestions.
>From bc1855fa101377a7f2df78a5af2f2343448adfdd Mon Sep 17 00:00:00 2001 Message-ID: <bc1855fa101377a7f2df78a5af2f2343448adfdd.1795253852.git.yanta...@posteo.net> From: Ihor Radchenko <[email protected]> Date: Sat, 21 Nov 2026 10:37:28 +0100 Subject: [PATCH] wip --- lisp/ox.el | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index ff9416daa..ce13d51af 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -4895,15 +4895,15 @@ (defun org-export-get-ordinal (element info &optional types predicate) the plist used as a communication channel. This allows counting only a certain type of object (i.e. inline images). -Return value is a list of numbers if ELEMENT is a headline or an -item. It is nil for keywords. It represents the footnote number -for footnote definitions and *inline* footnote references. For a -regular footnote reference, it is the number of the reference -among the references pointing to the same footnote, in reading -order. If ELEMENT is a target, return the same value as -if ELEMENT was the closest table, item or headline containing the -target. In any other case, return the sequence number of ELEMENT -among elements or objects of the same type." +Return value is a list of numbers if ELEMENT is a headline or an item. +It is nil for keywords. It represents the footnote number for +footnote definitions and *inline* footnotes (inline footnote +references). For a non-inline footnote reference, return its sequence +number among the references pointing to the same footnote. If ELEMENT +is a target, return the same value as if ELEMENT was the closest +table, item or headline containing the target. In any other case, +return the sequence number of ELEMENT among elements or objects of the +same type." ;; Ordinal of a target object refer to the ordinal of the closest ;; table, item, or headline containing the object. (when (org-element-type-p element 'target) @@ -4925,11 +4925,14 @@ (defun org-export-get-ordinal (element info &optional types predicate) ;; reference returns the number of the footnote it refers to. (footnote-definition (org-export-get-footnote-number element info)) (footnote-reference + ;; Special case 4: An inline footnote reference. Behaves + ;; like another (inline) footnote definition. (if (eq (org-element-property :type element) 'inline) - (org-export-get-footnote-number element info) - ;; A regular footnote reference is identified by its rank among - ;; the references to the same footnote, in reading order, since - ;; the same footnote may be referenced more than once. + (org-export-get-footnote-number element info) + ;; Special case 5: Reference to fotnote definition. + ;; Return sequence number among the references pointing to the + ;; same footnote. The same footnote defintion may be referenced + ;; more than once. (let ((label (org-element-property :label element)) (count 0)) (catch 'exit -- 2.55.0
> + ;; A regular footnote reference is identified by its rank among > + ;; the references to the same footnote, in reading order, since > + ;; the same footnote may be referenced more than once. > + (let ((label (org-element-property :label element)) > + (count 0)) > + (catch 'exit > + (org-export--footnote-reference-map > + (lambda (ref) > + (when (and (equal label (org-element-property :label ref)) > + (or (not predicate) (funcall predicate ref info))) > + (cl-incf count) > + (when (eq ref element) (throw 'exit count)))) > + (plist-get info :parse-tree) info))))) Here, you are largely duplicating the code of `org-export-get-footnote-number', so it is a good idea to inline the change there instead. Another reason to change `org-export-get-footnote-number' is because it is directly used in ox-odt and oc-csl. Those users will likely hid the same bug with duplicate footnote reference numbers. So, changing `org-export-get-footnote-number' seems to be strictly better. + (or (not predicate) (funcall predicate ref info)) Here, I think we should ignore predicate, just as org-export-get-footnote-number does. Maybe this pitfall should also be mentioned in the docstring of `org-export-get-ordinal'. -- Ihor Radchenko // yantar92, Org mode maintainer, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92>
