Hi,

When using LINES in `org-export--prepare-file-contents' the footnotes
section is not preserved causing export to fail.

Minimal example

$> cat t{1,2}.org
# this is t1.org
* intro
foo[fn:1]
* sec2
bar
* Footnotes

[fn:1] baz


# this is t2.org
#+INCLUDE: "./t1.org::#intro"

And export t2.org.

The attached patch fixes this by explicitly saving the footnote section

(Aside: org-footnote-section is used in hackish ways; should we make a
function that returns to correct regexp for the footnotes section?).

It works in a rather large document of mine and in the minimal test.

Should I apply it, or is there a better way to fix this bug?

Thanks,
Rasmus

-- 
Slowly unravels in a ball of yarn and the devil collects it
>From 3f352159d9011e6a00af853fa6dadb04a5b46c87 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 | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 9d9e794..8d4fd6c 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -3260,8 +3260,22 @@ 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
+	      (save-excursion
+		(goto-char (point-min))
+		(when (search-forward-regexp
+		       (concat "^\\*+[ \t]+" org-footnote-section "[ \t]*$")
+		       nil t)
+		  (buffer-substring
+		   (point-at-bol)
+		   (or
+		    (and (search-forward-regexp org-heading-regexp nil t)
+			 (point-at-bol))
+		    (point-max)))))))
+	(narrow-to-region beg end)
+	(and footnote-section
+	     (insert "\n" footnote-section))))
     ;; 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

Reply via email to