emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-html: subtree specific footnote references
@ 2012-07-07 20:00 Suhail Shergill
  2012-07-07 20:16 ` Suhail Shergill
  0 siblings, 1 reply; 11+ messages in thread
From: Suhail Shergill @ 2012-07-07 20:00 UTC (permalink / raw)
  To: Org mode

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

running org-export-as-html on a subtree is currently problematic if the result
is to be merged into a document which contains html-ized versions of other
subtrees: the footnote references and definitions get clobbered.

this patch uses the CUSTOM_ID property of the subtree to generate unique
footnote references and definitions. if the subtree does not have the CUSTOM_ID
property set the result is a nop.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2291 bytes --]

From 27f89f8bfff334810aba5c33af621e351fa0be79 Mon Sep 17 00:00:00 2001
From: Suhail Shergill <suhailshergill@gmail.com>
Date: Sun, 8 Apr 2012 10:49:51 -0400
Subject: [PATCH] org-html.el: Make footnotes unique to an entry

* lisp/org-html.el (org-export-as-html): Assign unique ids to footnotes
  if possible

If the entry (or its ancestor) has the CUSTOM_ID property defined, then
use that as part of the generated footnote references and definitions.
---
 lisp/org-html.el |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lisp/org-html.el b/lisp/org-html.el
index c9c9d78..8b79c39 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -1248,6 +1248,9 @@ PUB-DIR is set, use this as the publishing directory."
 	 (org-export-have-math nil)
 	 (org-export-footnotes-seen nil)
 	 (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
+	 (custom-id (or (org-entry-get nil "CUSTOM_ID" t) ""))
+	 (footnote-def-prefix (format "fn-%s" custom-id))
+	 (footnote-ref-prefix (format "fnr-%s" custom-id))
 	 (lines
 	  (org-split-string
 	   (org-export-preprocess-string
@@ -1685,8 +1688,8 @@ PUB-DIR is set, use this as the publishing directory."
 			  (format
 			   (concat "%s"
 				   (format org-export-html-footnote-format
-					   (concat "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>")))
-			   (or (match-string 1 org-line) "") n extra n n)
+					   (concat "<a class=\"footref\" name=\"" footnote-ref-prefix ".%s%s\" href=\"#" footnote-def-prefix ".%s\">%s</a>")))
+			   (or (match-string 1 line) "") n extra n n)
 			  ;; If another footnote is following the
 			  ;; current one, add a separator.
 			  (if (save-match-data
@@ -1773,8 +1776,9 @@ PUB-DIR is set, use this as the publishing directory."
 			      (format
 			       (concat "<p class=\"footnote\">"
 				       (format org-export-html-footnote-format
-					       "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
-			       n n n) t t org-line)))))
+					       (concat
+						"<a class=\"footnum\" name=\"" footnote-def-prefix ".%s\" href=\"#" footnote-ref-prefix ".%s\">%s</a>")))
+			       n n n) t t line)))))
 	    ;; Check if the line break needs to be conserved
 	    (cond
 	     ((string-match "\\\\\\\\[ \t]*$" org-line)
-- 
1.7.10


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


-- 
Suhail

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

* Re: org-html: subtree specific footnote references
  2012-07-07 20:00 org-html: subtree specific footnote references Suhail Shergill
@ 2012-07-07 20:16 ` Suhail Shergill
  2012-07-10  3:48   ` Jambunathan K
  0 siblings, 1 reply; 11+ messages in thread
From: Suhail Shergill @ 2012-07-07 20:16 UTC (permalink / raw)
  To: Org mode

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

oops. attached the wrong patch. amended patch follows.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2128 bytes --]

From b9192f5e9a3bbe9620d9f588313d7f62e33135a5 Mon Sep 17 00:00:00 2001
From: Suhail Shergill <suhailshergill@gmail.com>
Date: Sun, 8 Apr 2012 10:49:51 -0400
Subject: [PATCH] org-html.el: Make footnotes unique to an entry

* lisp/org-html.el (org-export-as-html): Assign unique ids to footnotes
  if possible

If the entry (or its ancestor) has the CUSTOM_ID property defined, then
use that as part of the generated footnote references and definitions.
---
 lisp/org-html.el |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/org-html.el b/lisp/org-html.el
index c9c9d78..b9123a1 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -1248,6 +1248,9 @@ PUB-DIR is set, use this as the publishing directory."
 	 (org-export-have-math nil)
 	 (org-export-footnotes-seen nil)
 	 (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
+	 (custom-id (or (org-entry-get nil "CUSTOM_ID" t) ""))
+	 (footnote-def-prefix (format "fn-%s" custom-id))
+	 (footnote-ref-prefix (format "fnr-%s" custom-id))
 	 (lines
 	  (org-split-string
 	   (org-export-preprocess-string
@@ -1685,7 +1688,7 @@ PUB-DIR is set, use this as the publishing directory."
 			  (format
 			   (concat "%s"
 				   (format org-export-html-footnote-format
-					   (concat "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>")))
+					   (concat "<a class=\"footref\" name=\"" footnote-ref-prefix ".%s%s\" href=\"#" footnote-def-prefix ".%s\">%s</a>")))
 			   (or (match-string 1 org-line) "") n extra n n)
 			  ;; If another footnote is following the
 			  ;; current one, add a separator.
@@ -1773,7 +1776,8 @@ PUB-DIR is set, use this as the publishing directory."
 			      (format
 			       (concat "<p class=\"footnote\">"
 				       (format org-export-html-footnote-format
-					       "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
+					       (concat
+						"<a class=\"footnum\" name=\"" footnote-def-prefix ".%s\" href=\"#" footnote-ref-prefix ".%s\">%s</a>")))
 			       n n n) t t org-line)))))
 	    ;; Check if the line break needs to be conserved
 	    (cond
-- 
1.7.10


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



Suhail Shergill <suhailshergill@gmail.com> writes:

> running org-export-as-html on a subtree is currently problematic if the result
> is to be merged into a document which contains html-ized versions of other
> subtrees: the footnote references and definitions get clobbered.
>
> this patch uses the CUSTOM_ID property of the subtree to generate unique
> footnote references and definitions. if the subtree does not have the CUSTOM_ID
> property set the result is a nop.
>
>
> From 27f89f8bfff334810aba5c33af621e351fa0be79 Mon Sep 17 00:00:00 2001
> From: Suhail Shergill <suhailshergill@gmail.com>
> Date: Sun, 8 Apr 2012 10:49:51 -0400
> Subject: [PATCH] org-html.el: Make footnotes unique to an entry
>
> * lisp/org-html.el (org-export-as-html): Assign unique ids to footnotes
>   if possible
>
> If the entry (or its ancestor) has the CUSTOM_ID property defined, then
> use that as part of the generated footnote references and definitions.
> ---
>  lisp/org-html.el |   12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/lisp/org-html.el b/lisp/org-html.el
> index c9c9d78..8b79c39 100644
> --- a/lisp/org-html.el
> +++ b/lisp/org-html.el
> @@ -1248,6 +1248,9 @@ PUB-DIR is set, use this as the publishing directory."
>  	 (org-export-have-math nil)
>  	 (org-export-footnotes-seen nil)
>  	 (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
> +	 (custom-id (or (org-entry-get nil "CUSTOM_ID" t) ""))
> +	 (footnote-def-prefix (format "fn-%s" custom-id))
> +	 (footnote-ref-prefix (format "fnr-%s" custom-id))
>  	 (lines
>  	  (org-split-string
>  	   (org-export-preprocess-string
> @@ -1685,8 +1688,8 @@ PUB-DIR is set, use this as the publishing directory."
>  			  (format
>  			   (concat "%s"
>  				   (format org-export-html-footnote-format
> -					   (concat "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>")))
> -			   (or (match-string 1 org-line) "") n extra n n)
> +					   (concat "<a class=\"footref\" name=\"" footnote-ref-prefix ".%s%s\" href=\"#" footnote-def-prefix ".%s\">%s</a>")))
> +			   (or (match-string 1 line) "") n extra n n)
>  			  ;; If another footnote is following the
>  			  ;; current one, add a separator.
>  			  (if (save-match-data
> @@ -1773,8 +1776,9 @@ PUB-DIR is set, use this as the publishing directory."
>  			      (format
>  			       (concat "<p class=\"footnote\">"
>  				       (format org-export-html-footnote-format
> -					       "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
> -			       n n n) t t org-line)))))
> +					       (concat
> +						"<a class=\"footnum\" name=\"" footnote-def-prefix ".%s\" href=\"#" footnote-ref-prefix ".%s\">%s</a>")))
> +			       n n n) t t line)))))
>  	    ;; Check if the line break needs to be conserved
>  	    (cond
>  	     ((string-match "\\\\\\\\[ \t]*$" org-line)
> -- 
> 1.7.10

-- 
Suhail

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

* Re: org-html: subtree specific footnote references
  2012-07-07 20:16 ` Suhail Shergill
@ 2012-07-10  3:48   ` Jambunathan K
  2012-07-10  4:18     ` Suhail Shergill
  0 siblings, 1 reply; 11+ messages in thread
From: Jambunathan K @ 2012-07-10  3:48 UTC (permalink / raw)
  To: Suhail Shergill; +Cc: Org mode


>> running org-export-as-html on a subtree is currently problematic if
>> the result is to be merged into a document which contains html-ized
>> versions of other subtrees: the footnote references and definitions
>> get clobbered.

Do the subtrees come from the same org file?

Won't it look odd and confusing to a reader, when there are two
different footnote definitions with the same number.  Confusion is like
to be pronounced, if the reader chooses to also print out the document
as a pdf or into paper.
-- 

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

* Re: org-html: subtree specific footnote references
  2012-07-10  3:48   ` Jambunathan K
@ 2012-07-10  4:18     ` Suhail Shergill
  2012-07-10  4:38       ` Jambunathan K
  0 siblings, 1 reply; 11+ messages in thread
From: Suhail Shergill @ 2012-07-10  4:18 UTC (permalink / raw)
  To: emacs-orgmode

Jambunathan K <kjambunathan@gmail.com> writes:

>>> running org-export-as-html on a subtree is currently problematic if
>>> the result is to be merged into a document which contains html-ized
>>> versions of other subtrees: the footnote references and definitions
>>> get clobbered.
>
> Do the subtrees come from the same org file?

that is the use case, yes.

> Won't it look odd and confusing to a reader, when there are two
> different footnote definitions with the same number. 

yes i agree that would be very confusing. but why, pray tell, would there be two
different definitions with the same number?

> Confusion is like to be pronounced, if the reader chooses to also print out
> the document as a pdf or into paper.

again, i'm not sure what scenario you're describing.

i was only describing a scenario where the patch is useful. allow me to try
again.

with the current patch, if the user selects the entire org file and exports it,
there will only be *one* footnotes section, albeit the footnote references and
definitions (which aren't visible unless someone inspects the source) will be
annotated with the CUSTOM_ID property value should it be defined.

the *only* behavioural change that this effects is that the links (and backlinks
from the definitions to references) will continue to work properly even in the
event the user decides to merge the result of multiple subtree exports into one
single document. now whether or not someone wants to do that, is up to them, but
this (the patch in question) at least makes the links more robust.

-- 
Suhail

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

* Re: org-html: subtree specific footnote references
  2012-07-10  4:18     ` Suhail Shergill
@ 2012-07-10  4:38       ` Jambunathan K
  2012-07-10  5:03         ` Suhail Shergill
  0 siblings, 1 reply; 11+ messages in thread
From: Jambunathan K @ 2012-07-10  4:38 UTC (permalink / raw)
  To: Suhail Shergill; +Cc: emacs-orgmode

Suhail Shergill <suhailshergill@gmail.com> writes:

> Jambunathan K <kjambunathan@gmail.com> writes:
>
>>>> running org-export-as-html on a subtree is currently problematic if
>>>> the result is to be merged into a document which contains html-ized
>>>> versions of other subtrees: the footnote references and definitions
>>>> get clobbered.
>>
>> Do the subtrees come from the same org file?
>
> that is the use case, yes.

Try marking the subtrees with :export: tag.  Lookup the following in the
mailing list, worg or the info manual.

     #+EXPORT_SELECT_TAGS:   Tags that select a tree for export
     #+EXPORT_EXCLUDE_TAGS:  Tags that exclude a tree from export

With this, do footnotes come out along the expected lines?

>> Won't it look odd and confusing to a reader, when there are two
>> different footnote definitions with the same number. 
>
> yes i agree that would be very confusing. but why, pray tell, would
> there be two different definitions with the same number?

<a>you haven't modified the description have you?</a>

>> Confusion is like to be pronounced, if the reader chooses to also print out
>> the document as a pdf or into paper.
>
> the *only* behavioural change that this effects is that the links (and backlinks
> from the definitions to references) will continue to work properly even in the
> event the user decides to merge the result of multiple subtree exports into one
> single document.

Links are visible when stuff is printed out on paper.  Is it?
-- 

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

* Re: org-html: subtree specific footnote references
  2012-07-10  4:38       ` Jambunathan K
@ 2012-07-10  5:03         ` Suhail Shergill
  2012-07-10  5:20           ` Jambunathan K
  2012-07-10  5:54           ` Jambunathan K
  0 siblings, 2 replies; 11+ messages in thread
From: Suhail Shergill @ 2012-07-10  5:03 UTC (permalink / raw)
  To: emacs-orgmode

Jambunathan K <kjambunathan@gmail.com> writes:

> Suhail Shergill <suhailshergill@gmail.com> writes:
>
>> Jambunathan K <kjambunathan@gmail.com> writes:
>>
>>>>> running org-export-as-html on a subtree is currently problematic if
>>>>> the result is to be merged into a document which contains html-ized
>>>>> versions of other subtrees: the footnote references and definitions
>>>>> get clobbered.
>>>
>>> Do the subtrees come from the same org file?
>>
>> that is the use case, yes.
>
> Try marking the subtrees with :export: tag.  Lookup the following in the
> mailing list, worg or the info manual.
>
>      #+EXPORT_SELECT_TAGS:   Tags that select a tree for export
>      #+EXPORT_EXCLUDE_TAGS:  Tags that exclude a tree from export
>
> With this, do footnotes come out along the expected lines?

*if* you were to generate the entire file again, things will be fine yes. i'm
talking about a scenario where for one reason or another you may not want to do
that, but may instead only want to export the most recent subtree which has been
added (since the last time it was exported). earlier when you tried to do that,
the footnote links would no longer work because of name attribute
collisions. this patch provides a way to prevent that.

>>> Won't it look odd and confusing to a reader, when there are two
>>> different footnote definitions with the same number. 
>>
>> yes i agree that would be very confusing. but why, pray tell, would
>> there be two different definitions with the same number?
>
> <a>you haven't modified the description have you?</a>

no, i haven't. also, you could look at the patch. the code is pretty
self-explanatory.

>>> Confusion is like to be pronounced, if the reader chooses to also print out
>>> the document as a pdf or into paper.
>>
>> the *only* behavioural change that this effects is that the links (and backlinks
>> from the definitions to references) will continue to work properly even in the
>> event the user decides to merge the result of multiple subtree exports into one
>> single document.
>
> Links are visible when stuff is printed out on paper.  Is it?

not sure what you mean by this. are links visible when you print them? yes,
unless you're using invisible ink. the patch (if you cared to look) modifies the
name attribute of the a tags in question (footnote definition and footnote
references). the text within the a tag (the bit that is actually rendered on
screen/print) is unchanged.

-- 
Suhail

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

* Re: org-html: subtree specific footnote references
  2012-07-10  5:03         ` Suhail Shergill
@ 2012-07-10  5:20           ` Jambunathan K
  2012-07-10  5:54           ` Jambunathan K
  1 sibling, 0 replies; 11+ messages in thread
From: Jambunathan K @ 2012-07-10  5:20 UTC (permalink / raw)
  To: Suhail Shergill; +Cc: emacs-orgmode


>>>> Won't it look odd and confusing to a reader, when there are two
>>>> different footnote definitions with the same number. 
>>>
>>> yes i agree that would be very confusing. but why, pray tell, would
>>> there be two different definitions with the same number?
>>
>> <a>you haven't modified the description have you?</a>
>
> no, i haven't. also, you could look at the patch. the code is pretty
> self-explanatory.

It was not a question. It was a suggestion.

Btw, I will not be the one integrating or reviewing this patch.
-- 

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

* Re: org-html: subtree specific footnote references
  2012-07-10  5:03         ` Suhail Shergill
  2012-07-10  5:20           ` Jambunathan K
@ 2012-07-10  5:54           ` Jambunathan K
  2012-07-16 17:31             ` Suhail Shergill
  1 sibling, 1 reply; 11+ messages in thread
From: Jambunathan K @ 2012-07-10  5:54 UTC (permalink / raw)
  To: Suhail Shergill; +Cc: emacs-orgmode

Suhail Shergill <suhailshergill@gmail.com> writes:

> i'm talking about a scenario where for one reason or another you may
> not want to do that, but may instead only want to export the most
> recent subtree which has been added (since the last time it was
> exported).

You are trying to merge two /instances of export command/ and not two
/instances of subtrees/.  It only so happens that, in your specific
case, you are selecting different subtrees for different export
instances.

What is the value of `org-footnote-section' in your case?

Wrt footnotes, what you see in the Org file is not what the exporter
sees.  Footnote definitions get collected in to the buffer at a suitable
point as part of pre-processing (see `org-footnote-normalize').  Also
footnote definitions can be placed by hand at arbitrary points through
out your Org file.

I have a feeling that patch requires more additions.  Furthermore, you
also need to submit a patch to org-e-html.el which will replace
org-html.el in the future.

I will let the owners of org-html.el to take over from here.

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

* Re: org-html: subtree specific footnote references
  2012-07-10  5:54           ` Jambunathan K
@ 2012-07-16 17:31             ` Suhail Shergill
  2012-08-02 16:26               ` Bastien
  0 siblings, 1 reply; 11+ messages in thread
From: Suhail Shergill @ 2012-07-16 17:31 UTC (permalink / raw)
  To: emacs-orgmode

Jambunathan K <kjambunathan@gmail.com> writes:

> Suhail Shergill <suhailshergill@gmail.com> writes:
>
>> i'm talking about a scenario where for one reason or another you may
>> not want to do that, but may instead only want to export the most
>> recent subtree which has been added (since the last time it was
>> exported).
>
> You are trying to merge two /instances of export command/ and not two
> /instances of subtrees/.  It only so happens that, in your specific
> case, you are selecting different subtrees for different export
> instances.

yes

> What is the value of `org-footnote-section' in your case?

the string "Footnotes"

> Wrt footnotes, what you see in the Org file is not what the exporter
> sees.  Footnote definitions get collected in to the buffer at a suitable
> point as part of pre-processing (see `org-footnote-normalize').  Also
> footnote definitions can be placed by hand at arbitrary points through
> out your Org file.

hmm right.

> I have a feeling that patch requires more additions. 

you're probably right.

> Furthermore, you also need to submit a patch to org-e-html.el which will
> replace org-html.el in the future.
> I will let the owners of org-html.el to take over from here.

*if* this patch makes sense, i'm willing to submit a patch for
org-e-html.el. does anyone have any views? does this patch 'make sense', and is
this the right place for it?

-- 
Suhail

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

* Re: org-html: subtree specific footnote references
  2012-07-16 17:31             ` Suhail Shergill
@ 2012-08-02 16:26               ` Bastien
  2012-08-04  0:17                 ` Suhail Shergill
  0 siblings, 1 reply; 11+ messages in thread
From: Bastien @ 2012-08-02 16:26 UTC (permalink / raw)
  To: Suhail Shergill; +Cc: emacs-orgmode

Hi Suhail,

I have accepted the patch.  I added a TINYCHANGE cookie at the end 
of the git commit message: this is requested for tiny changes made 
by people who did not sign the FSF papers.

Suhail Shergill <suhailshergill@gmail.com> writes:

> *if* this patch makes sense, i'm willing to submit a patch for
> org-e-html.el. 

The patch makes sense but is still a bit hackish.  I accepted it
because the functionality is useful in some cases and because it 
only affects org-html.el, which days are counted.

> does anyone have any views?

My view is that org-e-html.el should also make sure that we always
have unique ids for all the footnotes of the current files, even when 
we export only part of it.

This is not a trivial change though, because org-export.el has to 
change the way it retrieves the footnote number.

Can you have a look at this?

> does this patch 'make sense', and is this the right place for it?

Yes, it is the right place for such patches.

Thanks,

-- 
 Bastien

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

* Re: org-html: subtree specific footnote references
  2012-08-02 16:26               ` Bastien
@ 2012-08-04  0:17                 ` Suhail Shergill
  0 siblings, 0 replies; 11+ messages in thread
From: Suhail Shergill @ 2012-08-04  0:17 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Bastien <bzg@gnu.org> writes:

> My view is that org-e-html.el should also make sure that we always
> have unique ids for all the footnotes of the current files, even when 
> we export only part of it.
>
> This is not a trivial change though, because org-export.el has to 
> change the way it retrieves the footnote number.
>
> Can you have a look at this?

sure

-- 
Suhail

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

end of thread, other threads:[~2012-08-04  0:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-07 20:00 org-html: subtree specific footnote references Suhail Shergill
2012-07-07 20:16 ` Suhail Shergill
2012-07-10  3:48   ` Jambunathan K
2012-07-10  4:18     ` Suhail Shergill
2012-07-10  4:38       ` Jambunathan K
2012-07-10  5:03         ` Suhail Shergill
2012-07-10  5:20           ` Jambunathan K
2012-07-10  5:54           ` Jambunathan K
2012-07-16 17:31             ` Suhail Shergill
2012-08-02 16:26               ` Bastien
2012-08-04  0:17                 ` Suhail Shergill

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).