Rasmus <ras...@gmx.us> writes: > The attached patch fixes this by explicitly saving the footnote section
As per usual my first patch is dodgy. It occurred to me that Org can handle several footnote sections (that's how #+INCLUDE supports footnotes, I guess). The attached patch how supports export of t2.org in this example $> cat t{1,2}.org # this is t1.org * foo bar[fn:1] baz[fn:2] * Footnotes [fn:1] bar.corp * Footnotes [fn:2] baz.corp # this is t2.org #+INCLUDE: "/tmp/t1.org::*foo" However, there is a pitch-fall when doing #+INCLUDE: "/tmp/t1.org::*foo0" #+INCLUDE: "/tmp/t1.org::*foo1" Now *foo1 will be inserted under the footnote-heading of *foo0 which means it won't be exported. If min-level is used this is not an issue of course, but that's kind of unexpected (so is the fact that the second include will become a child of the first include, but that's another patch) . Perhaps a better overall approach (if the above limitation is unacceptable) would to translate all footnotes in an INCLUDEd file to inline ones, e.g. when including * foo in t1.org above, what would be inserted is * foo bar[fn::bar.corp] baz[fn::baz.corp] Yet another solution would be to return a cond of (included-text . included-footnotes) and make sure to insert footnotes at the very end. WDYT? —Rasmus -- . . . The proofs are technical in nature and provides no real understanding
>From 2a943b40c024df092cc2cf020bdf2646e7ab4b2c Mon Sep 17 00:00:00 2001 From: rasmus <ras...@gmx.us> Date: Tue, 9 Dec 2014 12:40:52 +0100 Subject: [PATCH] ox.el: Fix footnote-bug in #+INCLUDE-keyword * ox.el (org-export--prepare-file-contents): Preserve footnote-section when using the LINES argument. --- lisp/ox.el | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index 9d9e794..bf2ce4d 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3260,8 +3260,27 @@ with footnotes is included in a document." (end (if (zerop lend) (point-max) (goto-char (point-min)) (forward-line (1- lend)) - (point)))) - (narrow-to-region beg end))) + (point))) + (footnote-section-re + (concat "^\\*+[ \t]+" org-footnote-section "[ \t]*$")) + (footnote-sections + (save-match-data + (save-excursion + (goto-char (point-min)) + (loop do + (or (search-forward-regexp footnote-section-re nil t) + (end-of-buffer)) + while (not (eobp)) + collect + (buffer-substring + (line-beginning-position) + (or (and + (search-forward-regexp org-heading-regexp nil t) + (goto-char (match-beginning 0))) + (point-max)))))))) + (narrow-to-region beg end) + (and footnote-sections + (insert "\n" (mapconcat 'identity footnote-sections "\n"))))) ;; Remove blank lines at beginning and end of contents. The logic ;; behind that removal is that blank lines around include keyword ;; override blank lines in included file. -- 2.1.3