some enhancement
This commit is contained in:
parent
16a2d8d290
commit
8cdf1ea3c0
@ -90,37 +90,42 @@
|
||||
|
||||
(defun tikz-shell-command (dir cmd)
|
||||
(shell-command (concat "/bin/sh " " -c "
|
||||
"\" cd " dir ";"
|
||||
cmd "\"")))
|
||||
"\" cd " dir ";"
|
||||
cmd "\"")))
|
||||
|
||||
(defun tikz-script (fmt tikz-libs body)
|
||||
(defun tikz-script (fmt tikz-libs gd-libs body)
|
||||
(setq tikz-prologues
|
||||
(concat "\\documentclass{article}\n"
|
||||
"\\usepackage{tikz}\n"
|
||||
"%%\\usepackage{pgfplots}\n"
|
||||
(if tikz-libs
|
||||
(concat "\\usetikzlibrary{"
|
||||
tikz-libs
|
||||
"}\n")
|
||||
"")
|
||||
"\\begin{document}\n"
|
||||
"\\begin{tikzpicture}"))
|
||||
(concat "\\documentclass{article}\n"
|
||||
"\\usepackage{tikz}\n"
|
||||
"%%\\usepackage{pgfplots}\n"
|
||||
(if tikz-libs
|
||||
(concat "\\usetikzlibrary{"
|
||||
tikz-libs
|
||||
"}\n")
|
||||
"")
|
||||
(if gd-libs
|
||||
(concat "\\usegdlibrary{"
|
||||
gd-libs
|
||||
"}\n")
|
||||
"")
|
||||
"\\begin{document}\n"
|
||||
"\\begin{tikzpicture}"))
|
||||
|
||||
(setq tikz-script-data (concat body
|
||||
"\n\\end{tikzpicture}\n"
|
||||
"\\end{document}\n"))
|
||||
"\n\\end{tikzpicture}\n"
|
||||
"\\end{document}\n"))
|
||||
(message "%s" (concat tikz-prologues tikz-script-data))
|
||||
(concat tikz-prologues tikz-script-data))
|
||||
|
||||
(defun tikz-post-run (fmt in-file out-file)
|
||||
(tikz-shell-command "."
|
||||
(concat org-tikz-convert " "
|
||||
(concat org-babel-temporary-directory "/"
|
||||
(file-name-nondirectory in-file)
|
||||
".pdf")
|
||||
" "
|
||||
out-file)))
|
||||
|
||||
(concat org-tikz-convert " "
|
||||
(concat org-babel-temporary-directory "/"
|
||||
(file-name-nondirectory in-file)
|
||||
".pdf")
|
||||
" "
|
||||
out-file)))
|
||||
|
||||
;;;###autoload
|
||||
(defun org-babel-execute:tikz (body params)
|
||||
"Execute a block of Tikz code.
|
||||
@ -133,17 +138,25 @@ This function is called by `org-babel-execute-src-block'."
|
||||
"pdf"))
|
||||
(cmdline (cdr (assoc :cmdline params)))
|
||||
(in-file (org-babel-temp-file "tikz-"))
|
||||
(latex-engine
|
||||
(let ((engine (tikz-get-value-by-name 'latex-engine
|
||||
(org-babel--get-vars params))))
|
||||
(if engine
|
||||
engine
|
||||
org-tikz-program)))
|
||||
(cmd
|
||||
(concat (concat org-tikz-program " -shell-escape ")
|
||||
(org-babel-process-file-name in-file)
|
||||
)))
|
||||
(concat (concat latex-engine " -shell-escape ")
|
||||
(org-babel-process-file-name (concat in-file ".tex"))
|
||||
)))
|
||||
(with-temp-file (concat in-file ".tex")
|
||||
(insert (tikz-script format
|
||||
(tikz-get-value-by-name 'tikz-libs
|
||||
(org-babel--get-vars params))
|
||||
(org-babel-expand-body:generic
|
||||
body params
|
||||
(org-babel-variable-assignments:tikz params)))))
|
||||
(tikz-get-value-by-name 'tikz-libs
|
||||
(org-babel--get-vars params))
|
||||
(tikz-get-value-by-name 'gd-libs
|
||||
(org-babel--get-vars params))
|
||||
(org-babel-expand-body:generic
|
||||
body params
|
||||
(org-babel-variable-assignments:tikz params)))))
|
||||
(message cmd)
|
||||
(tikz-shell-command org-babel-temporary-directory cmd)
|
||||
(tikz-post-run format in-file out-file)
|
||||
@ -164,7 +177,7 @@ Tikz does not support sessions"
|
||||
(defun tikz-get-value-by-name (name vpairs)
|
||||
(let ((vp (assoc name vpairs)))
|
||||
(if vp
|
||||
(cdr vp)
|
||||
(cdr vp)
|
||||
nil)))
|
||||
|
||||
(defun org-babel-tikz-var-value (val)
|
||||
@ -185,16 +198,16 @@ The type is `string' if any element in DATA is
|
||||
a string. Otherwise, it is either `numeric', if some elements are
|
||||
floats, or `numeric'."
|
||||
(let* ((type 'numeric)
|
||||
find-type ; for byte-compiler
|
||||
(find-type
|
||||
(function
|
||||
(lambda (row)
|
||||
(catch 'exit
|
||||
(mapc (lambda (el)
|
||||
(cond ((listp el) (funcall find-type el))
|
||||
((stringp el) (throw 'exit (setq type 'string)))
|
||||
((floatp el) (setq type 'numeric))))
|
||||
row))))))
|
||||
find-type ; for byte-compiler
|
||||
(find-type
|
||||
(function
|
||||
(lambda (row)
|
||||
(catch 'exit
|
||||
(mapc (lambda (el)
|
||||
(cond ((listp el) (funcall find-type el))
|
||||
((stringp el) (throw 'exit (setq type 'string)))
|
||||
((floatp el) (setq type 'numeric))))
|
||||
row))))))
|
||||
(funcall find-type data) type))
|
||||
|
||||
(provide 'ob-tikz)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user