# Re: [O] Embedding diagrams in Org

Hi Marcin,

see some inline comments.  Note, that I have not done much research
on this and all my information may be outdated....

Marcin Borkowski <mb...@wmi.amu.edu.pl> writes:
> On 2015-02-18, at 20:37, Andreas Leha <andreas.l...@med.uni-goettingen.de>
> wrote:
>
>> I also use tikz in my org files.  I just include a slightly more
>> involved version of Eric's example to show some of the beauty of org.
>
> OK, so I'm trying to understand it.  (One of the reasons is that it
> doesn't work for me; somehow I couldn't get the svg export for inclusion
> in HTML.  OTOH, conversion using pdf2svg does work for me (in LaTeX
> files), so I want to learn how to utilize it for Org-mode.)
>
>> This includes a caption for the diagram, and different output formats
>> for different export routes.
>>
>> Best,
>> Andreas
>>
>> --8<---------------cut here---------------start------------->8---
>>
>> * tikz example
>>
>> #+name: tikz_example
>
> What does the above line do exactly?
>

This will ensure, that the produced latex file for the diagram loads
tikz.  I could not find that documented, so maybe that should be
replaced by ':headers '("\\usepackage{tikz}")'.  In my first tests it
now seems unnecessary, maybe due to a change in the semantics of

So, I guess you can omit that altogether.

>> #+header: :file (by-backend (latex "example_diagram.tikz") (html
>> "example_diagram.svg") (t "example_diagram.png"))
>
> The manual says that after :file I can have a string or a list of two
> strings.  Does the above mean that it is in fact macroexpanded?

The argument of any header option can be replaced by an elisp form
(which then in this case should return a string or a list of two
strings).

>  Do
> I get it correctly that the (t "example_diagram.png") refers to manual
> evaluation and not the evaluation during the export?

Yes.  I use that to be able to see the diagram within the org document.

>
>> #+header: :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry
>> 800
>> #+begin_src latex
>>   \begin{tikzpicture}
>>     \node[red!50!black] (a) {A};
>>     \node (b) [right of=a] {B};
>>     \draw[->] (a) -- (b);
>>   \end{tikzpicture}
>> #+end_src
>
> And, last but not least: how exactly the magic of tikz -> svg is
> supposed to work here?  Do I get it correctly that in you example,
> Imagemagick handles both png and svg?

Yes, imagemagick does both here.  And there is a bug in imagemagick up
to 6.9 producing corrupt svg [1].  I guess that is hitting you.  Try

> What if I want to use pdf2svg

I do not think that this is possible right now.

BUT:

You can use htlatex.

If you look at worg [2], you'll find an example demonstrating that.
It mainly requires setting
'(setq org-babel-latex-htlatex "htlatex")'.

I think that possibility might make pdf2svg unnecessary.

BUT 2:

This won't have an effect on the example in this thread.

I consider it a bug that the example I gave in this thread tries to run
imagemagick for the svg even if that variable is set to "htlatex".  I'll
file a bug report in a separate thread.

>
>> #+caption: A tikz example diagram with a caption
>> #+results: tikz_example
>> [[file:example_diagram.png]]
>> --8<---------------cut here---------------end--------------->8---
>
> TIA,

HTH,
Andreas

Footnotes:

[1] http://www.imagemagick.org/discourse-server/viewtopic.php?t=27009

[2]
http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html#sec-4-3