From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: tikz for multiple targets Date: Thu, 11 Jul 2013 00:11:23 -0600 Message-ID: <878v1d7his.fsf@gmail.com> References: <87k3kztlam.fsf@ucl.ac.uk> <87wqoyagmh.fsf@gmx.us> <87obaa65uu.fsf@ucl.ac.uk> <87ehb62lhe.fsf@med.uni-goettingen.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxA8I-0002Wa-SY for emacs-orgmode@gnu.org; Thu, 11 Jul 2013 02:13:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UxA8H-0000Sk-4e for emacs-orgmode@gnu.org; Thu, 11 Jul 2013 02:13:38 -0400 Received: from mail-pd0-x230.google.com ([2607:f8b0:400e:c02::230]:43651) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxA8G-0000Sa-Qz for emacs-orgmode@gnu.org; Thu, 11 Jul 2013 02:13:37 -0400 Received: by mail-pd0-f176.google.com with SMTP id t12so7076985pdi.7 for ; Wed, 10 Jul 2013 23:13:35 -0700 (PDT) In-Reply-To: <87ehb62lhe.fsf@med.uni-goettingen.de> (Andreas Leha's message of "Wed, 10 Jul 2013 22:44:45 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Andreas Leha Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain > > I updated the example again. Try this: > > --8<---------------cut here---------------start------------->8--- > #+LATEX_HEADER: \usepackage{tikz} > > * Tikz test > #+name: contents > #+header: :exports (if (and (boundp 'backend) (eq (org-export-backend-name backend) (intern "latex"))) "results" "none") > #+header: :results latex > #+begin_src latex > \begin{tikzpicture} > \node[red!50!black] (a) {A}; > \node (b) [right of=a] {B}; > \draw[->] (a) -- (b); > \end{tikzpicture} > #+end_src > > #+header: :exports (if (and (boundp 'backend) (eq (org-export-backend-name backend) (intern "latex"))) "none" "results") > #+header: :results raw :file test.png > #+header: :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 400 > #+header: :fit yes :noweb yes :headers '("\\usepackage{tikz}") > #+begin_src latex > <> > #+end_src > --8<---------------cut here---------------end--------------->8--- > Building from this example, the attached patch to ob-latex.el combined with the attached org-mode file should export the latex (tikz) code as an inline SVG image to HTML and as embedded tikz to latex. If this works generally I can commit the patch to ob-latex.el. --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=tikz-pdf-svg.org #+LATEX_HEADER: \usepackage{tikz} First execute the second code block, to define the convenience macro and to set the required new variables in ob-latex.el. Then export to HTML and to pdf to see the tree exported as an SVG image and as embedded tikz respectively. * Tikz test Here's a tree, exported to both html and pdf. #+header: :file (by-backend (html "tree.svg") (t 'nil)) #+header: :results (by-backend (html "raw") (t "latex")) #+begin_src latex \usetikzlibrary{trees} \begin{tikzpicture} \node [circle, draw, fill=red!20] at (0,0) {1} child { node [circle, draw, fill=blue!30] {2} child { node [circle, draw, fill=green!30] {3} } child { node [circle, draw, fill=yellow!30] {4} }}; \end{tikzpicture} #+end_src * COMMENT setup #+begin_src emacs-lisp :results silent (setq org-babel-latex-htlatex "htlatex") (defmacro by-backend (&rest body) `(case (if (boundp 'backend) (org-export-backend-name backend) nil) ,@body)) #+end_src --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-optional-svg-output-for-latex-code-blocks.patch >From 703ccbe2a4aeb87eaef4cfe0af2e9550877d09b0 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Thu, 11 Jul 2013 00:08:22 -0600 Subject: [PATCH] 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). --- lisp/ob-latex.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) 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)))) -- 1.8.3.2 --=-=-= Content-Type: text/plain Cheers, -- Eric Schulte http://cs.unm.edu/~eschulte --=-=-=--