From 6eee91a1171b70029ec290c18a32180cd1680e9d Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 15 May 2011 22:29:22 +0200 Subject: [PATCH] org-latex: correct bugs in footnote export * lisp/org-exp (org-export-preprocess-string): normalize footnotes before marking lists ending. * lisp/org-latex.el (org-export-latex-preprocess): work with labels as strings and not as numbers. --- lisp/org-exp.el | 8 ++++---- lisp/org-latex.el | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 8c414ec75..c4174c5c9 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1118,6 +1118,10 @@ on this string to produce the exported version." (org-export-handle-include-files-recurse) (run-hooks 'org-export-preprocess-after-include-files-hook) + ;; Normalize footnotes + (when (plist-get parameters :footnotes) + (org-footnote-normalize nil 'pre-process-p)) + ;; Change lists ending. Other parts of export may insert blank ;; lines and lists' structure could be altered. (org-export-mark-list-end) @@ -1155,10 +1159,6 @@ on this string to produce the exported version." ;; Protected spaces (org-export-convert-protected-spaces) - ;; Normalize footnotes - (when (plist-get parameters :footnotes) - (org-footnote-normalize nil 'pre-process-p)) - ;; Find all headings and compute the targets for them (setq target-alist (org-export-define-heading-targets target-alist)) diff --git a/lisp/org-latex.el b/lisp/org-latex.el index d6b76ea8d..be686be07 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -2428,26 +2428,28 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (let (ref) (while (setq ref (org-footnote-get-next-reference)) (let* ((beg (nth 1 ref)) - (lbl (string-to-number (car ref))) - (def (or (cdr (assoc lbl org-export-footnotes-markers)) ""))) + (lbl (car ref)) + (def (or (nth 3 (org-footnote-get-definition lbl)) ""))) ;; Fix body for footnotes ending on a link or a list and ;; remove definition from buffer. (setq def (concat def (if (string-match "ORG-LIST-END-MARKER\\'" def) "\n" " "))) - (org-footnote-delete-definitions (number-to-string lbl)) + (org-footnote-delete-definitions lbl) ;; Compute string to insert (FNOTE), and protect the outside ;; macro from further transformation. When footnote at point ;; is referring to a previously defined footnote, use ;; \footnotemark. Otherwise, use \footnote. - (let ((fnote (if (memq lbl org-export-latex-footmark-seen) + (let ((fnote (if (member lbl org-export-latex-footmark-seen) (org-export-latex-protect-string - (format "\\footnotemark[%d]" lbl)) + (format "\\footnotemark[%s]" lbl)) (push lbl org-export-latex-footmark-seen) (concat (org-export-latex-protect-string "\\footnote{") def (org-export-latex-protect-string "}")))) + ;; Check if another footnote is immediately following. + ;; If so, add a separator in-between. (sep (org-export-latex-protect-string (if (save-excursion (goto-char (1- (nth 2 ref))) (let ((next (org-footnote-get-next-reference))) @@ -2456,7 +2458,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (when (org-on-heading-p) (setq fnote (concat (org-export-latex-protect-string "\\protect") fnote))) - ;; Replace footnote reference with FOOTNOTE. + ;; Replace footnote reference with FNOTE and, maybe, SEP. ;; `save-excursion' is required if there are two footnotes ;; in a row. In that case, point would be left at the ;; beginning of the second one, and @@ -2472,9 +2474,10 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (org-if-unprotected (replace-match ""))) ;; Remove any left-over footnote definition. - (goto-char (point-min)) (mapc (lambda (fn) (org-footnote-delete-definitions (car fn))) - org-export-footnotes-data)) + org-export-footnotes-data) + (mapc (lambda (fn) (org-footnote-delete-definitions fn)) + org-export-latex-footmark-seen)) (defun org-export-latex-fix-inputenc () "Set the coding system in inputenc to what the buffer is."