summaryrefslogtreecommitdiff
path: root/lisp/ob-latex.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ob-latex.el')
-rw-r--r--lisp/ob-latex.el96
1 files changed, 59 insertions, 37 deletions
diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index 35b6650..4efa78d 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -50,7 +50,18 @@
'((:results . "latex") (:exports . "results"))
"Default arguments to use when evaluating a LaTeX source block.")
-(defcustom org-babel-latex-htlatex ""
+(defconst org-babel-header-args:latex
+ '((border . :any)
+ (fit . :any)
+ (iminoptions . :any)
+ (imoutoptions . :any)
+ (packages . :any)
+ (pdfheight . :any)
+ (pdfpng . :any)
+ (pdfwidth . :any))
+ "LaTeX-specific header arguments.")
+
+(defcustom org-babel-latex-htlatex "htlatex"
"The htlatex command to enable conversion of latex to SVG or HTML."
:group 'org-babel
:type 'string)
@@ -99,6 +110,51 @@ This function is called by `org-babel-execute-src-block'."
(when (file-exists-p out-file) (delete-file out-file))
(with-temp-file out-file
(insert body)))
+ ((and (or (string-match "\\.svg$" out-file)
+ (string-match "\\.html$" out-file))
+ (executable-find org-babel-latex-htlatex))
+ ;; TODO: this is a very different way of generating the
+ ;; frame latex document than in the pdf case. Ideally, both
+ ;; would be unified. This would prevent bugs creeping in
+ ;; such as the one fixed on Aug 16 2014 whereby :headers was
+ ;; not included in the SVG/HTML case.
+ (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")
+ (if headers
+ (concat "\n"
+ (if (listp headers)
+ (mapconcat #'identity headers "\n")
+ headers) "\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-sans-extension tex-file)
+ ".html")
+ out-file)
+ (error "HTML file produced but SVG file requested")))))
((or (string-match "\\.pdf$" out-file) imagemagick)
(with-temp-file tex-file
(require 'ox-latex)
@@ -135,51 +191,17 @@ This function is called by `org-babel-execute-src-block'."
((string-match "\\.pdf$" out-file)
(rename-file transient-pdf-file out-file))
(imagemagick
- (convert-pdf
+ (org-babel-latex-convert-pdf
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))
- (not (string= "" 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-sans-extension 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))))
nil) ;; signal that output has already been written to file
body))
-(defun convert-pdf (pdffile out-file im-in-options im-out-options)
+(defun org-babel-latex-convert-pdf (pdffile out-file im-in-options im-out-options)
"Generate a file from a pdf file using imagemagick."
(let ((cmd (concat "convert " im-in-options " " pdffile " "
im-out-options " " out-file)))