summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2013-07-11 00:08:22 -0600
committerEric Schulte <schulte.eric@gmail.com>2013-07-11 10:05:13 -0600
commit9f3bed367b50a9bc218febeb21448c64892d3175 (patch)
tree52e29a472bfb9ff1e005cbd3ceb364a23935cbd4
parent918551cec836b89c4f55bb1acf2626a939b9d1ee (diff)
downloadorg-mode-9f3bed367b50a9bc218febeb21448c64892d3175.tar.gz
optional svg output for latex code blocks
* lisp/ob-latex.el (org-babel-latex-htlatex): Set this variable to "htlatex" (or path to said) to enable svg generation from latex code blocks. (org-babel-latex-htlatex-packages): Libraries required for automatic svg generation. (org-babel-execute:latex): Generate SVG images directly from latex code blocks (assumes tikz).
-rw-r--r--lisp/ob-latex.el44
1 files changed, 44 insertions, 0 deletions
diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index 94d5133..f916eb0 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -50,6 +50,17 @@
'((:results . "latex") (:exports . "results"))
"Default arguments to use when evaluating a LaTeX source block.")
+(defcustom org-babel-latex-htlatex nil
+ "The htlatex command to enable conversion of latex to SVG or HTML."
+ :group 'org-babel
+ :type 'string)
+
+(defcustom org-babel-latex-htlatex-packages
+ '("[usenames]{color}" "{tikz}" "{color}" "{listings}" "{amsmath}")
+ "Packages to use for htlatex export."
+ :group 'org-babel
+ :type '(list string))
+
(defun org-babel-expand-body:latex (body params)
"Expand BODY according to PARAMS, return the expanded body."
(mapc (lambda (pair) ;; replace variables
@@ -124,6 +135,39 @@ This function is called by `org-babel-execute-src-block'."
transient-pdf-file out-file im-in-options im-out-options)
(when (file-exists-p transient-pdf-file)
(delete-file transient-pdf-file))))))
+ ((and (or (string-match "\\.svg$" out-file)
+ (string-match "\\.html$" out-file))
+ org-babel-latex-htlatex)
+ (with-temp-file tex-file
+ (insert (concat
+ "\\documentclass[preview]{standalone}
+\\def\\pgfsysdriver{pgfsys-tex4ht.def}
+"
+ (mapconcat (lambda (pkg)
+ (concat "\\usepackage" pkg))
+ org-babel-latex-htlatex-packages
+ "\n")
+ "\\begin{document}"
+ body
+ "\\end{document}")))
+ (when (file-exists-p out-file) (delete-file out-file))
+ (let ((default-directory (file-name-directory tex-file)))
+ (shell-command (format "%s %s" org-babel-latex-htlatex tex-file)))
+ (cond
+ ((file-exists-p (concat (file-name-sans-extension tex-file) "-1.svg"))
+ (if (string-match "\\.svg$" out-file)
+ (progn
+ (shell-command "pwd")
+ (shell-command (format "mv %s %s"
+ (concat (file-name-sans-extension tex-file) "-1.svg")
+ out-file)))
+ (error "SVG file produced but HTML file requested.")))
+ ((file-exists-p (concat (file-name-sans-extension tex-file) ".html"))
+ (if (string-match "\\.html$" out-file)
+ (shell-command "mv %s %s"
+ (concat (file-name-base tex-file) ".html")
+ out-file)
+ (error "HTML file produced but SVG file requested.")))))
((string-match "\\.\\([^\\.]+\\)$" out-file)
(error "Can not create %s files, please specify a .png or .pdf file or try the :imagemagick header argument"
(match-string 1 out-file))))