Browse Source

org-odt.el: Support for captioning and labelling of equation images

* contrib/lisp/org-lparse.el (org-do-lparse): let-bind
org-lparse-opt-plist to current export options.
* contrib/lisp/org-odt.el
(org-odt-begin-office-body): Add a directive so that Equations
can be sequentially numbered.
(org-export-odt-preprocess): Removed call to
org-export-odt-preprocess-latex-fragments.
(org-export-odt-preprocess-latex-fragments): Fix signature and
hook it to org-export-preprocess-after-blockquote-hook. Use
org-lparse-opt-plist.
(org-odt-unload-function): Leave no trace in
org-export-preprocess-after-blockquote-hook.

Thanks to Myles English for registering this requirement.
http://lists.gnu.org/archive/html/emacs-orgmode/2011-08/msg01116.html
Jambunathan K 13 years ago
parent
commit
3688deeb3f
2 changed files with 34 additions and 23 deletions
  1. 1 0
      contrib/lisp/org-lparse.el
  2. 33 23
      contrib/lisp/org-odt.el

+ 1 - 0
contrib/lisp/org-lparse.el

@@ -847,6 +847,7 @@ version."
 	 (org-export-footnotes-seen nil)
 	 (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
 	 (org-footnote-insert-pos-for-preprocessor 'point-min)
+	 (org-lparse-opt-plist opt-plist)
 	 (lines
 	  (org-split-string
 	   (org-export-preprocess-string

+ 33 - 23
contrib/lisp/org-odt.el

@@ -143,8 +143,9 @@ OpenDocument xml files.")
 (org-lparse-register-backend 'odt)
 
 (defun org-odt-unload-function ()
-  ;; notify org-lparse library on unload
   (org-lparse-unregister-backend 'odt)
+  (remove-hook 'org-export-preprocess-after-blockquote-hook
+	       'org-export-odt-preprocess-latex-fragments)
   nil)
 
 (defcustom org-export-odt-automatic-styles-file nil
@@ -435,6 +436,7 @@ PUB-DIR is set, use this as the publishing directory."
 	<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Table\"/>
 	<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Text\"/>
 	<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Drawing\"/>
+	<text:sequence-decl text:display-outline-level=\"0\" text:name=\"Equation\"/>
       </text:sequence-decls>"))
 
 ;; Following variable is let bound when `org-do-lparse' is in
@@ -1648,29 +1650,28 @@ visually."
        (substring label (match-beginning 1))))))
 
 (defvar org-lparse-latex-fragment-fallback) ; set by org-do-lparse
-(defun org-export-odt-preprocess-latex-fragments (parameters)
+(defvar org-lparse-opt-plist)		    ; bound during org-do-lparse
+(defun org-export-odt-preprocess-latex-fragments ()
   "Convert LaTeX fragments to images."
-  (when (and org-current-export-file
-	     (plist-get parameters :LaTeX-fragments))
-    (org-format-latex
-     (concat "ltxpng/" (file-name-sans-extension
-			(file-name-nondirectory
-			 org-current-export-file)))
-     org-current-export-dir nil "Creating LaTeX image %s"
-     nil nil
-     (cond
-      ((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
+  (let* ((latex-frag-opt (plist-get org-lparse-opt-plist :LaTeX-fragments))
+	 (latex-frag-opt-1		;  massage the options
+	  (or (and (member latex-frag-opt '(mathjax t))
+		   (prog1 org-lparse-latex-fragment-fallback
+		     (org-lparse-warn
+		      (concat
+		       "Use of MathJax is incompatible with ODT exporter. "
+		       (format "Using %S instead."
+			       org-lparse-latex-fragment-fallback)))))
+	      latex-frag-opt)))
+    (when (and org-current-export-file latex-frag-opt-1)
       ;; Investigate MathToWeb for converting TeX equations to MathML
-      ;; See http://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01755.html
-      ((or (eq (plist-get parameters :LaTeX-fragments) 'mathjax )
-	   (eq (plist-get parameters :LaTeX-fragments) t        ))
-       (org-lparse-warn
-	(concat
-	 "Use of MathJax is incompatible with ODT exporter. "
-	 (format "Using %S instead."  org-lparse-latex-fragment-fallback)))
-	 org-lparse-latex-fragment-fallback)
-      ((eq (plist-get parameters :LaTeX-fragments) 'dvipng  ) 'dvipng)
-      (t nil)))))
+      ;; http://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01755.html
+      (org-format-latex
+       (concat "ltxpng/" (file-name-sans-extension
+			  (file-name-nondirectory
+			   org-current-export-file)))
+       org-current-export-dir nil "Creating LaTeX image %s"
+       nil nil latex-frag-opt-1))))
 
 (defun org-export-odt-preprocess-label-references ()
   (goto-char (point-min))
@@ -1688,8 +1689,17 @@ visually."
 	    '("<text:sequence-ref text:reference-format=\"category-and-value\" text:ref-name=\"%s\">"
 	      . "</text:sequence-ref>") pretty-label label)) t t)))))
 
+;; process latex fragments as part of
+;; `org-export-preprocess-after-blockquote-hook'. Note that this hook
+;; is the one that is closest and well before the call to
+;; `org-export-attach-captions-and-attributes' in
+;; `org-export-preprocess-stirng'.  The above arrangement permits
+;; captions, labels and attributes to be attached to png images
+;; generated out of latex equations.
+(add-hook 'org-export-preprocess-after-blockquote-hook
+	  'org-export-odt-preprocess-latex-fragments)
+
 (defun org-export-odt-preprocess (parameters)
-  (org-export-odt-preprocess-latex-fragments parameters)
   (org-export-odt-preprocess-label-references))
 
 (declare-function archive-zip-extract "arc-mode.el" (archive name))