From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: tikz for multiple targets Date: Wed, 10 Jul 2013 11:50:14 +0200 Message-ID: <87wqoyagmh.fsf@gmx.us> References: <87k3kztlam.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uwr2a-0007XE-GG for emacs-orgmode@gnu.org; Wed, 10 Jul 2013 05:50:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uwr2R-0006tf-4K for emacs-orgmode@gnu.org; Wed, 10 Jul 2013 05:50:28 -0400 Received: from mout.gmx.net ([212.227.17.21]:51352) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uwr2Q-0006tR-R3 for emacs-orgmode@gnu.org; Wed, 10 Jul 2013 05:50:19 -0400 Received: from pank ([213.23.238.209]) by mail.gmx.com (mrgmx002) with ESMTPSA (Nemesis) id 0M08ia-1U2x4744r6-00uFCj for ; Wed, 10 Jul 2013 11:50:16 +0200 In-Reply-To: <87k3kztlam.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Tue, 9 Jul 2013 23:34:25 +0100") 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 Eric S Fraga writes: > Hello again, > > I am trying to get an example that worked with the old exporter to work > with the new exporter. The aim is to have a tikzpicture exported to > both LaTeX and HTML. The example is in the following message from over > a year ago now: > > http://article.gmane.org/gmane.emacs.orgmode/53900 > > This example no longer works for either LaTeX or HTML. For LaTeX, I > would expect the actual tikz code to be inserted into the LaTeX file and > then processed. Instead, I get the file name in a verbatim > environment. Tikz/pgf works for the latex exporter. Just insert it as a file link (with extension tikz or pgf) or as latex verbatim code. > For HTML, I would expect the image referred to from an > tag but I get a link to the test.png file instead. It should be an svg since tikz is a lossless format IMO. Here's a very rough and ugly function to translate tikz to svg. I don't know if there's a more direct approach. . . #+BEGIN_SRC emacs-lisp (defun tikz-to-svg (file &optional headers standalone-ops) "Convert a tikz picture to a svg picture ready for html output. Headers is a string like '(pgfplots '(calc tikzlibrary) (kpfonts usepackage oldstylenums).=20 Do not include tikz in headers. Set standalone-ops to t if you want to use the standalone packages conversi= on. " (let* ((name (file-name-sans-extension (file-name-nondirectory file))) (fname (concat "/tmp/" name)) (fnamet (concat fname ".tex")) (final (concat (file-name-directory file) name ".svg")) ) (with-temp-file fnamet (insert (format "\\documentclass[tikz,%s]{standalone}\n" (if (not standalone-ops) "" (if (eq t standalone-ops)=20 "convert=3D{outfile=3D\jobname.svg}" standalone= -ops)))) (when headers (insert (mapconcat (lambda (x) (cond ((stringp x) (format "\\usepackage{%s}" x)) ((and (listp x) (=3D 2 (length x))) (apply 'format "\\%s{%s}" (reverse x)) ) ((and (listp x) (=3D 3 (length x))) (funcall 'format "\\%s[%s]{%s}" (second x) (third x) (first x)) (t "") ))) "\n"))) (insert "\n\\begin{document}\n") (progn (insert-file file) (goto-char (point-max))) (insert "\n\\end{document}")) (call-process "pdflatex" nil "*tmp*" nil "-shell-escape" "-output-direc= tory /tmp/" fnamet) (call-process "pdf2svg" nil "*tmp*" nil (concat fname ".pdf") (concat f= name ".svg")) (rename-file (concat fname ".svg") final t) (if (file-exists-p final) (format "[[file:%s]]" final) "" (error "conversion failed") ))) #+END_SRC > Is what I want possible with the new exporter? If so, I imagine the > test for the backend must be different now. Any pointers very welcome! It needs to be added to `org-html-inline-image-rules' and some potential translation should be added to org-html-inline-image-p, e.g. substitute pgf or tikz with whatever is the output format. Perhaps the dvipng code in ox-html can utilized to obtain a png seemingly. =E2=80=93Rasmus --=20 The Kids call him Billy the Saint