From 861ecb85baf0467610bb6bbdfa985a2f4adaa795 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Sun, 18 Sep 2011 00:09:06 +0530 Subject: [PATCH] org-odt.el: Typeset display equations using tables * contrib/odt/styles/OrgOdtContentTemplate.xml: Add bottom margin to "OrgTable". Modify border properties of "OrgTblCell*"s. Add "OrgEquation" table styles for typesetting of display equations. * contrib/odt/styles/OrgOdtStyles.xml: Added various "graphic" styles for formatting of inline and display equations. Modified names of some "graphic" styles for images for reasons of consistency. * contrib/lisp/org-odt.el (org-export-odt-do-format-image): Removed. This is now folded in to `org-export-odt-format-image'. A part of this is extracted in to `org-odt-format-entity'. (org-odt-entity-frame-styles): New variable. (org-odt-format-entity): New function. See previous entries. (org-export-odt-format-image): Modified. See previous entries. (org-export-odt-do-format-numbered-formula) (org-export-odt-do-format-formula): Removed. These functions are now folded within `org-export-odt-format-formula'. (org-export-odt-format-formula): Modified as noted above. Also use `org-odt-format-entity'. (org-odt-format-frame, org-odt-format-textbox): Modified signature to facilitate elegant introduction of `org-odt-format-entity'. (org-odt-format-inlinetask): Honor change in signature. (org-odt-label-def-ref-spec): Added an entry for "Equation". Only MathML equations are typeset using tables. Dvipng equations are still typeset as regular images. --- contrib/lisp/org-odt.el | 139 ++++++++++++--------------- contrib/odt/styles/OrgOdtContentTemplate.xml | 54 ++++++++--- contrib/odt/styles/OrgOdtStyles.xml | 28 +++++- 3 files changed, 121 insertions(+), 100 deletions(-) diff --git a/contrib/lisp/org-odt.el b/contrib/lisp/org-odt.el index 7c03745aa..792ca2cea 100644 --- a/contrib/lisp/org-odt.el +++ b/contrib/lisp/org-odt.el @@ -1170,51 +1170,11 @@ value of `org-export-odt-use-htmlfontify." (org-odt-copy-image-file thefile) thelink)))) (org-export-odt-format-image thefile href))) -(defun org-export-odt-do-format-numbered-formula (embed-as caption attr label - width height href) - (with-temp-buffer - (let ((org-lparse-table-colalign-info '((0 "c" "8") (0 "c" "1")))) - (org-lparse-insert-list-table - `((,(org-export-odt-do-format-formula ; caption and label - ; should be nil - embed-as nil attr nil width height href) - ,(org-odt-format-entity-caption label caption "Equation"))) - nil nil nil nil nil org-lparse-table-colalign-info)) - (buffer-substring-no-properties (point-min) (point-max)))) - -(defun org-export-odt-do-format-formula (embed-as caption attr label - width height href) - "Create image tag with source and attributes." - (save-match-data - (cond - ((and (not caption) (not label)) - (let (style-name anchor-type) - (case embed-as - (paragraph - (setq style-name "OrgSimpleGraphics" anchor-type "paragraph")) - (character - (setq style-name "OrgInlineGraphics" anchor-type "as-char")) - (t - (error "Unknown value for embed-as %S" embed-as))) - (org-odt-format-frame href style-name width height nil anchor-type))) - (t - (concat - (org-odt-format-textbox - (org-odt-format-stylized-paragraph - 'illustration - (concat - (let ((extra "")) - (org-odt-format-frame - href "" width height extra "paragraph")) - (org-odt-format-entity-caption label caption "Equation"))) - "OrgCaptionFrame" width height)))))) - (defun org-export-odt-format-formula (src href &optional embed-as) "Create image tag with source and attributes." (save-match-data (let* ((caption (org-find-text-property-in-string 'org-caption src)) (caption (and caption (org-xml-format-desc caption))) - (attr (org-find-text-property-in-string 'org-attributes src)) (label (org-find-text-property-in-string 'org-label src)) (embed-as (or embed-as (and (org-find-text-property-in-string @@ -1222,11 +1182,20 @@ value of `org-export-odt-use-htmlfontify." (org-find-text-property-in-string 'org-latex-src-embed-type src)) 'paragraph)) - (attr-plist (when attr (read attr))) - (width (plist-get attr-plist :width)) - (height (plist-get attr-plist :height))) - (org-export-odt-do-format-formula - embed-as caption attr label width height href)))) + width height) + (cond + ((eq embed-as 'character) + (org-odt-format-entity "InlineFormula" href width height)) + (t + (org-lparse-end-paragraph) + (org-lparse-insert-list-table + `((,(org-odt-format-entity + (if caption "CaptionedDisplayFormula" "DisplayFormula") + href width height caption nil) + ,(if (not label) "" + (org-odt-format-entity-caption label nil "Equation")))) + nil nil nil "OrgEquation" nil '((1 "c" 8) (2 "c" 1))) + (throw 'nextline nil)))))) (defvar org-odt-embedded-formulas-count 0) (defun org-odt-copy-formula-file (path) @@ -1409,12 +1378,20 @@ MAY-INLINE-P allows inlining it as an image." (size (org-odt-image-size-from-file src (plist-get attr-plist :width) (plist-get attr-plist :height) - (plist-get attr-plist :scale) nil embed-as))) - (org-export-odt-do-format-image - embed-as caption attr label (car size) (cdr size) href)))) + (plist-get attr-plist :scale) nil embed-as)) + (width (car size)) (height (cdr size))) + (cond + ((not (or caption label)) + (case embed-as + (paragraph (org-odt-format-entity "DisplayImage" href width height)) + (character (org-odt-format-entity "InlineImage" href width height)) + (t (error "Unknown value for embed-as %S" embed-as)))) + (t + (org-odt-format-entity + "CaptionedDisplayImage" href width height caption label)))))) -(defun org-odt-format-frame (text style &optional - width height extra anchor-type) +(defun org-odt-format-frame (text width height style &optional + extra anchor-type) (let ((frame-attrs (concat (if width (format " svg:width=\"%0.2fcm\"" width) "") @@ -1425,13 +1402,14 @@ MAY-INLINE-P allows inlining it as an image." '("" . "") text style frame-attrs))) -(defun org-odt-format-textbox (text style &optional width height extra) +(defun org-odt-format-textbox (text width height style &optional + extra anchor-type) (org-odt-format-frame (org-odt-format-tags '("" . "") text (concat (format " fo:min-height=\"%0.2fcm\"" (or height .2)) (format " fo:min-width=\"%0.2fcm\"" (or width .2)))) - style width nil extra)) + width nil style extra anchor-type)) (defun org-odt-format-inlinetask (heading content &optional todo priority tags) @@ -1442,33 +1420,34 @@ MAY-INLINE-P allows inlining it as an image." (org-lparse-format 'HEADLINE (concat (org-lparse-format-todo todo) " " heading) nil tags)) - content) "OrgInlineTaskFrame" nil nil " style:rel-width=\"100%\""))) -(defun org-export-odt-do-format-image (embed-as caption attr label - width height href) - "Create image tag with source and attributes." - (save-match-data - (cond - ((and (not caption) (not label)) - (let (style-name anchor-type) - (case embed-as - (paragraph - (setq style-name "OrgSimpleGraphics" anchor-type "paragraph")) - (character - (setq style-name "OrgInlineGraphics" anchor-type "as-char")) - (t - (error "Unknown value for embed-as %S" embed-as))) - (org-odt-format-frame href style-name width height nil anchor-type))) - (t - (concat - (org-odt-format-textbox - (org-odt-format-stylized-paragraph - 'illustration - (concat - (let ((extra " style:rel-width=\"100%\" style:rel-height=\"scale\"")) - (org-odt-format-frame - href "OrgCaptionedGraphics" width height extra "paragraph")) - (org-odt-format-entity-caption label caption "Figure"))) - "OrgCaptionFrame" width height)))))) + content) nil nil "OrgInlineTaskFrame" " style:rel-width=\"100%\""))) + +(defvar org-odt-entity-frame-styles + '(("InlineImage" "Figure" ("OrgInlineImage" nil "as-char")) + ("DisplayImage" "Figure" ("OrgDisplayImage" nil "paragraph")) + ("CaptionedDisplayImage" "Figure" + ("OrgCaptionedImage" + " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph") + ("OrgImageCaptionFrame")) + ("InlineFormula" "Equation" ("OrgInlineFormula" nil "as-char")) + ("DisplayFormula" "Equation" ("OrgDisplayFormula" nil "as-char")) + ("CaptionedDisplayFormula" "Equation" + ("OrgCaptionedFormula" nil "paragraph") + ("OrgFormulaCaptionFrame" nil "as-char")))) + +(defun org-odt-format-entity (entity href width height &optional caption label) + (let* ((entity-style (assoc entity org-odt-entity-frame-styles)) + (entity-frame (apply 'org-odt-format-frame + href width height (nth 2 entity-style)))) + (if (not (or caption label)) entity-frame + (apply 'org-odt-format-textbox + (org-odt-format-stylized-paragraph + 'illustration + (concat entity-frame (org-odt-format-entity-caption + label caption (nth 1 entity-style)))) + width height (nth 3 entity-style))))) + + (defvar org-odt-embedded-images-count 0) (defun org-odt-copy-image-file (path) @@ -1572,7 +1551,7 @@ retrieve an entry with `org-odt-get-label-definition'.") See `org-odt-entity-labels-alist' for known CATEGORY-NAMEs.") (defvar org-odt-label-def-ref-spec - '(;; ("Equation" "(%n)" "text" "(%n)") + '(("Equation" "(%n)" "text" "(%n)") ("" "%e %n%c" "category-and-value" "%e %n")) "Specify how labels are applied and referenced. This is an alist where each element is of the form (CATEGORY-NAME diff --git a/contrib/odt/styles/OrgOdtContentTemplate.xml b/contrib/odt/styles/OrgOdtContentTemplate.xml index 61143d994..0ba78c0d5 100644 --- a/contrib/odt/styles/OrgOdtContentTemplate.xml +++ b/contrib/odt/styles/OrgOdtContentTemplate.xml @@ -46,7 +46,7 @@ - + @@ -57,50 +57,72 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contrib/odt/styles/OrgOdtStyles.xml b/contrib/odt/styles/OrgOdtStyles.xml index 7f6f0ad61..e6817f28a 100644 --- a/contrib/odt/styles/OrgOdtStyles.xml +++ b/contrib/odt/styles/OrgOdtStyles.xml @@ -363,29 +363,49 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + -- 2.11.4.GIT