emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: Georg Lehner <jorge-org@magma.com.ni>
Cc: emacs-orgmode@gnu.org
Subject: Re: Open Document Exporter
Date: Sat, 29 Jun 2013 18:13:52 +0530	[thread overview]
Message-ID: <87hagh2ik7.fsf@gmail.com> (raw)
In-Reply-To: <51CB8504.9030401@magma.com.ni> (Georg Lehner's message of "Thu, 27 Jun 2013 02:19:16 +0200")

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


I need time to review other issues you are raising.  

Georg Lehner <jorge-org@magma.com.ni> writes:
> 4. LaTeX like definition lists

Here is a patch and sample documents.  You can pull from my private repo
which is at 

        http://repo.or.cz/w/org-mode/org-kjn.git


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-odt-Support-for-typesetting-Description-lists-as-.patch --]
[-- Type: text/x-diff, Size: 8746 bytes --]

From 7dfa274163fb3a06ff947e1af884af49dca34b0e Mon Sep 17 00:00:00 2001
From: Jambunathan K <kjambunathan@gmail.com>
Date: Sat, 29 Jun 2013 17:59:48 +0530
Subject: [PATCH] ox-odt: Support for typesetting Description lists as in LaTeX

* etc/styles.OrgOdtStyles.xml (OrgDescriptionTerm)
(OrgDescriptionDefinition): New styles for typesetting
description lists.

* lisp/ox-odt.el (org-odt-description-list-style): New user option.
(org-odt--translate-description-lists/html): Renmed from
`org-odt--translate-description-lists.  Use new style
"OrgDescriptionTerm".  Update comments.
(org-odt--translate-description-lists/latex): New.
(org-odt-bold): Add an internal `:style' property.
---
 etc/styles/OrgOdtStyles.xml |   10 +++
 lisp/ox-odt.el              |  141 +++++++++++++++++++++++++++++++++++++-----
 2 files changed, 134 insertions(+), 17 deletions(-)

diff --git a/etc/styles/OrgOdtStyles.xml b/etc/styles/OrgOdtStyles.xml
index f41d984..c2c32fa 100644
--- a/etc/styles/OrgOdtStyles.xml
+++ b/etc/styles/OrgOdtStyles.xml
@@ -729,6 +729,16 @@
    </text:list-level-style-number>
   </text:list-style>
 
+  <style:style style:name="OrgDescriptionTerm" style:family="text">
+   <style:text-properties fo:font-weight="bold"/>
+  </style:style>
+
+  <style:style style:name="OrgDescriptionDefinition" style:family="paragraph" style:parent-style-name="Text_20_body" style:class="text">
+   <style:paragraph-properties fo:margin-left="0.64cm" fo:margin-right="0cm" fo:text-indent="-0.64cm" style:auto-text-indent="false">
+    <style:tab-stops/>
+   </style:paragraph-properties>
+  </style:style>
+
   <text:list-style style:name="OrgSrcBlockNumberedLine">
    <text:list-level-style-number text:level="1" style:num-format="1">
     <style:list-level-properties text:space-before="0.635cm" text:min-label-width="0.635cm" text:min-label-distance="0.101cm" fo:text-align="end"/>
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index a76f7dd..0eaffcb 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -86,7 +86,7 @@ (org-export-define-backend 'odt
   :export-block "ODT"
   :filters-alist '((:filter-parse-tree
 		    . (org-odt--translate-latex-fragments
-		       org-odt--translate-description-lists
+		       org-odt--translate-description-lists ; Dummy symbol
 		       org-odt--translate-list-tables)))
   :menu-entry
   '(?o "Export to ODT"
@@ -777,6 +777,22 @@ (defcustom org-odt-pixels-per-inch display-pixels-per-inch
   :version "24.1")
 
 
+;;;; Lists
+
+(defcustom org-odt-description-list-style #'org-odt--translate-description-lists/html
+  "Specify how description lists are rendered.
+Choose one of HTML or LaTeX style."
+  :type '(choice
+          (const :tag "Use HTML style" org-odt--translate-description-lists/html )
+          (const :tag "Use LaTeX style" org-odt--translate-description-lists/latex ))
+  :group 'org-export-odt
+  :set (lambda (symbol value)
+	 "Alias `org-odt--translate-description-lists'."
+	 (set-default symbol value)
+  	 (fset 'org-odt--translate-description-lists value))
+  :version "24.1")
+
+
 ;;;; Src Block
 
 (defcustom org-odt-create-custom-styles-for-srcblocks t
@@ -1583,7 +1599,11 @@ (defun org-odt-bold (bold contents info)
 CONTENTS is the text with bold markup.  INFO is a plist holding
 contextual information."
   (format "<text:span text:style-name=\"%s\">%s</text:span>"
-	  "Bold" contents))
+	  ;; Internally, `org-odt--translate-description-lists/html'
+	  ;; or `org-odt--translate-description-lists/latex' requests
+	  ;; a custom style for bold.
+	  (or (org-element-property :style bold) "Bold")
+	  contents))
 
 
 ;;;; Center Block
@@ -3650,7 +3670,7 @@ (defun org-odt-table (table contents info)
     ;;   item, but also within description lists and low-level
     ;;   headlines.
 
-    ;; See `org-odt-translate-description-lists' and
+    ;; See `org-odt--translate-description-lists' and
     ;; `org-odt-translate-low-level-headlines' for how this is
     ;; tackled.
 
@@ -3869,27 +3889,44 @@ (defun org-odt--translate-latex-fragments (tree backend info)
 ;; This translator is necessary to handle indented tables in a uniform
 ;; manner.  See comment in `org-odt--table'.
 
-(defun org-odt--translate-description-lists (tree backend info)
+;; Depending on user option `org-odt-description-list-style',
+;; description lists can be typeset either as in HTML documents or as
+;; in LaTeX documents.
+
+(defun org-odt--translate-description-lists/html (tree backend info)
   ;; OpenDocument has no notion of a description list.  So simulate it
   ;; using plain lists.  Description lists in the exported document
   ;; are typeset in the same manner as they are in a typical HTML
-  ;; document.
+  ;; document.  See `org-odt--translate-description-lists/latex' for
+  ;; yet another way of translation.
   ;;
   ;; Specifically, a description list like this:
   ;;
-  ;;     ,----
-  ;;     | - term-1 :: definition-1
-  ;;     | - term-2 :: definition-2
-  ;;     `----
+  ;; 	 ,----
+  ;; 	 | - term-1 :: definition-1
+  ;; 	 |
+  ;; 	 | 	    paragraph-1
+  ;; 	 |
+  ;; 	 | - term-2 :: definition-2
+  ;; 	 |
+  ;; 	 | 	    paragraph-2
+  ;; 	 `----
   ;;
   ;; gets translated in to the following form:
   ;;
-  ;;     ,----
-  ;;     | - term-1
-  ;;     |   - definition-1
-  ;;     | - term-2
-  ;;     |   - definition-2
-  ;;     `----
+  ;; 	 ,----
+  ;; 	 | - term-1
+  ;;     |
+  ;; 	 |   - definition-1
+  ;; 	 |
+  ;; 	 |     paragraph-1
+  ;; 	 |
+  ;; 	 | - term-2
+  ;;     |
+  ;; 	 |   - definition-2
+  ;; 	 |
+  ;; 	 |     paragraph-2
+  ;; 	 `----
   ;;
   ;; Further effect is achieved by fixing the OD styles as below:
   ;;
@@ -3912,8 +3949,9 @@ (defun org-odt--translate-description-lists (tree backend info)
 		   (org-element-adopt-elements
 		    (list 'item (list :checkbox (org-element-property
 						 :checkbox item)))
-		    (list 'paragraph (list :style "Text_20_body_20_bold")
-			  (or (org-element-property :tag item) "(no term)"))
+		    (list 'paragraph nil
+			  (list 'bold (list :style "OrgDescriptionTerm")
+				(or (org-element-property :tag item) "(no term)")))
 		    (org-element-adopt-elements
 		     (list 'plain-list (list :type 'descriptive-2))
 		     (apply 'org-element-adopt-elements
@@ -3924,6 +3962,75 @@ (defun org-odt--translate-description-lists (tree backend info)
     info)
   tree)
 
+(defun org-odt--translate-description-lists/latex (tree backend info)
+  ;; OpenDocument has no notion of a description list.  So simulate it
+  ;; using plain lists.  Description lists in the exported document
+  ;; are typeset in the same manner as they are in a typical LaTeX
+  ;; style document.  See `org-odt--translate-description-lists/html'
+  ;; for yet another way of translation.
+  ;;
+  ;; Specifically, a description list like this:
+  ;;
+  ;; 	,----
+  ;; 	| - term-1 :: definition-1
+  ;; 	|
+  ;; 	| 	    paragraph-1
+  ;; 	|
+  ;; 	| - term-2 :: definition-2
+  ;; 	|
+  ;; 	| 	    paragraph-2
+  ;; 	`----
+  ;;
+  ;; gets translated in to the following form:
+  ;;
+  ;; 	 ,----
+  ;; 	 | - *term-1* definition-1
+  ;; 	 |
+  ;; 	 |   - paragraph-1
+  ;; 	 |
+  ;; 	 | - *term-2* definition-2
+  ;; 	 |
+  ;; 	 |   - paragraph-2
+  ;; 	 `----
+  ;;
+  ;; Further effect is achieved by fixing the OD styles as below:
+  ;;
+  ;; 1. Set the :type property of the simulated lists to
+  ;;    `descriptive-1' and `descriptive-2'.  Map these to list-styles
+  ;;    that has *no* bullets whatsoever.
+  ;;
+  ;; 2. The paragraph containing the definition term is styled to be
+  ;;    use hanging indent.
+  ;;
+  (org-element-map tree 'plain-list
+    (lambda (el)
+      (when (equal (org-element-property :type el) 'descriptive)
+	(org-element-set-element
+	 el
+	 (apply 'org-element-adopt-elements
+		(list 'plain-list (list :type 'descriptive-1))
+		(mapcar
+		 (lambda (item)
+		   (let* ((item-contents (org-element-contents item))
+			  (leading-paragraph (car item-contents))
+			  (item-contents (cdr item-contents)))
+		     (org-element-adopt-elements
+		      (list 'item (list :checkbox (org-element-property :checkbox item)))
+		      (apply 'org-element-adopt-elements
+			     (list 'paragraph (list :style "OrgDescriptionDefinition"))
+			     (list 'bold (list :style "OrgDescriptionTerm" :post-blank 1)
+				   (or (org-element-property :tag item) "(no term)"))
+			     (org-element-contents leading-paragraph))
+		      (org-element-adopt-elements
+		       (list 'plain-list (list :type 'descriptive-2))
+		       (apply 'org-element-adopt-elements
+			      (list 'item nil)
+			      item-contents)))))
+		 (org-element-contents el)))))
+      nil)
+    info)
+  tree)
+
 ;;;; List tables
 
 ;; Lists that are marked with attribute `:list-table' are called as
-- 
1.7.2.5


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: dl.org --]
[-- Type: text/x-org, Size: 765 bytes --]

* One
- term-1 :: definition-1 definition-1 definition-1 definition-1
            definition-1 definition-1 definition-1 definition-1
            definition-1 definition-1 definition-1 definition-1
            definition-1 definition-1 definition-1 definition-1
            definition-1 definition-1 definition-1 definition-1
            definition-1 definition-1 definition-1 definition-1
            definition-1
	    
	    Some paragraph.

            | a | b | c |
            | d | e | f |

- term-2 :: definition-2 definition-2 definition-2 definition-2
            definition-2 definition-2 definition-2 definition-2
            definition-2 definition-2 definition-2 definition-2
            definition-2 definition-2 definition-2

	    Another paragraph.


[-- Attachment #4: dl.latex.odt --]
[-- Type: application/vnd.oasis.opendocument.text, Size: 10530 bytes --]

[-- Attachment #5: dl.html.odt --]
[-- Type: application/vnd.oasis.opendocument.text, Size: 10523 bytes --]

  parent reply	other threads:[~2013-06-29 12:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-24 21:29 Open Document Exporter Georg Lehner
2013-06-25  1:35 ` Vikas Rawal
2013-06-27  0:19   ` Georg Lehner
2013-06-27 13:58     ` Bastien
2013-06-29 12:43     ` Jambunathan K [this message]
2013-06-29 20:37       ` Georg Lehner
2013-06-26  9:42 ` Nicolas Goaziou
2013-06-28 21:20 ` Georg Lehner
2013-06-29 13:24 ` Jambunathan K
2013-06-29 13:26 ` Jambunathan K

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hagh2ik7.fsf@gmail.com \
    --to=kjambunathan@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jorge-org@magma.com.ni \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).