From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Leha Subject: patch for latex->tikz Date: Wed, 17 Jul 2013 23:37:41 +0200 Message-ID: <87zjtkeul6.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]:47718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzZRD-0006Pj-Ey for emacs-orgmode@gnu.org; Wed, 17 Jul 2013 17:39:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzZR9-0004WX-9b for emacs-orgmode@gnu.org; Wed, 17 Jul 2013 17:39:07 -0400 Received: from plane.gmane.org ([80.91.229.3]:55679) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzZR9-0004WO-2z for emacs-orgmode@gnu.org; Wed, 17 Jul 2013 17:39:03 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UzZR5-0002g8-Ch for emacs-orgmode@gnu.org; Wed, 17 Jul 2013 23:38:59 +0200 Received: from vpn-2025.gwdg.de ([134.76.2.25]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 17 Jul 2013 23:38:59 +0200 Received: from andreas.leha by vpn-2025.gwdg.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 17 Jul 2013 23:38:59 +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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hi all, attached is a small patch that makes it possible to 'evaluate' latex source blocks to tikz files. When the :file header argument has a value ending in '.tikz' the content of the body of the source block will be copied into the resulting tikz file. This makes handling of tikz figures with captions easier. Here is a use-case: --8<---------------cut here---------------start------------->8--- #+latex_header: \usepackage{tikz} * Test #+name: picturecontents #+begin_src latex :noweb yes :exports none \node[red!50!black] (a) {A}; \node (b) [right of=a] {B}; \draw[->] (a) -- (b); #+end_src #+name: flowdiagram #+header: :exports results #+header: :imagemagick (if (and (boundp 'backend) (eq (org-export-backend-name backend) (intern "latex"))) "no" "yes") #+header: :fit (if (and (boundp 'backend) (eq (org-export-backend-name backend) (intern "latex"))) "no" "yes") #+header: :results raw :file (if (and (boundp 'backend) (eq (org-export-backend-name backend) (intern "latex"))) "flowdiagram.tikz" "flowdiagram.png") #+header: :headers "\\usepackage{tikz}" #+header: :noweb yes #+begin_src latex \begin{tikzpicture} <> \end{tikzpicture} #+end_src #+caption: Testing figure caption for figure going to multiple destinations #+results: flowdiagram [[file:flowdiagram.png]] --8<---------------cut here---------------end--------------->8--- This example works well besides some weird scaling/placement issue. Regards, Andreas --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-add-.tikz-files-as-possible-result-files-for-latex-b.patch Content-Description: small patch for ob-latex.el >From 1d9c381c309a3a72b5d9feb3db28cdaed920c16d Mon Sep 17 00:00:00 2001 From: Andreas Leha Date: Wed, 17 Jul 2013 16:45:32 +0200 Subject: [PATCH] add *.tikz files as possible result files for latex blocks * lisp/ob-latex.el (org-babel-execute:latex) add a tizk option that copies the body of the block into a tikz file --- lisp/ob-latex.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el index f916eb0..f9216e1 100644 --- a/lisp/ob-latex.el +++ b/lisp/ob-latex.el @@ -95,7 +95,11 @@ This function is called by `org-babel-execute-src-block'." ((and (string-match "\\.png$" out-file) (not imagemagick)) (org-create-formula-image body out-file org-format-latex-options in-buffer)) - ((or (string-match "\\.pdf$" out-file) imagemagick) + ((string-match "\\.tikz$" out-file) + (when (file-exists-p out-file) (delete-file out-file)) + (with-temp-file out-file + (insert body))) + ((or (string-match "\\.pdf$" out-file) imagemagick) (with-temp-file tex-file (require 'ox-latex) (insert -- 1.7.10.4 --=-=-=--