Browse Source

Annotate Dvipng images/Math formula and strengthen error handling

* contrib/lisp/org-odt.el (org-odt-encode-plain-text): New.
(org-odt-format-line)
(org-odt-format-source-code-or-example-plain): Use it.
(org-odt-format-object-description): New.  Format svg:title
and svg:desc elements out of plain text.
(org-export-odt-format-formula, org-export-odt-format-image):
Check whether the incoming formula or image is generated out
of a latex fragment.  If yes, pass the latex fragment for
downstream processing.
(org-odt-format-frame): Check if the object that is enclosed
in the frame has metadata associated with it.  If yes, dump it
as part of svg:title and svg:desc elements.
(org-odt-protect-latex-fragment): New after advice for
`org-format-latex-as-mathml'.  Fixes the following bug
http://lists.gnu.org/archive/html/emacs-orgmode/2011-11/msg00176.html
Jambunathan K 13 years ago
parent
commit
f8168144a9
1 changed files with 42 additions and 12 deletions
  1. 42 12
      contrib/lisp/org-odt.el

+ 42 - 12
contrib/lisp/org-odt.el

@@ -1005,12 +1005,16 @@ styles congruent with the ODF-1.2 specification."
 (defun org-odt-format-horizontal-line ()
   (org-odt-format-stylized-paragraph 'horizontal-line ""))
 
+(defun org-odt-encode-plain-text (line &optional no-whitespace-filling)
+  (setq line (org-xml-encode-plain-text line))
+  (if no-whitespace-filling line
+    (org-odt-fill-tabs-and-spaces line)))
+
 (defun org-odt-format-line (line)
   (case org-lparse-dyn-current-environment
     (fixedwidth (concat
 		 (org-odt-format-stylized-paragraph
-		  'fixedwidth (org-odt-fill-tabs-and-spaces
-			       (org-xml-encode-plain-text line))) "\n"))
+		  'fixedwidth (org-odt-encode-plain-text line)) "\n"))
     (t (concat line "\n"))))
 
 (defun org-odt-format-comment (fmt &rest args)
@@ -1060,10 +1064,9 @@ off."
      (lambda (line)
        (incf i)
        (org-odt-format-source-line-with-line-number-and-label
-	line rpllbl num (lambda (line)
-			  (org-odt-fill-tabs-and-spaces
-			   (org-xml-encode-plain-text line)))
-	(if (= i line-count) "OrgFixedWidthBlockLastLine" "OrgFixedWidthBlock")))
+	line rpllbl num 'org-odt-encode-plain-text
+	(if (= i line-count) "OrgFixedWidthBlockLastLine"
+	  "OrgFixedWidthBlock")))
      lines "\n")))
 
 (defvar org-src-block-paragraph-format
@@ -1263,13 +1266,16 @@ value of `org-export-odt-fontify-srcblocks."
     (let* ((caption (org-find-text-property-in-string 'org-caption src))
 	   (caption (and caption (org-xml-format-desc caption)))
 	   (label (org-find-text-property-in-string 'org-label src))
+	   (latex-frag (org-find-text-property-in-string 'org-latex-src src))
 	   (embed-as (or embed-as
-			 (and (org-find-text-property-in-string
-			       'org-latex-src src)
+			 (and latex-frag
 			      (org-find-text-property-in-string
 			       'org-latex-src-embed-type src))
 			 'paragraph))
 	   width height)
+      (when latex-frag
+	(setq href (org-propertize href :title "LaTeX Fragment"
+				   :description latex-frag)))
       (cond
        ((eq embed-as 'character)
 	(org-odt-format-entity "InlineFormula" href width height))
@@ -1477,11 +1483,11 @@ MAY-INLINE-P allows inlining it as an image."
 	   (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))
-	   (latex-fragment-p (org-find-text-property-in-string
+	   (latex-frag (org-find-text-property-in-string
 			      'org-latex-src src))
-	   (category (and latex-fragment-p "__DvipngImage__"))
+	   (category (and latex-frag "__DvipngImage__"))
 	   (embed-as (or embed-as
-			 (if latex-fragment-p
+			 (if latex-frag
 			     (or (org-find-text-property-in-string
 				  'org-latex-src-embed-type src) 'character)
 			   'paragraph)))
@@ -1491,6 +1497,9 @@ MAY-INLINE-P allows inlining it as an image."
 		  (plist-get attr-plist :height)
 		  (plist-get attr-plist :scale) nil embed-as))
 	   (width (car size)) (height (cdr size)))
+      (when latex-frag
+	(setq href (org-propertize href :title "LaTeX Fragment"
+				   :description latex-frag)))
       (cond
        ((not (or caption label))
 	(case embed-as
@@ -1501,6 +1510,14 @@ MAY-INLINE-P allows inlining it as an image."
 	(org-odt-format-entity
 	 "CaptionedDisplayImage" href width height caption label category))))))
 
+(defun org-odt-format-object-description (title description)
+  (concat (and title (org-odt-format-tags
+		      '("<svg:title>" . "</svg:title>")
+		      (org-odt-encode-plain-text title t)))
+	  (and description (org-odt-format-tags
+			    '("<svg:desc>" . "</svg:desc>")
+			    (org-odt-encode-plain-text description t)))))
+
 (defun org-odt-format-frame (text width height style &optional
 				  extra anchor-type)
   (let ((frame-attrs
@@ -1511,7 +1528,10 @@ MAY-INLINE-P allows inlining it as an image."
 	  (format " text:anchor-type=\"%s\"" (or anchor-type "paragraph")))))
     (org-odt-format-tags
      '("<draw:frame draw:style-name=\"%s\"%s>" . "</draw:frame>")
-     text style frame-attrs)))
+     (concat text (org-odt-format-object-description
+		   (get-text-property 0 :title text)
+		   (get-text-property 0 :description text)))
+     style frame-attrs)))
 
 (defun org-odt-format-textbox (text width height style &optional
 				    extra anchor-type)
@@ -2189,6 +2209,16 @@ using `org-open-file'."
        org-current-export-dir nil display-msg
        nil nil latex-frag-opt))))
 
+(defadvice org-format-latex-as-mathml
+  (after org-odt-protect-latex-fragment activate)
+  "Encode LaTeX fragment as XML.
+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-odt-encode-plain-text (ad-get-arg 0))
+			  'org-protected t))))
+
 (defun org-export-odt-preprocess-latex-fragments ()
   (when (equal org-export-current-backend 'odt)
     (org-export-odt-do-preprocess-latex-fragments)))