emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] [ODT] Subtree export gives wrong footnote style
@ 2013-03-28 12:05 Christian Moe
  2013-03-29 12:51 ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Moe @ 2013-03-28 12:05 UTC (permalink / raw)
  To: Emacs-orgmode


Hi,

The new ODT exporter sometimes, but not always fails to put footnotes in
Footnote style as expected. They are left in Text Body, which is wrong
(and surprisingly difficult to fix in LibreOffice).

After a bit of trial and failure, it seems the error depends on the
scope of export: 

Exporting the whole buffer gives correct footnote style.

Exporting a subtree only fails to give the correct style -- *unless* the
footnote is included in the subtree. In the example below, I actually
get a mix of stylesm depending on whether the footnote is defined in the
exported section or outside it. Org-mode is clearly able to find both
footnotes, and recognize them as footnotes, so I'm baffled at the
different styling.

---------Begin example

#+TITLE: Test ODT footnote style
#+OPTIONS: num:nil toc:nil

* This is a heading

This is a bit of body text.[fn:1] It has footnotes.[fn:2]

[fn:1] This is a footnote I have placed in the same section that I am
exporting. It is in Footnote style (correct).

* Footnotes

[fn:2] This is a footnote in a footnote section. When I export the
section above as a subtree, this footnote is in Text Body
(wrong). When I export the whole document, it's in Footnote style
(correct).

---------End example

Yours,
Christian

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

* Re: [BUG] [ODT] Subtree export gives wrong footnote style
  2013-03-28 12:05 [BUG] [ODT] Subtree export gives wrong footnote style Christian Moe
@ 2013-03-29 12:51 ` Nicolas Goaziou
  2013-03-29 14:22   ` Christian Moe
  0 siblings, 1 reply; 11+ messages in thread
From: Nicolas Goaziou @ 2013-03-29 12:51 UTC (permalink / raw)
  To: Christian Moe; +Cc: Emacs-orgmode

Hello,

Christian Moe <christian.moe@hf.uio.no> writes:

> The new ODT exporter sometimes, but not always fails to put footnotes in
> Footnote style as expected. They are left in Text Body, which is wrong
> (and surprisingly difficult to fix in LibreOffice).
>
> After a bit of trial and failure, it seems the error depends on the
> scope of export: 
>
> Exporting the whole buffer gives correct footnote style.
>
> Exporting a subtree only fails to give the correct style -- *unless* the
> footnote is included in the subtree. In the example below, I actually
> get a mix of stylesm depending on whether the footnote is defined in the
> exported section or outside it. Org-mode is clearly able to find both
> footnotes, and recognize them as footnotes, so I'm baffled at the
> different styling.

I see where the problem lies. In order to implement an appropriate fix,
I need to know the answer of the following problem:

In regular contents, paragraphs within centered blocks get the
"OrgCenter" style. So, in the following example:

  Para 1
  #+begin_center
  Para 2
  #+end_center

style for "Para 1" (resp. "Para 2") is "Text_20_body" (resp.
"OrgCenter").

Now consider the following example where everything is located within
a footnote definition:

  [fn:1] Para 1
    #+begin_center
    Para 2
    #+end_center

"Para 1" obviously gets "Footnote" as style. I'm not sure about "Para
2". What is the appropriate style for it?


Regards,

-- 
Nicolas Goaziou

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

* Re: [BUG] [ODT] Subtree export gives wrong footnote style
  2013-03-29 12:51 ` Nicolas Goaziou
@ 2013-03-29 14:22   ` Christian Moe
  2013-03-29 22:15     ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Moe @ 2013-03-29 14:22 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Christian Moe, Emacs-orgmode


Hi,

Maybe I'm being obtuse, but I don't understand the relevance of your
question to the bug I pointed out. My example had two simple footnotes,
neither of which contained any blocks. The only difference between them
was that one was located inside the subtree being exported and the other
not. They should both simply be in Footnote style.

As for the scenario outlined, I see no justification for centering a
block inside a footnote. I could see a case for supporting, say, quotes
and verse in the footnote context, on the off chance that an Org user
would ever want to do that. If so, I guess the best way to go would be
to define separate Footnote Quote and Footnote Verse styles, and tell
the exporter to use them when such blocks appear inside footnotes.

Yours,
Christian


Nicolas Goaziou writes:

> Hello,
>
> Christian Moe <christian.moe@hf.uio.no> writes:
>
>> The new ODT exporter sometimes, but not always fails to put footnotes in
>> Footnote style as expected. They are left in Text Body, which is wrong
>> (and surprisingly difficult to fix in LibreOffice).
>>
>> After a bit of trial and failure, it seems the error depends on the
>> scope of export: 
>>
>> Exporting the whole buffer gives correct footnote style.
>>
>> Exporting a subtree only fails to give the correct style -- *unless* the
>> footnote is included in the subtree. In the example below, I actually
>> get a mix of stylesm depending on whether the footnote is defined in the
>> exported section or outside it. Org-mode is clearly able to find both
>> footnotes, and recognize them as footnotes, so I'm baffled at the
>> different styling.
>
> I see where the problem lies. In order to implement an appropriate fix,
> I need to know the answer of the following problem:
>
> In regular contents, paragraphs within centered blocks get the
> "OrgCenter" style. So, in the following example:
>
>   Para 1
>   #+begin_center
>   Para 2
>   #+end_center
>
> style for "Para 1" (resp. "Para 2") is "Text_20_body" (resp.
> "OrgCenter").
>
> Now consider the following example where everything is located within
> a footnote definition:
>
>   [fn:1] Para 1
>     #+begin_center
>     Para 2
>     #+end_center
>
> "Para 1" obviously gets "Footnote" as style. I'm not sure about "Para
> 2". What is the appropriate style for it?
>
>
> Regards,

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

* Re: [BUG] [ODT] Subtree export gives wrong footnote style
  2013-03-29 14:22   ` Christian Moe
@ 2013-03-29 22:15     ` Nicolas Goaziou
  2013-03-30  8:11       ` Christian Moe
  0 siblings, 1 reply; 11+ messages in thread
From: Nicolas Goaziou @ 2013-03-29 22:15 UTC (permalink / raw)
  To: Christian Moe; +Cc: Emacs-orgmode

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

Hello,

Christian Moe <christian.moe@hf.uio.no> writes:

> Maybe I'm being obtuse, but I don't understand the relevance of your
> question to the bug I pointed out. My example had two simple footnotes,
> neither of which contained any blocks.

I understood your problem, but I needed to know how deep I had to change
paragraph styles.

Would you mind testing the following patch? I added two new styles. Feel
free to correct them if needed.


Regards,

-- 
Nicolas Goaziou

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

From efd1d46bc3c92e8821cf6156eaf6910444381e02 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Fri, 29 Mar 2013 23:09:11 +0100
Subject: [PATCH] ox-odt: Fix export of footnotes outside subtree during
 subtree export

* etc/styles/OrgOdtStyles.xml: Define "OrgFootnoteCenter" and
  "OrgFootnoteQuotations" styles.
* lisp/ox-odt.el (org-odt--format-paragraph): New function.
(org-odt-paragraph): Use new function to limit code duplication.
(org-odt-footnote-reference): Change default style for paragraphs when
transcoding a footnote definition.
---
 etc/styles/OrgOdtStyles.xml |  6 ++++++
 lisp/ox-odt.el              | 46 +++++++++++++++++++++++++++++++--------------
 2 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/etc/styles/OrgOdtStyles.xml b/etc/styles/OrgOdtStyles.xml
index 26d05f1..f41d984 100644
--- a/etc/styles/OrgOdtStyles.xml
+++ b/etc/styles/OrgOdtStyles.xml
@@ -256,6 +256,9 @@
   <style:style style:name="Quotations" style:family="paragraph" style:parent-style-name="Standard" style:class="html">
    <style:paragraph-properties fo:margin-left="1cm" fo:margin-right="1cm" fo:margin-top="0cm" fo:margin-bottom="0.499cm" fo:text-indent="0cm" style:auto-text-indent="false"/>
   </style:style>
+  <style:style style:name="OrgFootnoteQuotations" style:family="paragraph" style:parent-style-name="Footnote" style:class="html">
+   <style:paragraph-properties fo:margin-left="1cm" fo:margin-right="1cm" fo:margin-top="0cm" fo:margin-bottom="0.499cm" fo:text-indent="0cm" style:auto-text-indent="false"/>
+  </style:style>
   <style:style style:name="Preformatted_20_Text" style:display-name="Preformatted Text" style:family="paragraph" style:parent-style-name="Standard" style:class="html">
    <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm"/>
    <style:text-properties style:font-name="Courier New" fo:font-size="10pt" style:font-name-asian="NSimSun" style:font-size-asian="10pt" style:font-name-complex="Courier New" style:font-size-complex="10pt"/>
@@ -298,6 +301,9 @@
   <style:style style:name="OrgCenter" style:family="paragraph" style:parent-style-name="Text_20_body">
    <style:paragraph-properties fo:text-align="center" style:justify-single-word="false"/>
   </style:style>
+  <style:style style:name="OrgFootnoteCenter" style:family="paragraph" style:parent-style-name="Footnote">
+   <style:paragraph-properties fo:text-align="center" style:justify-single-word="false"/>
+  </style:style>
   <style:style style:name="OrgTableContents" style:family="paragraph" style:parent-style-name="Text_20_body"/>
   <style:style style:name="OrgTableHeading" style:family="paragraph" style:parent-style-name="OrgTableContents" style:class="extra">
     <style:paragraph-properties fo:text-align="center" style:justify-single-word="false" text:number-lines="false" text:line-number="0"/>
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 9dd8946..250aa33 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -1750,9 +1750,17 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	;; Inline definitions are secondary strings.
 	;; Non-inline footnotes definitions are full Org data.
 	(t
-	 (let* ((raw (org-export-get-footnote-definition footnote-reference
-							 info))
-		(def (let ((def (org-trim (org-export-data raw info))))
+	 (let* ((raw (org-export-get-footnote-definition
+		      footnote-reference info))
+		(translations
+		 (cons (cons 'paragraph
+			     (lambda (p c i)
+			       (org-odt--format-paragraph
+				p c "Footnote" "OrgFootnoteCenter"
+				"OrgFootnoteQuotations")))
+		       (org-export-backend-translate-table 'odt)))
+		(def (let ((def (org-trim (org-export-data-with-translations
+					   raw translations info))))
 		       (if (eq (org-element-type raw) 'org-data) def
 			 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 				 "Footnote" def)))))
@@ -2872,27 +2880,37 @@ INFO is a plist holding contextual information.  See
 
 ;;;; Paragraph
 
-(defun org-odt-paragraph (paragraph contents info)
-  "Transcode a PARAGRAPH element from Org to ODT.
-CONTENTS is the contents of the paragraph, as a string.  INFO is
-the plist used as a communication channel."
+(defun org-odt--format-paragraph (paragraph contents default center quote)
+  "Format paragraph according to given styles.
+PARAGRAPH is a paragraph type element.  CONTENTS is the
+transcoded contents of that paragraph, as a string.  DEFAULT,
+CENTER and QUOTE are, respectively, style to use when paragraph
+belongs to no special environment, a center block, or a quote
+block."
   (let* ((parent (org-export-get-parent paragraph))
 	 (parent-type (org-element-type parent))
 	 (style (case parent-type
-		  (quote-block "Quotations")
-		  (center-block "OrgCenter")
-		  (footnote-definition "Footnote")
-		  (t (or (org-element-property :style paragraph)
-			 "Text_20_body")))))
+		  (quote-block quote)
+		  (center-block center)
+		  (t default))))
     ;; If this paragraph is a leading paragraph in an item and the
     ;; item has a checkbox, splice the checkbox and paragraph contents
     ;; together.
     (when (and (eq (org-element-type parent) 'item)
-    	       (eq paragraph (car (org-element-contents parent))))
+	       (eq paragraph (car (org-element-contents parent))))
       (setq contents (concat (org-odt--checkbox parent) contents)))
-    (assert style)
     (format "\n<text:p text:style-name=\"%s\">%s</text:p>" style contents)))
 
+(defun org-odt-paragraph (paragraph contents info)
+  "Transcode a PARAGRAPH element from Org to ODT.
+CONTENTS is the contents of the paragraph, as a string.  INFO is
+the plist used as a communication channel."
+  (org-odt--format-paragraph
+   paragraph contents
+   (or (org-element-property :style paragraph) "Text_20_body")
+   "OrgCenter"
+   "Quotations"))
+
 
 ;;;; Plain List
 
-- 
1.8.2


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

* Re: [BUG] [ODT] Subtree export gives wrong footnote style
  2013-03-29 22:15     ` Nicolas Goaziou
@ 2013-03-30  8:11       ` Christian Moe
  2013-04-01  8:02         ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Moe @ 2013-03-30  8:11 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Christian Moe, Emacs-orgmode

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


Nicolas Goaziou writes:
> I understood your problem, but I needed to know how deep I had to change
> paragraph styles.

Pardon the noise.

> Would you mind testing the following patch? I added two new styles. Feel
> free to correct them if needed.

* The patch fixes the announced bug. Thank you!

All footnotes appear in Footnote style again, regardless of whether the
footnote definitions are located within the exported subtree.

This is an important fix, I think. The output was difficult to correct
within LibreOffice.


* The new styles don't seem to get applied

Quote and center blocks in footnotes do not get OrgFootnoteQuotations
style in my test. They remain Footnote.

(You didn't add any OrgFootnoteVerse style, but I tried it out anyway. A
verse block inside a footnote appears as OrgVerse.)

I include below a test Org fragment and attach the resulting ODT.


* Testing ODT with footnotes

This is a text, with classical footnotes.[fn:1] Some aspire to
poetry,[fn:2] others just seek typographic effect.[fn:3]

[fn:2] This is another footnote in the same subtree. It's followed by
a bit of doggerel.
#+begin_verse
  I think that I shall never see
  a poem lovely as a tree.
#+end_verse

* Footnotes

[fn:1] This is a footnote. It should be in Footnote style in ODT
export. It's followed by a quote block.
#+begin_quote
  "I see that it is long", said Alice, "but how can a tail be sad?"
#+end_quote

[fn:3] This is a third footnote followed by a center block.
#+begin_center
  Centered text here.
#+end_center


Yours,
Christian


[-- Attachment #2: org.odt --]
[-- Type: application/vnd.oasis.opendocument.text, Size: 9767 bytes --]

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

* Re: [BUG] [ODT] Subtree export gives wrong footnote style
  2013-03-30  8:11       ` Christian Moe
@ 2013-04-01  8:02         ` Nicolas Goaziou
  2013-04-01 12:02           ` Christian Moe
  0 siblings, 1 reply; 11+ messages in thread
From: Nicolas Goaziou @ 2013-04-01  8:02 UTC (permalink / raw)
  To: Christian Moe; +Cc: Emacs-orgmode

Hello,

Christian Moe <christian.moe@hf.uio.no> writes:

> * The new styles don't seem to get applied
>
> Quote and center blocks in footnotes do not get OrgFootnoteQuotations
> style in my test. They remain Footnote.
>
> (You didn't add any OrgFootnoteVerse style, but I tried it out anyway. A
> verse block inside a footnote appears as OrgVerse.)
>
> I include below a test Org fragment and attach the resulting ODT.

Judging by the output (i.e. contents.xml), styles are applied:

  <text:p text:style-name="OrgFootnoteQuotations">“I see that it is long”, said Alice, “but how can a tail be sad?”
  </text:p>

  <text:p text:style-name="OrgFootnoteCenter">Centered text here.
  </text:p>

The question is: why aren't these styles effectively applied on the
output. It may be related to their definition, which can be incorrect.


Regards,

-- 
Nicolas Goaziou

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

* Re: [BUG] [ODT] Subtree export gives wrong footnote style
  2013-04-01  8:02         ` Nicolas Goaziou
@ 2013-04-01 12:02           ` Christian Moe
  2013-04-01 15:35             ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Moe @ 2013-04-01 12:02 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Christian Moe, Emacs-orgmode


Hi, Nicolas,

Apologies, it looks like my installation is to blame, and that the part
of the patch that inserted the new style definitions was never applied
to OrgOdtStyles.xml. My org-odt-styles-dir becomes
"/usr/share/emacs/etc/org/styles/", not "etc/styles/". I assume the
latter would be the correct setup.

Yours,
Christian

Nicolas Goaziou writes:
> Judging by the output (i.e. contents.xml), styles are applied:
>
>   <text:p text:style-name="OrgFootnoteQuotations">“I see that it is long”, said Alice, “but how can a tail be sad?”
>   </text:p>
>
>   <text:p text:style-name="OrgFootnoteCenter">Centered text here.
>   </text:p>

> The question is: why aren't these styles effectively applied on the
> output. It may be related to their definition, which can be incorrect.

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

* Re: [BUG] [ODT] Subtree export gives wrong footnote style
  2013-04-01 12:02           ` Christian Moe
@ 2013-04-01 15:35             ` Nicolas Goaziou
  2013-04-01 18:37               ` Christian Moe
  0 siblings, 1 reply; 11+ messages in thread
From: Nicolas Goaziou @ 2013-04-01 15:35 UTC (permalink / raw)
  To: Christian Moe; +Cc: Emacs-orgmode

Christian Moe <christian.moe@hf.uio.no> writes:

> Apologies, it looks like my installation is to blame, and that the part
> of the patch that inserted the new style definitions was never applied
> to OrgOdtStyles.xml. My org-odt-styles-dir becomes
> "/usr/share/emacs/etc/org/styles/", not "etc/styles/". I assume the
> latter would be the correct setup.

Indeed. Try using

  #+odt_styles_file: "/path/to/etc/styles/OrgOdtStyles.xml"

in your buffer.  The styles should be applied to the buffer.

We could also make use of OrgFootnoteVerse and OrgFootnoteCode styles,
but I'm not sure about their definition.

For now, I think the patch is correct to apply. What do you think?


Regards,

-- 
Nicolas Goaziou

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

* Re: [BUG] [ODT] Subtree export gives wrong footnote style
  2013-04-01 15:35             ` Nicolas Goaziou
@ 2013-04-01 18:37               ` Christian Moe
  2013-04-01 22:09                 ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Moe @ 2013-04-01 18:37 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Christian Moe, Emacs-orgmode


Hi again,

Now that I've finally pointed to the patched file, the patch seems to
work perfectly.

> We could also make use of OrgFootnoteVerse and OrgFootnoteCode styles,
> but I'm not sure about their definition.

It doesn't matter all that much, I think -- in any case the style
definition is entirely customizable, and the rare user who wants to use
them will probably want to tweak the style anyway. As long as they
inherit from Footnote and don't look really weird, it should be OK. 

Both could be indented like OrgFootnoteQuotation, the O.F.Code should
probably have a fixed-width font, and if you wanted to make the
distinction between O.F.Verse and O.F.Quotation visually clearer, I
guess verse could be italicised. (No need to copy the OrgVerse style...)

> For now, I think the patch is correct to apply. What do you think?

Absolutely, it fixes a bug in footnote styling, and adds useful styling
of quotes within footnotes.

Yours,
Christian

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

* Re: [BUG] [ODT] Subtree export gives wrong footnote style
  2013-04-01 18:37               ` Christian Moe
@ 2013-04-01 22:09                 ` Nicolas Goaziou
  2013-04-02  7:09                   ` Christian Moe
  0 siblings, 1 reply; 11+ messages in thread
From: Nicolas Goaziou @ 2013-04-01 22:09 UTC (permalink / raw)
  To: Christian Moe; +Cc: Emacs-orgmode

Christian Moe <christian.moe@hf.uio.no> writes:

>> For now, I think the patch is correct to apply. What do you think?
>
> Absolutely, it fixes a bug in footnote styling, and adds useful styling
> of quotes within footnotes.

Patch applied.  Thank you.


Regards,

-- 
Nicolas Goaziou

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

* Re: [BUG] [ODT] Subtree export gives wrong footnote style
  2013-04-01 22:09                 ` Nicolas Goaziou
@ 2013-04-02  7:09                   ` Christian Moe
  0 siblings, 0 replies; 11+ messages in thread
From: Christian Moe @ 2013-04-02  7:09 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Christian Moe, Emacs-orgmode


Thanks!

Yours,
Christian

Nicolas Goaziou writes:

> Christian Moe <christian.moe@hf.uio.no> writes:
>
>>> For now, I think the patch is correct to apply. What do you think?
>>
>> Absolutely, it fixes a bug in footnote styling, and adds useful styling
>> of quotes within footnotes.
>
> Patch applied.  Thank you.
>
>
> Regards,

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

end of thread, other threads:[~2013-04-02  7:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-28 12:05 [BUG] [ODT] Subtree export gives wrong footnote style Christian Moe
2013-03-29 12:51 ` Nicolas Goaziou
2013-03-29 14:22   ` Christian Moe
2013-03-29 22:15     ` Nicolas Goaziou
2013-03-30  8:11       ` Christian Moe
2013-04-01  8:02         ` Nicolas Goaziou
2013-04-01 12:02           ` Christian Moe
2013-04-01 15:35             ` Nicolas Goaziou
2013-04-01 18:37               ` Christian Moe
2013-04-01 22:09                 ` Nicolas Goaziou
2013-04-02  7:09                   ` Christian Moe

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