From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: Bug: When exporting to PDF an Org file where multiple footnotes share the same definition, only the first footnote is clickable [8.3.4 (8.3.4-39-ge0acd8-elpaplus @ /home/jorge/.emacs.d/elpa/org-plus-contrib-20160418/)] Date: Sun, 22 May 2016 22:16:04 +0200 Message-ID: <87r3ctalx7.fsf@gmx.us> References: <1461444845.13483.6.camel@gmail.com> <87h9eqt74z.fsf@gmx.us> <87a8kivzcc.fsf@saiph.selenimh> <87r3durmc6.fsf@gmx.us> <87h9ep6hkx.fsf@saiph.selenimh> <874mapstdk.fsf@gmx.us> <87a8kh4wpp.fsf@saiph.selenimh> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4ZrB-0004Am-N6 for emacs-orgmode@gnu.org; Sun, 22 May 2016 16:20:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b4Zr7-0004Zy-Fz for emacs-orgmode@gnu.org; Sun, 22 May 2016 16:20:12 -0400 Received: from plane.gmane.org ([80.91.229.3]:38087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4Zr7-0004Zj-4L for emacs-orgmode@gnu.org; Sun, 22 May 2016 16:20:09 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1b4Zr1-0000jv-Fc for emacs-orgmode@gnu.org; Sun, 22 May 2016 22:20:03 +0200 Received: from ip-178-203-232-158.hsi10.unitymediagroup.de ([178.203.232.158]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 22 May 2016 22:20:03 +0200 Received: from rasmus by ip-178-203-232-158.hsi10.unitymediagroup.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 22 May 2016 22:20:03 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Nicolas Goaziou writes: > Rasmus writes: > >> Could we inject labels in all footnotes? If so we could simply use >> >> \textsuperscript{\ref{FN-LABEL}} >> >> In place of >> >> \footnotemark[FN-GUESS]{} >> >> It seems \footref of scrextend.sty has some extra robustness built into it >> but until someone complains I think the \textsuperscript hack should be >> enough and better then what we’ve got. > > That's a bit hackish, but definitely possible. Do yo want to provide > a patch? With the attached patch ox-latex seems to behave in this way. Though perhaps there’s a more efficient way to get the first footnote-reference to a given definition than trawling through with org-export--footnote-reference-map. Nicolas, where is the info plist documented or defined/populated? Rasmus -- Together we will make the possible totalllly impossible! --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-ox-latex-More-robust-footnote-referencing.patch >From 07f15d538aa02d5b45fa545395442f5663260430 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Sun, 22 May 2016 20:33:06 +0200 Subject: [PATCH] ox-latex: More robust footnote referencing * lisp/ox-latex.el (org-latex--label): Prefix footnote with "fn". (org-latex--delayed-footnotes-definitions): Fix typo in docstring. (org-latex-footnote-reference): Use \ref{.} and \label{.} for repeated references. --- lisp/ox-latex.el | 72 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 9c31645..3c66a32 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -1246,6 +1246,8 @@ Eventually, if FULL is non-nil, wrap label within \"\\label{}\"." org-latex-math-environments-re (org-element-property :value datum)) "eq:")) + (footnote-reference "fn:") + (footnote-definition "fn:") (paragraph (and (org-element-property :caption datum) "fig:"))) @@ -1498,7 +1500,7 @@ INFO is a plist used as a communication channel. See INFO is a plist used as a communication channel. -Footnotes definitions are returned within \"\\footnotetxt{}\" +Footnotes definitions are returned within \"\\footnotetext{}\" commands. This function is used within constructs that don't support @@ -1803,30 +1805,50 @@ CONTENTS is nil. INFO is a plist holding contextual information." (defun org-latex-footnote-reference (footnote-reference _contents info) "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX. CONTENTS is nil. INFO is a plist holding contextual information." - (concat - ;; Insert separator between two footnotes in a row. - (let ((prev (org-export-get-previous-element footnote-reference info))) - (when (eq (org-element-type prev) 'footnote-reference) - (plist-get info :latex-footnote-separator))) - (cond - ;; Use \footnotemark if the footnote has already been defined. - ((not (org-export-footnote-first-reference-p footnote-reference info)) - (format "\\footnotemark[%s]{}" - (org-export-get-footnote-number footnote-reference info))) - ;; Use \footnotemark if reference is within another footnote - ;; reference, footnote definition or table cell. - ((org-element-lineage footnote-reference - '(footnote-reference footnote-definition table-cell)) - "\\footnotemark") - ;; Otherwise, define it with \footnote command. - (t - (let ((def (org-export-get-footnote-definition footnote-reference info))) - (concat - (format "\\footnote{%s}" (org-trim (org-export-data def info))) - ;; Retrieve all footnote references within the footnote and - ;; add their definition after it, since LaTeX doesn't support - ;; them inside. - (org-latex--delayed-footnotes-definitions def info))))))) + (let ((label (org-element-property :label footnote-reference))) + (concat + ;; Insert separator between two footnotes in a row. + (let ((prev (org-export-get-previous-element footnote-reference info))) + (when (eq (org-element-type prev) 'footnote-reference) + (plist-get info :latex-footnote-separator))) + (cond + ;; Use \footnotemark if the footnote has already been defined. + ((not (org-export-footnote-first-reference-p footnote-reference info)) + (format "\\textsuperscript{\\ref{%s}}" + (org-latex--label + (catch 'exit + (org-export--footnote-reference-map + (lambda (f) + (let ((l (org-element-property :label f))) + (when (and l label (string= label l)) + (throw 'exit f)))) + (plist-get info :parse-tree) info)) + info t))) + ;; Use \footnotemark if reference is within another footnote + ;; reference, footnote definition or table cell. + ((org-element-lineage footnote-reference + '(footnote-reference footnote-definition table-cell)) + "\\footnotemark") + ;; Otherwise, define it with \footnote command. + (t + (let ((def (org-export-get-footnote-definition footnote-reference info))) + (concat + (format "\\footnote{%s%s}" (org-trim (org-export-data def info)) + (if (catch 'exit + (org-export--footnote-reference-map + (lambda (f) + (let ((l (org-element-property :label f))) + (when (and l label + (not (eq f footnote-reference)) + (string= label l)) + (throw 'exit t)))) + (plist-get info :parse-tree) info)) + (org-latex--label footnote-reference info t t) + "")) + ;; Retrieve all footnote references within the footnote and + ;; add their definition after it, since LaTeX doesn't support + ;; them inside. + (org-latex--delayed-footnotes-definitions def info)))))))) ;;;; Headline -- 2.8.2 --=-=-=--