Re: [O] tikz for multiple targets

2013-07-16 Thread Eric S Fraga
Hi Eric et al.,

I now have a system I am happy with mostly for using LaTeX code blocks
heading to multiple export targets.  The solution I am using is a
combination of what has been discussed in this thread (by-backend
customisation of headers for babel) and using noweb substitution for the
main content.  I have two LaTeX babel source blocks, one for PDF export
and the other for HTML export.  Each of these has a tikzpicture
environment which then includes the actual instructions for drawing
brought in using noweb.

The problem I have remaining is how to get the version used to export to
PDF via LaTeX to use a figure environment with captioning.  I had
thought that something along these lines would work:

#+begin_src org
  ,#+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 (if (and (boundp 'backend) (eq (org-export-backend-name 
backend) (intern latex))) results none)
  ,#+header: :results latex
  ,#+header: :noweb yes
  ,#+begin_src latex
\begin{tikzpicture}
  picturecontents
\end{tikzpicture}
  ,#+end_src
  
  ,#+caption: Testing figure caption for figure going to multiple destinations
  ,#+results: flowdiagram
#+end_src

as I expected the export to put the results of the flowdiagram code
block after the results line.  This doesn't work: the exported LaTeX
has no figure environment etc.  The diagram does come out but it is
placed directly into the document.

I hope this all makes sense?  Any suggestions?

thanks,
eric
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-337-g9f3bed




Re: [O] tikz for multiple targets

2013-07-16 Thread Andreas Leha
Hi Eric,

Eric S Fraga e.fr...@ucl.ac.uk writes:

 Hi Eric et al.,

 I now have a system I am happy with mostly for using LaTeX code blocks
 heading to multiple export targets.  The solution I am using is a
 combination of what has been discussed in this thread (by-backend
 customisation of headers for babel) and using noweb substitution for the
 main content.  I have two LaTeX babel source blocks, one for PDF export
 and the other for HTML export.  Each of these has a tikzpicture
 environment which then includes the actual instructions for drawing
 brought in using noweb.

 The problem I have remaining is how to get the version used to export to
 PDF via LaTeX to use a figure environment with captioning.  I had
 thought that something along these lines would work:

 #+begin_src org
   ,#+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 (if (and (boundp 'backend) (eq (org-export-backend-name 
 backend) (intern latex))) results none)
   ,#+header: :results latex
   ,#+header: :noweb yes
   ,#+begin_src latex
 \begin{tikzpicture}
   picturecontents
 \end{tikzpicture}
   ,#+end_src
   
   ,#+caption: Testing figure caption for figure going to multiple destinations
   ,#+results: flowdiagram
 #+end_src

 as I expected the export to put the results of the flowdiagram code
 block after the results line.  This doesn't work: the exported LaTeX
 has no figure environment etc.  The diagram does come out but it is
 placed directly into the document.

 I hope this all makes sense?  Any suggestions?

 thanks,
 eric


I actually think, that it would be cool, if latex supported the tikz
output as R does.

But since you have a dedicated latex export-only block, the simplest
solution would be to put the caption inside:

--8---cut here---start-8---
#+latex_header: \usepackage{tikz}
#+latex_header: \usepackage{hyperref}

* 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 (if (and (boundp 'backend) (eq (org-export-backend-name 
backend) (intern latex))) results none)
#+header: :results latex
#+header: :noweb yes
#+begin_src latex
  \begin{figure}
   \begin{tikzpicture}
 picturecontents
   \end{tikzpicture}
   \caption{Testing figure caption for figure going to multiple destinations}
  \end{figure}
#+end_src
--8---cut here---end---8---


Regards,
Andreas




Re: [O] tikz for multiple targets

2013-07-16 Thread Eric S Fraga
Andreas Leha andreas.l...@med.uni-goettingen.de writes:

[...]

 But since you have a dedicated latex export-only block, the simplest
 solution would be to put the caption inside:

D'uh!  That is so obvious (in hindsight ;-) blush...  thanks!  
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-337-g9f3bed




Re: [O] tikz for multiple targets

2013-07-15 Thread Eric S Fraga
Eric Schulte schulte.e...@gmail.com writes:

[...]

 My patch introduced a new variable `org-babel-latex-htlatex-packages'
 which controls the packages added to these latex to SVG code block
 snippets.  The following should work.

   (push {your-package} org-babel-latex-htlatex-packages)

Yes, thanks, I found this soon afterwards by carefully reading your
previous email!

I still have some problems but I think they are due to my various other
customisations.

Thanks again,
eric

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.6-333-gca5623




Re: [O] tikz for multiple targets

2013-07-11 Thread Eric Schulte

 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
   contents
 #+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.

#+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
From 703ccbe2a4aeb87eaef4cfe0af2e9550877d09b0 Mon Sep 17 00:00:00 2001
From: Eric Schulte schulte.e...@gmail.com
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 

Re: [O] tikz for multiple targets

2013-07-11 Thread Eric S Fraga
Andreas Leha andreas.l...@med.uni-goettingen.de writes:

 Hi Eric,


[...]

 I updated the example again.  Try this:

Brilliant.  Thanks.  This works perfectly.  I can see the changes you've
made and they make sense (in hindsight for me) except for the (intern
latex) bit... but this is probably to do with how eq works I guess.

Anyway, thanks again.
eric
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-326-g325e40




Re: [O] tikz for multiple targets

2013-07-11 Thread Rasmus
Eric Schulte schulte.e...@gmail.com writes:


 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.

Looks good to me, although it would make ox-html depend on ox-latex
which may or may not be desirable. . .  For instance math stuff is
handled internally by ox-html, it seems (correct me if I'm wrong).
While TikZ clearly is a LaTeX feature, producing SVGs are more of a
way of support this type of figures in html output, although it
depends on TeX binaries.

File links to tikz files [[file:pix.pgf]] (e.g. produced with R or
matplotlib) won't be understood with this patch.  It should
automatically convert the picture to an svg figure, I think.  Perhaps
support for file links can be added later.

—Rasmus

-- 
In theory, practice and theory are the same. In practice they are not




Re: [O] tikz for multiple targets

2013-07-11 Thread Andreas Leha
Hi Eric,

Eric Schulte schulte.e...@gmail.com writes:


 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
   contents
 #+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.

 #+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
 From 703ccbe2a4aeb87eaef4cfe0af2e9550877d09b0 Mon Sep 17 00:00:00 2001
 From: Eric Schulte schulte.e...@gmail.com
 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
 +

Re: [O] tikz for multiple targets

2013-07-11 Thread Eric Schulte
Eric S Fraga e.fr...@ucl.ac.uk writes:

 Andreas Leha andreas.l...@med.uni-goettingen.de writes:

 Hi Eric,


 [...]

 I updated the example again.  Try this:

 Brilliant.  Thanks.  This works perfectly.  I can see the changes you've
 made and they make sense (in hindsight for me) except for the (intern
 latex) bit... but this is probably to do with how eq works I guess.

 Anyway, thanks again.
 eric

I actually dropped the intern bit from the previous approach.

I'm happy this looks useful, I will go ahead and commit.

-- 
Eric Schulte
http://cs.unm.edu/~eschulte



Re: [O] tikz for multiple targets

2013-07-11 Thread Eric Schulte
Rasmus ras...@gmx.us writes:

 Eric Schulte schulte.e...@gmail.com writes:


 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.

 Looks good to me, although it would make ox-html depend on ox-latex
 which may or may not be desirable. . .  For instance math stuff is
 handled internally by ox-html, it seems (correct me if I'm wrong).
 While TikZ clearly is a LaTeX feature, producing SVGs are more of a
 way of support this type of figures in html output, although it
 depends on TeX binaries.


Nope, this patch only touches ob-latex not ox-latex (easily mistaken
names).


 File links to tikz files [[file:pix.pgf]] (e.g. produced with R or
 matplotlib) won't be understood with this patch.  It should
 automatically convert the picture to an svg figure, I think.  Perhaps
 support for file links can be added later.


Correct.  I think that users of R or gnuplot should use R or gnuplot to
produce SVG or PDF images directly.  I don't think htlatex makes sense
in those use cases.


 —Rasmus

-- 
Eric Schulte
http://cs.unm.edu/~eschulte



Re: [O] tikz for multiple targets

2013-07-11 Thread Eric Schulte

 This is very nice and works well for me.  I would very much like to see
 that in orgmode.  Thanks a lot!


Great, I've just committed this patch.  Thanks for your original example
which this simply extends.


 How do I extend your example to output latex for latex, svg for html and
 png in all other cases?


The attached does this.  The catch is that the :imagemagick header
argument is required for png (and other) image types to be used.

#+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) (pdf 'nil) (t tree.png))
#+header: :imagemagick
#+header: :results (by-backend (pdf latex) (t raw))
#+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

#+RESULTS:
[[file:tree.png]]

* 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

Cheers,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte


Re: [O] tikz for multiple targets

2013-07-11 Thread Andreas Leha
Hi Eric,

Eric Schulte schulte.e...@gmail.com writes:


 This is very nice and works well for me.  I would very much like to see
 that in orgmode.  Thanks a lot!


 Great, I've just committed this patch.  Thanks for your original example
 which this simply extends.


 How do I extend your example to output latex for latex, svg for html and
 png in all other cases?


 The attached does this.  The catch is that the :imagemagick header
 argument is required for png (and other) image types to be used.


thanks for the quick answer.  I am aware, that imagemagick is needed.
Let me rephrase my question using your example:

 #+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) (pdf 'nil) (t tree.png))
 #+header: :imagemagick

I seem not to be able to apply (by-backend ) at the 'top-level, like so:

#+header: (by-backend (html 'nil) (pdf 'nil) (t :imagemagick))

Why is that?

Regards,
Andreas




Re: [O] tikz for multiple targets

2013-07-11 Thread Eric Schulte
 Thanks for the quick answer.  I am aware, that imagemagick is needed.
 Let me rephrase my question using your example:

 #+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) (pdf 'nil) (t tree.png))
 #+header: :imagemagick

 I seem not to be able to apply (by-backend ) at the 'top-level, like so:

 #+header: (by-backend (html 'nil) (pdf 'nil) (t :imagemagick))

 Why is that?


Because elisp evaluation is available for header argument *values*, not
for the entire header argument line.  Instead you could do the
following, or just use the example in my previous email which sets
:imagemagick in all cases.

#+header: :imagemagick (by-backend ((html pdf) 'nil) (t yes))

Cheers,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte



Re: [O] tikz for multiple targets

2013-07-11 Thread Eric S Fraga
Eric Schulte schulte.e...@gmail.com writes:


 This is very nice and works well for me.  I would very much like to see
 that in orgmode.  Thanks a lot!


 Great, I've just committed this patch.  Thanks for your original example
 which this simply extends.

Thanks for this Eric!  I've tried it out just now (on a real document)
and it works well.

I do have a problem in the SVG creation in that I need a special package
included to generate the figure in question.  Time to search on the list
as I think this has come up before for LaTeX snippets.

Thanks again,
eric

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-337-g9f3bed




Re: [O] tikz for multiple targets

2013-07-11 Thread Andreas Leha
Hi Eric,

Eric Schulte schulte.e...@gmail.com writes:

 Thanks for the quick answer.  I am aware, that imagemagick is needed.
 Let me rephrase my question using your example:

 #+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) (pdf 'nil) (t tree.png))
 #+header: :imagemagick

 I seem not to be able to apply (by-backend ) at the 'top-level, like so:

 #+header: (by-backend (html 'nil) (pdf 'nil) (t :imagemagick))

 Why is that?


 Because elisp evaluation is available for header argument *values*, not
 for the entire header argument line.  Instead you could do the
 following, or just use the example in my previous email which sets
 :imagemagick in all cases.

 #+header: :imagemagick (by-backend ((html pdf) 'nil) (t yes))

 Cheers,


I understand.  Thanks a lot for the clarification.

Regards,
Andreas




Re: [O] tikz for multiple targets

2013-07-11 Thread Eric Schulte
Eric S Fraga e.fr...@ucl.ac.uk writes:

 Eric Schulte schulte.e...@gmail.com writes:


 This is very nice and works well for me.  I would very much like to see
 that in orgmode.  Thanks a lot!


 Great, I've just committed this patch.  Thanks for your original example
 which this simply extends.

 Thanks for this Eric!  I've tried it out just now (on a real document)
 and it works well.

 I do have a problem in the SVG creation in that I need a special package
 included to generate the figure in question.  Time to search on the list
 as I think this has come up before for LaTeX snippets.


My patch introduced a new variable `org-babel-latex-htlatex-packages'
which controls the packages added to these latex to SVG code block
snippets.  The following should work.

  (push {your-package} org-babel-latex-htlatex-packages)

-- 
Eric Schulte
http://cs.unm.edu/~eschulte



Re: [O] tikz for multiple targets

2013-07-10 Thread Rasmus
Eric S Fraga e.fr...@ucl.ac.uk 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
 img 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). 
Do not include tikz in headers.

Set standalone-ops to t if you want to use the standalone packages conversion.

  (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) 
convert={outfile=\jobname.svg} standalone-ops
  (when headers
(insert
 (mapconcat (lambda (x)
  (cond ((stringp x) (format \\usepackage{%s} x))
((and (listp x) (= 2 (length x)))
 (apply 'format \\%s{%s} (reverse x))
 )
((and (listp x) (= 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-directory 
/tmp/ fnamet)
(call-process pdf2svg nil *tmp* nil (concat fname .pdf) (concat fname 
.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.

–Rasmus

-- 
The Kids call him Billy the Saint



Re: [O] tikz for multiple targets

2013-07-10 Thread Rasmus
Rasmus ras...@gmx.us writes:

 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.

Actually, dvisvgm might be way to go as it may be possible to leverage
upon all of the dvipng code without much loss of generality.  It would
also be useful for equations where one does not want to use mathjax.
It's only packed for Texlive, though.

 http://www.ctan.org/pkg/dvisvgm

–Rasmus

-- 
May contains speling mistake




Re: [O] tikz for multiple targets

2013-07-10 Thread Fabrice Popineau
And did anybody tried the svg backend available from tikz, rather than
relying
on pdf conversion?

Fabrice



2013/7/10 Rasmus ras...@gmx.us

 Rasmus ras...@gmx.us writes:

  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.

 Actually, dvisvgm might be way to go as it may be possible to leverage
 upon all of the dvipng code without much loss of generality.  It would
 also be useful for equations where one does not want to use mathjax.
 It's only packed for Texlive, though.

  http://www.ctan.org/pkg/dvisvgm

 –Rasmus

 --
 May contains speling mistake





-- 
Fabrice Popineau
-
SUPELEC
Département Informatique
3, rue Joliot Curie
91192 Gif/Yvette Cedex
Tel direct : +33 (0) 169851950
Standard : +33 (0) 169851212
--


Re: [O] tikz for multiple targets

2013-07-10 Thread Eric S Fraga
Rasmus ras...@gmx.us writes:

[...]

 Tikz/pgf works for the latex exporter.  Just insert it as a file link
 (with extension tikz or pgf) or as latex verbatim code.

Yes, thanks.  However, I guess I didn't explain very well what I was
looking for.  

I use tikz all the time and typically enclose it in a #+begin_LaTeX
... #+end_LaTeX block.  That is fine for most of my documents where I
only wish to export to PDF via LaTeX.

However, what I would like is to be able to use the same code, inline
within the org file and not as a separate .tikz file, in some cases to
export to both LaTeX and HTML (or ODT for that matter).  The code in the
link I posted used to do this by dynamically setting the :exports and/or
:results options using org babel headers with emacs lisp code.  A
variation of this worked with the old exporter but doesn't with the new
one.

Thanks again,
eric
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-326-g325e40




Re: [O] tikz for multiple targets

2013-07-10 Thread Andreas Leha
Hi Eric,

Eric S Fraga e.fr...@ucl.ac.uk writes:

 Rasmus ras...@gmx.us writes:

 [...]

 Tikz/pgf works for the latex exporter.  Just insert it as a file link
 (with extension tikz or pgf) or as latex verbatim code.

 Yes, thanks.  However, I guess I didn't explain very well what I was
 looking for.  

 I use tikz all the time and typically enclose it in a #+begin_LaTeX
 ... #+end_LaTeX block.  That is fine for most of my documents where I
 only wish to export to PDF via LaTeX.

 However, what I would like is to be able to use the same code, inline
 within the org file and not as a separate .tikz file, in some cases to
 export to both LaTeX and HTML (or ODT for that matter).  The code in the
 link I posted used to do this by dynamically setting the :exports and/or
 :results options using org babel headers with emacs lisp code.  A
 variation of this worked with the old exporter but doesn't with the new
 one.

 Thanks again,
 eric

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
  contents
#+end_src
--8---cut here---end---8---

Regards,
Andreas




[O] tikz for multiple targets

2013-07-09 Thread Eric S Fraga
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.  For HTML, I would expect the image referred to from an
img tag but I get a link to the test.png file instead.

The actual test.png file is created in both cases.

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!

Thanks,
eric

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org 
release_8.0.5-322-gd5c11e.dirty