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