org-e-odt: Fix handling of inline formula.

Also handle #+ODT_STYLES_FILE.
This commit is contained in:
Jambunathan K 2012-04-05 02:23:18 +05:30
parent 5d9c6d5853
commit 05498b23ab
1 changed files with 87 additions and 61 deletions

View File

@ -711,33 +711,52 @@ Update styles.xml with styles that were collected as part of
(file-relative-name (expand-file-name path dir) (file-relative-name (expand-file-name path dir)
(expand-file-name "eyecandy" dir)))) (expand-file-name "eyecandy" dir))))
(defun org-e-odt-format-formula (src href) (defun org-e-odt-format-formula (src &optional caption label attr)
(save-match-data (let* ((href
(let* ((caption (org-find-text-property-in-string 'org-caption src)) (org-e-odt-format-tags
(caption (and caption (org-xml-format-desc caption))) "<draw:object xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
(label (org-find-text-property-in-string 'org-label src)) (file-name-directory (org-e-odt-copy-formula-file src))))
(latex-frag (org-find-text-property-in-string 'org-latex-src src)) ;; FIXME
(embed-as (or (and latex-frag ;; (caption (org-find-text-property-in-string 'org-caption src))
(org-find-text-property-in-string ;; (caption (and caption (org-xml-format-desc caption)))
'org-latex-src-embed-type src)) ;; (label (org-find-text-property-in-string 'org-label src))
(if (or caption label) 'paragraph 'character))) ;; (latex-frag (org-find-text-property-in-string 'org-latex-src src))
width height) (embed-as (or
(when latex-frag ;; FIXME
(setq href (org-propertize href :title "LaTeX Fragment" ;; (and latex-frag
:description latex-frag))) ;; (org-find-text-property-in-string
(cond ;; 'org-latex-src-embed-type src))
((eq embed-as 'character) (if (or caption label) 'paragraph 'character)))
(org-e-odt-format-entity "InlineFormula" href width height)) width height)
(t ;; FIXME
(org-lparse-end-paragraph) ;; (when latex-frag
(org-lparse-insert-list-table ;; (setq href (org-propertize href :title "LaTeX Fragment"
;; :description latex-frag)))
(cond
((eq embed-as 'character)
(org-e-odt-format-entity "InlineFormula" href width height))
(t
;; (org-lparse-end-paragraph)
(let ((table-info nil)
(table-info
'(:alignment ["c" "c"]
:column-groups [nil nil]
:row-groups (0)
:special-column-p nil :width [8 1]))
(org-lparse-table-ncols 2)
) ; FIXME
(org-e-odt-list-table
`((,(org-e-odt-format-entity `((,(org-e-odt-format-entity
(if caption "CaptionedDisplayFormula" "DisplayFormula") (if caption "CaptionedDisplayFormula" "DisplayFormula")
href width height :caption caption :label nil) href width height :caption caption :label nil)
,(if (not label) "" ,(if (not label) ""
(org-e-odt-format-entity-caption label nil "__MathFormula__")))) (org-e-odt-format-entity-caption label nil "__MathFormula__"))))
nil nil nil ":style \"OrgEquation\"" nil '((1 "c" 8) (2 "c" 1))) nil nil ":style \"OrgEquation\"" ;; nil '((1 "c" 8) (2 "c" 1)) FIXME
(throw 'nextline nil)))))) ))
;; (throw 'nextline nil)
))))
(defun org-e-odt-copy-formula-file (path) (defun org-e-odt-copy-formula-file (path)
"Returns the internal name of the file" "Returns the internal name of the file"
@ -764,17 +783,6 @@ Update styles.xml with styles that were collected as part of
(org-e-odt-create-manifest-file-entry "text/xml" target-file) (org-e-odt-create-manifest-file-entry "text/xml" target-file)
target-file)) target-file))
(defun org-e-odt-format-inline-formula (thefile)
(let* ((thelink (if (file-name-absolute-p thefile) thefile
(org-xml-format-href
(org-e-odt-relocate-relative-path
thefile org-current-export-file))))
(href
(org-e-odt-format-tags
"<draw:object xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
(file-name-directory (org-e-odt-copy-formula-file thefile)))))
(org-e-odt-format-formula thefile href)))
(defun org-e-odt-is-formula-link-p (file) (defun org-e-odt-is-formula-link-p (file)
(let ((case-fold-search nil)) (let ((case-fold-search nil))
(cond (cond
@ -814,7 +822,7 @@ ATTR is a string of other attributes of the a element."
(not fragment) (not fragment)
(org-e-odt-is-formula-link-p filename) (org-e-odt-is-formula-link-p filename)
(or (not descp))) (or (not descp)))
(org-e-odt-format-inline-formula thefile)) (org-e-odt-format-formula thefile))
((string= type "coderef") ((string= type "coderef")
(let* ((ref fragment) (let* ((ref fragment)
(lineno-or-ref (cdr (assoc ref org-export-code-refs))) (lineno-or-ref (cdr (assoc ref org-export-code-refs)))
@ -1223,7 +1231,7 @@ ATTR is a string of other attributes of the a element."
;; (when (equal org-lparse-backend 'odt) FIXME ;; (when (equal org-lparse-backend 'odt) FIXME
;; ) ;; )
(org-e-odt-update-styles-file opt-plist) ;; (org-e-odt-update-styles-file opt-plist)
;; create mimetype file ;; create mimetype file
(let ((mimetype (org-e-odt-write-mimetype-file ;; org-lparse-backend FIXME (let ((mimetype (org-e-odt-write-mimetype-file ;; org-lparse-backend FIXME
@ -1352,9 +1360,9 @@ ATTR is a string of other attributes of the a element."
;; create a manifest entry for meta.xml ;; create a manifest entry for meta.xml
(org-e-odt-create-manifest-file-entry "text/xml" "meta.xml")) (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
(defun org-e-odt-update-styles-file (opt-plist) (defun org-e-odt-update-styles-file (info)
;; write styles file ;; write styles file
(let ((styles-file (plist-get opt-plist :odt-styles-file))) (let ((styles-file (plist-get info :odt-styles-file)))
(org-e-odt-copy-styles-file (and styles-file (org-e-odt-copy-styles-file (and styles-file
(read (org-trim styles-file)))) (read (org-trim styles-file))))
@ -1466,15 +1474,20 @@ using `org-open-file'."
org-current-export-dir nil display-msg org-current-export-dir nil display-msg
nil nil latex-frag-opt)))) nil nil latex-frag-opt))))
(defadvice org-format-latex-as-mathml (eval-after-load 'org-odt
(after org-e-odt-protect-latex-fragment activate) '(ad-deactivate 'org-format-latex-as-mathml))
"Encode LaTeX fragment as XML.
Do this when translation to MathML fails." ; FIXME
(when (or (not (> (length ad-return-value) 0))
(get-text-property 0 'org-protected ad-return-value)) ;; (defadvice org-format-latex-as-mathml ; FIXME
(setq ad-return-value ;; (after org-e-odt-protect-latex-fragment activate)
(org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0)) ;; "Encode LaTeX fragment as XML.
'org-protected t)))) ;; Do this when translation to MathML fails."
;; (when (or (not (> (length ad-return-value) 0))
;; (get-text-property 0 'org-protected ad-return-value))
;; (setq ad-return-value
;; (org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0))
;; 'org-protected t))))
(defun org-e-odt-preprocess-latex-fragments () (defun org-e-odt-preprocess-latex-fragments ()
(when (equal org-export-current-backend 'odt) (when (equal org-export-current-backend 'odt)
@ -1631,12 +1644,6 @@ formula file."
;;; Hooks ;;; Hooks
(defvar org-e-odt-after-blockquotes-hook nil
"Hook run during HTML export, after blockquote, verse, center are done.")
(defvar org-e-odt-final-hook nil
"Hook run at the end of HTML export, in the new buffer.")
;; FIXME: it already exists in org-e-odt.el ;; FIXME: it already exists in org-e-odt.el
;;; Function Declarations ;;; Function Declarations
@ -2046,6 +2053,7 @@ LABEL-STYLE are used for generating ODT labels. See
;; (:html-preamble nil nil org-e-odt-preamble) ;; (:html-preamble nil nil org-e-odt-preamble)
;; (:html-table-tag nil nil org-e-odt-table-tag) ;; (:html-table-tag nil nil org-e-odt-table-tag)
;; (:xml-declaration nil nil org-e-odt-xml-declaration) ;; (:xml-declaration nil nil org-e-odt-xml-declaration)
(:odt-styles-file "ODT_STYLES_FILE" nil nil t)
(:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments)) (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments))
"Alist between export properties and ways to set them. "Alist between export properties and ways to set them.
@ -3172,6 +3180,10 @@ original parsed data. INFO is a plist holding export options."
;; Table of Contents ;; Table of Contents
(let ((depth (plist-get info :with-toc))) (let ((depth (plist-get info :with-toc)))
(when (wholenump depth) (insert (org-e-odt-toc depth info)))) (when (wholenump depth) (insert (org-e-odt-toc depth info))))
;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
(org-e-odt-update-styles-file info)
;; Update styles.xml - take care of outline numbering ;; Update styles.xml - take care of outline numbering
(with-current-buffer (with-current-buffer
(find-file-noselect (expand-file-name "styles.xml") t) (find-file-noselect (expand-file-name "styles.xml") t)
@ -3614,12 +3626,15 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(caption (and (car caption) (org-export-secondary-string (caption (and (car caption) (org-export-secondary-string
(car caption) 'e-odt info))) (car caption) 'e-odt info)))
(label (org-element-property :name latex-environment)) (label (org-element-property :name latex-environment))
(attr nil) ; FIXME (attr nil) ; FIXME
(label (org-element-property :name latex-environment))) (label (org-element-property :name latex-environment)))
(cond (cond
((member processing-type '(t mathjax)) ((member processing-type '(t mathjax))
(org-e-odt-format-latex latex-frag 'mathml)) (let* ((formula-link (org-e-odt-format-latex latex-frag 'mathml)))
(when (and formula-link
(string-match "file:\\([^]]*\\)" formula-link))
(org-e-odt-format-formula
(match-string 1 formula-link) caption label attr))))
((equal processing-type 'dvipng) ((equal processing-type 'dvipng)
(let* ((formula-link (org-e-odt-format-latex (let* ((formula-link (org-e-odt-format-latex
latex-frag processing-type))) latex-frag processing-type)))
@ -3640,7 +3655,12 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(processing-type (plist-get info :LaTeX-fragments))) (processing-type (plist-get info :LaTeX-fragments)))
(cond (cond
((member processing-type '(t mathjax)) ((member processing-type '(t mathjax))
(org-e-odt-format-latex latex-frag 'mathml)) (let* ((formula-link (org-e-odt-format-latex latex-frag 'mathml))
(src (and formula-link
(string-match "file:\\([^]]*\\)" formula-link)
(match-string 1 formula-link))))
(assert src)
(org-e-odt-format-formula src)))
((equal processing-type 'dvipng) ((equal processing-type 'dvipng)
(let* ((formula-link (org-e-odt-format-latex latex-frag processing-type)) (let* ((formula-link (org-e-odt-format-latex latex-frag processing-type))
(src (and formula-link (src (and formula-link
@ -3839,6 +3859,10 @@ INFO is a plist holding contextual information. See
"__Table__") "__Table__")
((org-e-odt-standalone-image-p destination info) ((org-e-odt-standalone-image-p destination info)
"__Figure__") "__Figure__")
((eq (org-element-type destination) 'latex-environment)
; FIXME: Check if it is
; acutally latex eqn.
"__MathFormula__")
(t (error "Handle enumeration of %S" destination))))) (t (error "Handle enumeration of %S" destination)))))
(org-e-odt-format-label-reference label default-category number))))))) (org-e-odt-format-label-reference label default-category number)))))))
;; Coderef: replace link with the reference name or the ;; Coderef: replace link with the reference name or the
@ -4125,7 +4149,6 @@ contextual information."
(concat preamble (if colgropen "</colgroup>")))) (concat preamble (if colgropen "</colgroup>"))))
(defun org-e-odt-list-table (lines caption label attributes) (defun org-e-odt-list-table (lines caption label attributes)
(setq lines (org-e-odt-org-table-to-list-table lines))
(let* ((splice nil) head (let* ((splice nil) head
(org-e-odt-table-rownum -1) (org-e-odt-table-rownum -1)
i (cnt 0) i (cnt 0)
@ -4208,9 +4231,12 @@ form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
(defun org-e-odt-table (table contents info) (defun org-e-odt-table (table contents info)
"Transcode a TABLE element from Org to HTML. "Transcode a TABLE element from Org to HTML.
CONTENTS is nil. INFO is a plist holding contextual information." CONTENTS is nil. INFO is a plist holding contextual information."
(let* ((label (org-element-property :name table)) (let* ((caption (org-element-property :caption table))
(caption (org-e-odt--caption/label-string (short-caption (and (cdr caption) (org-export-secondary-string
(org-element-property :caption table) label info)) (cdr caption) 'e-odt info)))
(caption (and (car caption) (org-export-secondary-string
(car caption) 'e-odt info)))
(label (org-element-property :name table))
(attr (mapconcat #'identity (attr (mapconcat #'identity
(org-element-property :attr_odt table) (org-element-property :attr_odt table)
" ")) " "))
@ -4230,7 +4256,8 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(genealogy (org-export-get-genealogy table info)) (genealogy (org-export-get-genealogy table info))
(parent (car genealogy)) (parent (car genealogy))
(parent-type (org-element-type parent))) (parent-type (org-element-type parent)))
(org-e-odt-list-table lines caption label attr)))))) (org-e-odt-list-table
(org-e-odt-org-table-to-list-table lines) caption label attr))))))
;;;; Target ;;;; Target
@ -4397,7 +4424,6 @@ Return output file's name."
;;;; org-whitespace ;;;; org-whitespace
;;;; "<span style=\"visibility:hidden;\">%s</span>" ;;;; "<span style=\"visibility:hidden;\">%s</span>"
;;;; Remove display properties ;;;; Remove display properties
;;;; org-e-odt-final-hook
;;;; org-e-odt-with-timestamp ;;;; org-e-odt-with-timestamp
;;;; org-e-odt-html-helper-timestamp ;;;; org-e-odt-html-helper-timestamp