>From f709741922122f76959414f9c152b1aff872ab4e Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Sat, 29 Jun 2013 17:59:48 +0530 Subject: [PATCH 1/4] 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. ---------------------------------------------------------------- To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see . ---------------------------------------------------------------- --- 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 @@ + + + + + + + + + + diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index ae9e473..5dcf9ec 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" @@ -770,6 +770,22 @@ (defcustom org-odt-pixels-per-inch 96.0 :package-version '(Org . "8.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 @@ -1561,7 +1577,11 @@ (defun org-odt-bold (bold contents info) CONTENTS is the text with bold markup. INFO is a plist holding contextual information." (format "%s" - "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 @@ -3643,7 +3663,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. @@ -3863,27 +3883,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: ;; @@ -3906,8 +3943,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 @@ -3918,6 +3956,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