Commits

Anonymous committed 0823c47

org-html.el: Handle dvipng

  • Participants
  • Parent commits 24d82eb

Comments (0)

Files changed (1)

File contrib/lisp/org-html.el

     (:html-postamble nil nil org-export-html-postamble)
     (:html-preamble nil nil org-export-html-preamble)
     (:html-table-tag nil nil org-export-html-table-tag)
-    (:xml-declaration nil nil org-export-html-xml-declaration))
+    (:xml-declaration nil nil org-export-html-xml-declaration)
+    (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments))
   "Alist between export properties and ways to set them.
 
 The car of the alist is the property name, and the cdr is a list
   "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
 CONTENTS is nil.  INFO is a plist holding contextual information.
 See `org-element-export-data'."
-  (org-remove-indentation (org-element-get-property :value latex-environment)))
+  (let ((latex-frag
+	 (org-remove-indentation
+	  (org-element-get-property :value latex-environment)))
+	(processing-type (plist-get info :LaTeX-fragments)))
+    (cond
+     ((member processing-type '(t mathjax))
+      (org-html-format-latex latex-frag 'mathjax))
+     ((equal processing-type 'dvipng)
+      (let* ((formula-link (org-html-format-latex
+			    latex-frag processing-type)))
+	(when (and formula-link
+		   (string-match "file:\\([^]]*\\)" formula-link))
+	  (setq formula-file (match-string 1 formula-link))
+	  (org-html-format-inline-image formula-file))))
+     (t
+      latex-frag))))
+
+(defun org-html-format-latex (latex-frag processing-type)
+  (let* ((cache-relpath
+	  (concat "ltxpng/" (file-name-sans-extension
+			     (file-name-nondirectory (buffer-file-name)))))
+	 (cache-dir (file-name-directory (buffer-file-name )))
+	 (display-msg "Creating LaTeX Image..."))
+
+    (with-temp-buffer
+      (insert latex-frag)
+      (org-format-latex cache-relpath cache-dir nil display-msg
+			nil nil processing-type)
+      (buffer-string))))
 
 (defun org-html-latex-fragment (latex-fragment contents info)
   "Transcode a LATEX-FRAGMENT object from Org to HTML.
 		     label)))
 	(org-html-format-internal-link text href)))
      (t
-      latex-frag))))
+      (let ((processing-type (plist-get info :LaTeX-fragments)))
+	(cond
+	 ((member processing-type '(t mathjax))
+	  (org-html-format-latex latex-frag 'mathjax))
+	 ((equal processing-type 'dvipng)
+	  (let* ((formula-link (org-html-format-latex
+				latex-frag processing-type)))
+	    (when (and formula-link
+		       (string-match "file:\\([^]]*\\)" formula-link))
+	      (setq formula-file (match-string 1 formula-link))
+	      (org-html-format-inline-image formula-file))))
+	 (t
+	  latex-frag)))))))
 
 (defun org-html-line-break (line-break contents info)
   "Transcode a LINE-BREAK object from Org to LaTeX.