emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Exporting footnotes
@ 2011-01-30  9:00 Ethan Glasser-Camp
  2011-02-12 15:59 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Ethan Glasser-Camp @ 2011-01-30  9:00 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 862 bytes --]

Hi list,

I've been playing with the HTML export and it's pretty cool. I just have 
one quibble, which is that footnotes are always put at the end of the 
document. I'd like them to be at the end of each item, which is where I 
put them in my org file -- i.e. I've set org-footnote-section to nil.

I poked around in the code and it looks like the footnotes are being 
normalized, and the normalization function is putting them all at the 
end of the document. Normalization is necessary for the names of 
footnotes, but I think it is too aggressive about moving footnotes. Are 
there exporters for which collecting footnotes in one place is 
necessary? I think org-export-as-html could handle keeping the footnotes 
where they are with minimal changes.

Attached is a sketchy patch that does what I want. It's an ugly hack. 
What do you think?

Thanks.

Ethan


[-- Attachment #2: org-normalize-without-moving.patch --]
[-- Type: text/x-patch, Size: 3076 bytes --]

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index a055bac..99b3a64 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -1094,7 +1094,9 @@ on this string to produce the exported version."
 
       ;; Normalize footnotes
       (when (plist-get parameters :footnotes)
-	(org-footnote-normalize nil t))
+	(if htmlp
+	    (org-footnote-normalize nil org-footnote-section)
+	  (org-footnote-normalize nil t)))
 
       ;; Find all headings and compute the targets for them
       (setq target-alist (org-export-define-heading-targets target-alist))
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index 88ffd6e..027856e 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -478,14 +478,24 @@ referenced sequence."
 	      (not sort-only)	     ; this is normalization
 	      for-preprocessor)       ; the is the preprocessor
 	  ;; Insert the footnotes together in one place
-	  (progn
-	    (setq def
-		  (mapconcat
-		   (lambda (x)
-		     (format "[%s] %s" (nth (if sort-only 0 1) x)
-			     (org-trim (nth 2 x))))
-		   ref-table "\n\n"))
-	    (if ref-table (insert "\n" def "\n\n")))
+	  (if for-preprocessor
+	      (progn
+		(message "%s" ref-table)
+		(setq def
+		      (mapconcat
+		       (lambda (x)
+			 (format "[%s] %s" (nth (if sort-only 0 1) x)
+				 (org-trim (nth 2 x))))
+		       ref-table "\n\n"))
+		(if ref-table (insert "\n" def "\n\n")))
+	    (mapc (lambda (entry)
+		    (when (car entry)
+		      (goto-char (point-min))
+		      (when (re-search-forward (format ".\\[%s[]:]" (regexp-quote (nth 1 entry)))
+					       nil t)
+			(org-footnote-goto-local-insertion-point)
+			(insert (format "\n\n[%s] %s" (nth 1 entry) (nth 2 entry))))))
+		  ref-table))
 	;; Insert each footnote near the first reference
 	;; Happens only in Org files with no special footnote section,
 	;; and only when doing sorting
diff --git a/lisp/org-html.el b/lisp/org-html.el
index 9a5d225..3dedab9 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -1676,16 +1676,19 @@ lang=\"%s\" xml:lang=\"%s\">
       ;; the </div> to close the last text-... div.
       (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
 
-      (save-excursion
-	(goto-char (point-min))
-	(while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
-	  (push (match-string 0) footnotes)
-	  (replace-match "" t t)))
-      (when footnotes
-	(insert (format org-export-html-footnotes-section
-			(nth 4 lang-words)
-			(mapconcat 'identity (nreverse footnotes) "\n"))
-		"\n"))
+      (when org-footnote-section
+	;; Move all the footnotes into a footnotes section
+	(save-excursion
+	  (goto-char (point-min))
+	  (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
+	    (push (match-string 0) footnotes)
+	    (replace-match "" t t)))
+	(when footnotes
+	  (insert (format org-export-html-footnotes-section
+			  (nth 4 lang-words)
+			  (mapconcat 'identity (nreverse footnotes) "\n"))
+		  "\n")))
+
       (let ((bib (org-export-html-get-bibliography)))
 	(when bib
 	  (insert "\n" bib "\n")))

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: Exporting footnotes
  2011-01-30  9:00 Exporting footnotes Ethan Glasser-Camp
@ 2011-02-12 15:59 ` Bastien
  0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2011-02-12 15:59 UTC (permalink / raw)
  To: Ethan Glasser-Camp; +Cc: emacs-orgmode

Hi Ethan,

Ethan Glasser-Camp <glasse@cs.rpi.edu> writes:

> I've been playing with the HTML export and it's pretty cool. I just have
> one quibble, which is that footnotes are always put at the end of the
> document. I'd like them to be at the end of each item, which is where I put
> them in my org file -- i.e. I've set org-footnote-section to nil.
>
> I poked around in the code and it looks like the footnotes are being
> normalized, and the normalization function is putting them all at the end
> of the document. Normalization is necessary for the names of footnotes, but
> I think it is too aggressive about moving footnotes. 

I agree.

> Are there exporters for which collecting footnotes in one place is
> necessary? I think org-export-as-html could handle keeping the
> footnotes where they are with minimal changes.
>
> Attached is a sketchy patch that does what I want. It's an ugly hack. What
> do you think?

I tested the patch and it does what you want, thanks for it.

It doesn't break footnotes export in LaTeX (good thing!).  I didn't 
test for other exporters.

However, it seems to me that org-footnote-normalize does the right thing
when putting every footnotes at a single place -- at least, there should
be a footnote section, even when footnotes live within a subtree.  It'll
make life easier for exporter.

If you don't mind, I first want to do some work on the generic exporter
to decide how to implement your idea.

Thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-02-12 15:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-30  9:00 Exporting footnotes Ethan Glasser-Camp
2011-02-12 15:59 ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).