Kaynağa Gözat

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.
Nicolas Goaziou 14 yıl önce
ebeveyn
işleme
6eee91a117
2 değiştirilmiş dosya ile 15 ekleme ve 12 silme
  1. 4 4
      lisp/org-exp.el
  2. 11 8
      lisp/org-latex.el

+ 4 - 4
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))
 

+ 11 - 8
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."