all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Embedding diagrams in Org
@ 2015-02-18 12:34 Marcin Borkowski
  2015-02-18 14:19 ` Eric S Fraga
  2015-03-04 19:19 ` Marcin Borkowski
  0 siblings, 2 replies; 19+ messages in thread
From: Marcin Borkowski @ 2015-02-18 12:34 UTC (permalink / raw)
  To: Org-Mode mailing list

Hello all,

I need to embed some diagrams (graphs of functions, for instance, or
trees) in an Org file.  Any suggestions on how to do it?  In case of
ditaa, I can use a source block and the "results" line, and see the
image with C-c C-x C-v.  Can I do a similar thing with Asymptote?  How
hard/time-consuming would it be to add support e.g. for tikz or other
such tools?

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-18 12:34 Embedding diagrams in Org Marcin Borkowski
@ 2015-02-18 14:19 ` Eric S Fraga
  2015-02-18 15:51   ` Eduardo Ochs
                     ` (2 more replies)
  2015-03-04 19:19 ` Marcin Borkowski
  1 sibling, 3 replies; 19+ messages in thread
From: Eric S Fraga @ 2015-02-18 14:19 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Org-Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 725 bytes --]

On Wednesday, 18 Feb 2015 at 13:34, Marcin Borkowski wrote:
> Hello all,
>
> I need to embed some diagrams (graphs of functions, for instance, or
> trees) in an Org file.  Any suggestions on how to do it?  In case of
> ditaa, I can use a source block and the "results" line, and see the
> image with C-c C-x C-v.  Can I do a similar thing with Asymptote?  How
> hard/time-consuming would it be to add support e.g. for tikz or other
> such tools?

Support for tikz is there implicitly in that there is support for
LaTeX.  I use tikz all the time.

Simple example attached.

I do believe others have used asymptote in the past.

HTH,
eric
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org release_8.3beta-843-ga5f1a3.dirty

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: t.org --]
[-- Type: text/x-org, Size: 474 bytes --]

#+latex_header: \usepackage{tikz}
* tikz with babel
This example generates a figure using tikz and exports it as raw latex

#+begin_src latex :results latex raw :exports results
  \begin{tikzpicture}
    \node[red!50!black] (a) {A};
    \node (b) [right of=a] {B};
    \draw[->] (a) -- (b);
  \end{tikzpicture}
#+end_src

Alternatively, you can put tikz inline:
#+latex: \tikz \draw[rotate=30] (0,0) ellipse (6pt and 3pt);
which should appear in the middle of the sentence.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-18 14:19 ` Eric S Fraga
@ 2015-02-18 15:51   ` Eduardo Ochs
  2015-02-18 19:01     ` Eric S Fraga
  2015-02-18 19:37   ` Andreas Leha
  2015-02-24  0:01   ` Marcin Borkowski
  2 siblings, 1 reply; 19+ messages in thread
From: Eduardo Ochs @ 2015-02-18 15:51 UTC (permalink / raw)
  To: Org-Mode mailing list, Eric S Fraga

On Wed, Feb 18, 2015 at 12:19 PM, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:
> On Wednesday, 18 Feb 2015 at 13:34, Marcin Borkowski wrote:
>> Hello all,
>>
>> I need to embed some diagrams (graphs of functions, for instance, or
>> trees) in an Org file.  Any suggestions on how to do it?  In case of
>> ditaa, I can use a source block and the "results" line, and see the
>> image with C-c C-x C-v.  Can I do a similar thing with Asymptote?  How
>> hard/time-consuming would it be to add support e.g. for tikz or other
>> such tools?
>
> Support for tikz is there implicitly in that there is support for
> LaTeX.  I use tikz all the time.
>
> Simple example attached.
>
> I do believe others have used asymptote in the past.
>
> HTH,
> eric
> --
> : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org release_8.3beta-843-ga5f1a3.dirty

Hi Eric,

I tested your example - with `C-c C-e l o' to export to LaTeX and open
the PDF file -, and the ellipse in the middle of the sentence appeared,
but the block

#+begin_src latex :results latex raw :exports results
  \begin{tikzpicture}
    \node[red!50!black] (a) {A};
    \node (b) [right of=a] {B};
    \draw[->] (a) -- (b);
  \end{tikzpicture}
#+end_src

did not make its way to the t.tex file... I asked for help in the
#org-mode channel at freenode, as I am an Org newbie, and found a fix.
Your example is one of the best one I've seen so far of diagrams-
in-Org-for-newbies, but it seems to be at least one micro-bug from
perfect, as it supposes that the person trying it has already enabled
latex support in babel!

Here is an idea to make your example more newbie-friendly: add the
comments below to it.

# Note that you may have to add latex support to babel
# to make the tikzpicture block work...
# see: (info "(org)Languages")
# try: (org-babel-do-load-languages 'org-babel-load-languages '((latex . t)))
#
# To disable to question "Evaluate this latex code block on your system?",
# see: (info "(org)Code evaluation security")
# try: (setq org-confirm-babel-evaluate nil)

Cheers =),
  Eduardo Ochs
  eduardoochs@gmail.com
  http://angg.twu.net/
  http://angg.twu.net/eev-intros/find-eval-intro.html

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-18 15:51   ` Eduardo Ochs
@ 2015-02-18 19:01     ` Eric S Fraga
  2015-02-19  8:45       ` Sebastien Vauban
  0 siblings, 1 reply; 19+ messages in thread
From: Eric S Fraga @ 2015-02-18 19:01 UTC (permalink / raw)
  To: Eduardo Ochs; +Cc: Org-Mode mailing list

On Wednesday, 18 Feb 2015 at 13:51, Eduardo Ochs wrote:

[...]

> perfect, as it supposes that the person trying it has already enabled
> latex support in babel!

You mean people don't automatically have this enabled already?  ;-)

But, yes, you are correct!  My org customisations are so many that I
forget what are defaults and what are not.

I'm glad that you got help from #org-mode; I actually have that channel
in another emacs window but I wasn't looking at it.  I keep telling myself
to get another monitor but there isn't room for a third one on my desk
:(

I do wonder, however, why we need to turn languages on or off?  It would
be nice if org-babel would do this automatically when a language
specific src block is encountered...

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org release_8.3beta-843-ga5f1a3.dirty

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-18 14:19 ` Eric S Fraga
  2015-02-18 15:51   ` Eduardo Ochs
@ 2015-02-18 19:37   ` Andreas Leha
  2015-02-19  8:49     ` Sebastien Vauban
                       ` (2 more replies)
  2015-02-24  0:01   ` Marcin Borkowski
  2 siblings, 3 replies; 19+ messages in thread
From: Andreas Leha @ 2015-02-18 19:37 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> On Wednesday, 18 Feb 2015 at 13:34, Marcin Borkowski wrote:
>> Hello all,
>>
>> I need to embed some diagrams (graphs of functions, for instance, or
>> trees) in an Org file.  Any suggestions on how to do it?  In case of
>> ditaa, I can use a source block and the "results" line, and see the
>> image with C-c C-x C-v.  Can I do a similar thing with Asymptote?  How
>> hard/time-consuming would it be to add support e.g. for tikz or other
>> such tools?
>
> Support for tikz is there implicitly in that there is support for
> LaTeX.  I use tikz all the time.
>
> Simple example attached.
>
> I do believe others have used asymptote in the past.
>
> HTH,
> eric


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.

This includes a caption for the diagram, and different output formats
for different export routes.

Best,
Andreas

--8<---------------cut here---------------start------------->8---
#+LATEX_HEADER: \usepackage{tikz}

* tikz example

#+name: tikz_example
#+header: :packages '(("" "tikz"))
#+header: :file (by-backend (latex "example_diagram.tikz") (html "example_diagram.svg") (t "example_diagram.png"))
#+header: :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 800
#+header: :results file raw
#+header: :fit yes
#+begin_src latex
  \begin{tikzpicture}
    \node[red!50!black] (a) {A};
    \node (b) [right of=a] {B};
    \draw[->] (a) -- (b);
  \end{tikzpicture}
#+end_src

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-18 19:01     ` Eric S Fraga
@ 2015-02-19  8:45       ` Sebastien Vauban
  0 siblings, 0 replies; 19+ messages in thread
From: Sebastien Vauban @ 2015-02-19  8:45 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Eric S Fraga wrote:
> I do wonder, however, why we need to turn languages on or off?  It
> would be nice if org-babel would do this automatically when a language
> specific src block is encountered...

That'd make some sense, indeed... Kind of autoloads for all the
languages...

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-18 19:37   ` Andreas Leha
@ 2015-02-19  8:49     ` Sebastien Vauban
  2015-02-21 11:06       ` Andreas Leha
  2015-02-19 14:10     ` Eric S Fraga
  2015-03-21 11:23     ` Marcin Borkowski
  2 siblings, 1 reply; 19+ messages in thread
From: Sebastien Vauban @ 2015-02-19  8:49 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Andreas,

Andreas Leha 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.
>
> This includes a caption for the diagram, and different output formats
> for different export routes.
>
> #+LATEX_HEADER: \usepackage{tikz}
>
> * tikz example
>
> #+name: tikz_example
> #+header: :packages '(("" "tikz"))
> #+header: :file (by-backend (latex "example_diagram.tikz") (html "example_diagram.svg") (t "example_diagram.png"))

Where is the `by-backend' function defined?

> #+header: :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 800
> #+header: :results file raw
> #+header: :fit yes
> #+begin_src latex
>   \begin{tikzpicture}
>     \node[red!50!black] (a) {A};
>     \node (b) [right of=a] {B};
>     \draw[->] (a) -- (b);
>   \end{tikzpicture}
> #+end_src
>
> #+caption: A tikz example diagram with a caption
> #+results: tikz_example
> [[file:example_diagram.png]]

What'd be nice is that you could say (in a *file* property) that the
extension for LaTeX always has to be .tikz, for HTML .svg and .png in
all the other cases.

Then, you could simply give the base name of the figure where
appropriate, in a "DRY" configuration.

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-18 19:37   ` Andreas Leha
  2015-02-19  8:49     ` Sebastien Vauban
@ 2015-02-19 14:10     ` Eric S Fraga
  2015-03-21 11:23     ` Marcin Borkowski
  2 siblings, 0 replies; 19+ messages in thread
From: Eric S Fraga @ 2015-02-19 14:10 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

On Wednesday, 18 Feb 2015 at 19:37, Andreas Leha 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.

Thanks for adding to the example.  Your "by-backend" function looks
useful.  Would you post it to the list please?  I've done something
similar via nested if's but your approach is much cleaner.

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org release_8.3beta-843-ga5f1a3.dirty

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-19  8:49     ` Sebastien Vauban
@ 2015-02-21 11:06       ` Andreas Leha
  0 siblings, 0 replies; 19+ messages in thread
From: Andreas Leha @ 2015-02-21 11:06 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Sebastien Vauban <sva-news@mygooglest.com> writes:
> Hello Andreas,
>
> Andreas Leha 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.
>>
>> This includes a caption for the diagram, and different output formats
>> for different export routes.
>>
>> #+LATEX_HEADER: \usepackage{tikz}
>>
>> * tikz example
>>
>> #+name: tikz_example
>> #+header: :packages '(("" "tikz"))
>> #+header: :file (by-backend (latex "example_diagram.tikz") (html "example_diagram.svg") (t "example_diagram.png"))
>
> Where is the `by-backend' function defined?
>

Sorry, I thought the by-backend function was 'common wisdom' by now.
It's been proposed by Eric Schulte and there has been a short discussion
about including it in org proper.  Here it is:

--8<---------------cut here---------------start------------->8---
(defmacro by-backend (&rest body)
  `(case (if (boundp 'backend) (org-export-backend-name backend) nil) ,@body))
--8<---------------cut here---------------end--------------->8---


And I forgot to add:  For the SVG export in html you might need to set

--8<---------------cut here---------------start------------->8---
(setq org-babel-latex-htlatex "htlatex")
--8<---------------cut here---------------end--------------->8---



>> #+header: :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 800
>> #+header: :results file raw
>> #+header: :fit yes
>> #+begin_src latex
>>   \begin{tikzpicture}
>>     \node[red!50!black] (a) {A};
>>     \node (b) [right of=a] {B};
>>     \draw[->] (a) -- (b);
>>   \end{tikzpicture}
>> #+end_src
>>
>> #+caption: A tikz example diagram with a caption
>> #+results: tikz_example
>> [[file:example_diagram.png]]
>
> What'd be nice is that you could say (in a *file* property) that the
> extension for LaTeX always has to be .tikz, for HTML .svg and .png in
> all the other cases.

I agree.  Especially if that setup should be applied to every figure in
the document, the header repetitions are tedious.  I do not have a
solution, I am afraid.

>
> Then, you could simply give the base name of the figure where
> appropriate, in a "DRY" configuration.

I'd love to see that, too.

Best,
Andreas

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-18 14:19 ` Eric S Fraga
  2015-02-18 15:51   ` Eduardo Ochs
  2015-02-18 19:37   ` Andreas Leha
@ 2015-02-24  0:01   ` Marcin Borkowski
  2015-02-24  8:04     ` Eric S Fraga
  2 siblings, 1 reply; 19+ messages in thread
From: Marcin Borkowski @ 2015-02-24  0:01 UTC (permalink / raw)
  To: Org-Mode mailing list


On 2015-02-18, at 15:19, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:

> Support for tikz is there implicitly in that there is support for
> LaTeX.  I use tikz all the time.

Yes, but I wanted to be able both to see the diagram in the Org file
itself /and/ to export it properly to LaTeX.  (It seems that your
solutions did support both these things, though.  Thanks!)

> Simple example attached.

I have one question.

> #+begin_src latex :results latex raw :exports results

Why ":results latex raw" and not ":results latex"?

> HTH,
> eric

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-24  0:01   ` Marcin Borkowski
@ 2015-02-24  8:04     ` Eric S Fraga
  2015-02-24 17:00       ` Charles C. Berry
  0 siblings, 1 reply; 19+ messages in thread
From: Eric S Fraga @ 2015-02-24  8:04 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Org-Mode mailing list

On Tuesday, 24 Feb 2015 at 01:01, Marcin Borkowski wrote:

[...]

> I have one question.
>
>> #+begin_src latex :results latex raw :exports results
>
> Why ":results latex raw" and not ":results latex"?

I have no idea ;-)

I find, unfortunately, that getting babel to do what I want is somewhat
of an arcane art (for me) so once I get something doing what I want it
to do, I leave things alone...

I'm sure it all makes sense but it's probably a case of my not having
the time to figure things out properly.  When I need to get something
done, it's often because I need it *now* (or yesterday :-).

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org release_8.3beta-843-ga5f1a3.dirty

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-24  8:04     ` Eric S Fraga
@ 2015-02-24 17:00       ` Charles C. Berry
  2015-03-05  8:51         ` Sebastien Vauban
  0 siblings, 1 reply; 19+ messages in thread
From: Charles C. Berry @ 2015-02-24 17:00 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: Org-Mode mailing list, Marcin Borkowski

On Tue, 24 Feb 2015, Eric S Fraga wrote:

> On Tuesday, 24 Feb 2015 at 01:01, Marcin Borkowski wrote:
>
> [...]
>
>> I have one question.
>>
>>> #+begin_src latex :results latex raw :exports results
>>
>> Why ":results latex raw" and not ":results latex"?
>
> I have no idea ;-)
>
> I find, unfortunately, that getting babel to do what I want is somewhat
> of an arcane art (for me) so once I get something doing what I want it
> to do, I leave things alone...
>

  `:results latex raw' is equivalent to `:results raw'.

If you try C-c C-v C-i in your src block, you will get

,----
| Lang: latex
| Properties:
| 	:header-args 	nil
| 	:header-args:latex 	nil
| Header Arguments:
| 	:cache		no
| 	:exports	results
| 	:hlines		no
| 	:noweb		no
| 	:results	raw replace
| 	:session	none
| 	:tangle		no
`----

So the result is processed by the exporter as `raw', which works ok as 
long as the exporter leaves the latex alone --- as in your case.

But sometimes is not what you want.

For example, a naked ~tildes~ will be marked up as \verb~tildes~ under 
`:results raw' or `:results latex raw', and as ~tildes~ under `:results 
latex'.


> I'm sure it all makes sense but it's probably a case of my not having
> the time to figure things out properly.  When I need to get something
> done, it's often because I need it *now* (or yesterday :-).
>

Been there, too.

Chuck

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-18 12:34 Embedding diagrams in Org Marcin Borkowski
  2015-02-18 14:19 ` Eric S Fraga
@ 2015-03-04 19:19 ` Marcin Borkowski
  2015-03-04 19:37   ` Rasmus
  2015-03-04 21:22   ` Andreas Leha
  1 sibling, 2 replies; 19+ messages in thread
From: Marcin Borkowski @ 2015-03-04 19:19 UTC (permalink / raw)
  To: Org-Mode mailing list

e
On 2015-02-18, at 13:34, Marcin Borkowski <mbork@wmi.amu.edu.pl> wrote:

> Hello all,
>
> I need to embed some diagrams (graphs of functions, for instance, or
> trees) in an Org file.  Any suggestions on how to do it?  In case of
> ditaa, I can use a source block and the "results" line, and see the
> image with C-c C-x C-v.  Can I do a similar thing with Asymptote?  How
> hard/time-consuming would it be to add support e.g. for tikz or other
> such tools?
>
> Best,

While the answers I got were helpful, and thank you all for them, my
curiosity jumped two levels up when I saw the code for
org-latex--inline-image in ox-latex today.  It seems that there are
special provisions for tikz pictures.  However, the code does seem to be
a bit weird: for instance, the tikz code seems to be wrapped in the
tikzpicture environment depending on whether any /options/ are given or
not, which seems an odd choice to me.

Did anyone use the ability to inline tikz pictures (i.e., pictures in
a file with =tikz= or =pgf= extension)?  If so, could you share some
examples, or at least success stories?

Also, org-latex--inline-image seems to provide for including svg images,
but I could not find a \usepackage{svg}, nor a provision for enabling
shell-escape (like in the case of minted).  Again: any success stories
or is there a bug?

TIA,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-03-04 19:19 ` Marcin Borkowski
@ 2015-03-04 19:37   ` Rasmus
  2015-03-04 21:22   ` Andreas Leha
  1 sibling, 0 replies; 19+ messages in thread
From: Rasmus @ 2015-03-04 19:37 UTC (permalink / raw)
  To: emacs-orgmode

Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:

> Did anyone use the ability to inline tikz pictures (i.e., pictures in
> a file with =tikz= or =pgf= extension)?  If so, could you share some
> examples, or at least success stories?
>
> Also, org-latex--inline-image seems to provide for including svg images,
> but I could not find a \usepackage{svg}, nor a provision for enabling
> shell-escape (like in the case of minted).  Again: any success stories
> or is there a bug?

The following seem to work with pdflatex.  You need svg and tikz from
CTAN.  I use tikz frequently via matplotlib in Python and tikzDevice in R.

#+CAPTION: a svg drawing
[[file:circle.svg]]

#+CAPTION: a tikz drawing 
[[file:fig.tikz]]

* assets                                                           :noexport:
#+BEGIN_SRC emacs-lisp
(org-babel-tangle)
#+END_SRC

#+RESULTS:
| fig.tikz | circle.svg |

#+LATEX_HEADER: \usepackage{tikz}
#+BEGIN_SRC latex :tangle fig.tikz
  \begin{tikzpicture}
  \node [draw=red,circle] at (0,0) {X};
  \end{tikzpicture}
#+END_SRC

#+LATEX_HEADER: \usepackage{svg}
#+BEGIN_SRC html :tangle circle.svg
  <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
    <circle r="100" cx="100" cy="100"></circle>
  </svg>
#+END_SRC


-- 
Got mashed potatoes. Ain't got no T-Bone. No T-Bone

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-03-04 19:19 ` Marcin Borkowski
  2015-03-04 19:37   ` Rasmus
@ 2015-03-04 21:22   ` Andreas Leha
  2015-03-05  8:12     ` Eric S Fraga
  1 sibling, 1 reply; 19+ messages in thread
From: Andreas Leha @ 2015-03-04 21:22 UTC (permalink / raw)
  To: emacs-orgmode

Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
> e
> On 2015-02-18, at 13:34, Marcin Borkowski <mbork@wmi.amu.edu.pl> wrote:
>
>> Hello all,
>>
>> I need to embed some diagrams (graphs of functions, for instance, or
>> trees) in an Org file.  Any suggestions on how to do it?  In case of
>> ditaa, I can use a source block and the "results" line, and see the
>> image with C-c C-x C-v.  Can I do a similar thing with Asymptote?  How
>> hard/time-consuming would it be to add support e.g. for tikz or other
>> such tools?
>>
>> Best,
>
> While the answers I got were helpful, and thank you all for them, my
> curiosity jumped two levels up when I saw the code for
> org-latex--inline-image in ox-latex today.  It seems that there are
> special provisions for tikz pictures.  However, the code does seem to be
> a bit weird: for instance, the tikz code seems to be wrapped in the
> tikzpicture environment depending on whether any /options/ are given or
> not, which seems an odd choice to me.
>
> Did anyone use the ability to inline tikz pictures (i.e., pictures in
> a file with =tikz= or =pgf= extension)?  If so, could you share some
> examples, or at least success stories?
>

The example I posted earlier in this thread [1] uses the *.tikz version for
latex export.

I do not know, whether that helps, but I think the behaviour of the tikz
graphics has been decided in this thread [2].

The wrapping in tikzpicture if options are present is quite sensible, as
these options have to be presented somewhere.  Note, that it is fine to
nest tikzpicture environments.  So, the *.tikz file is basically
expected to bring its own tikzpicture environment.  If there are options
given in the org file, this is just wrapped into another tikzpicture
environment.  (If I understand the reasoning correctly, that is...)

Regards,
Andreas

> Also, org-latex--inline-image seems to provide for including svg images,
> but I could not find a \usepackage{svg}, nor a provision for enabling
> shell-escape (like in the case of minted).  Again: any success stories
> or is there a bug?
>




[1] http://permalink.gmane.org/gmane.emacs.orgmode/95197

[2] http://thread.gmane.org/gmane.emacs.orgmode/66900

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-03-04 21:22   ` Andreas Leha
@ 2015-03-05  8:12     ` Eric S Fraga
  0 siblings, 0 replies; 19+ messages in thread
From: Eric S Fraga @ 2015-03-05  8:12 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

On Wednesday,  4 Mar 2015 at 21:22, Andreas Leha wrote:

[...]

> The example I posted earlier in this thread [1] uses the *.tikz version for
> latex export.
> [...]
> [1] http://permalink.gmane.org/gmane.emacs.orgmode/95197

I had forgotten about that thread.  Very useful, in particular finding
an example that uses gnuplot to generate tikz output.  However, in
trying a simple example:

#+begin_src org
* gnuplot

#+latex_header: \usepackage{gnuplot-lua-tikz}

#+name: gnuplot2tikz
#+headers: :term "tikz size 15cm,15cm" :cache yes
#+begin_src gnuplot :file tikzgnuplot.tikz
plot sin(x)
#+end_src

#+results[ca28dda18a661b1eb77b4be5c23f5c1f1133629f]: gnuplot2tikz
[[file:tikzgnuplot.tikz]]

#+end_src

I found that the ~latex_header~ line was necessary as the tikz generated by gnuplot requires that package.

I'm putting this here as a /heads up/ for anybody else trying this.

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org release_8.3beta-843-ga5f1a3.dirty

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-24 17:00       ` Charles C. Berry
@ 2015-03-05  8:51         ` Sebastien Vauban
  0 siblings, 0 replies; 19+ messages in thread
From: Sebastien Vauban @ 2015-03-05  8:51 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

"Charles C. Berry" wrote:
>>> Why ":results latex raw" and not ":results latex"?
>>
>> I have no idea ;-)
>>
>> I find, unfortunately, that getting babel to do what I want is somewhat
>> of an arcane art (for me) so once I get something doing what I want it
>> to do, I leave things alone...
>
> `:results latex raw' is equivalent to `:results raw'.
>
> [...]
>
> For example, a naked ~tildes~ will be marked up as \verb~tildes~ under
> `:results raw' or `:results latex raw', and as ~tildes~ under
> `:results latex'.

Aren't "raw" and "latex" two _mutually exclusive_ format options?

See http://orgmode.org/manual/results.html.

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-02-18 19:37   ` Andreas Leha
  2015-02-19  8:49     ` Sebastien Vauban
  2015-02-19 14:10     ` Eric S Fraga
@ 2015-03-21 11:23     ` Marcin Borkowski
  2015-03-21 21:41       ` Andreas Leha
  2 siblings, 1 reply; 19+ messages in thread
From: Marcin Borkowski @ 2015-03-21 11:23 UTC (permalink / raw)
  To: emacs-orgmode


On 2015-02-18, at 20:37, Andreas Leha <andreas.leha@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---
> #+LATEX_HEADER: \usepackage{tikz}
>
> * tikz example
>
> #+name: tikz_example
> #+header: :packages '(("" "tikz"))

What does the above line do exactly?

> #+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?  Do
I get it correctly that the (t "example_diagram.png") refers to manual
evaluation and not the evaluation during the export?

> #+header: :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 800
> #+header: :results file raw
> #+header: :fit yes
> #+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?  What if I want to use pdf2svg
instead?

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

TIA,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Embedding diagrams in Org
  2015-03-21 11:23     ` Marcin Borkowski
@ 2015-03-21 21:41       ` Andreas Leha
  0 siblings, 0 replies; 19+ messages in thread
From: Andreas Leha @ 2015-03-21 21:41 UTC (permalink / raw)
  To: emacs-orgmode

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 <mbork@wmi.amu.edu.pl> writes:
> On 2015-02-18, at 20:37, Andreas Leha <andreas.leha@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---
>> #+LATEX_HEADER: \usepackage{tikz}
>>
>> * tikz example
>>
>> #+name: tikz_example
>> #+header: :packages '(("" "tikz"))
>
> 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
LATEX_HEADER when LATEX_HEADER_EXTRA was introduced.

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
>> #+header: :results file raw
>> #+header: :fit yes
>> #+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
upgrading your imagemagick.

> What if I want to use pdf2svg
> instead?

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-03-21 21:41 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-18 12:34 Embedding diagrams in Org Marcin Borkowski
2015-02-18 14:19 ` Eric S Fraga
2015-02-18 15:51   ` Eduardo Ochs
2015-02-18 19:01     ` Eric S Fraga
2015-02-19  8:45       ` Sebastien Vauban
2015-02-18 19:37   ` Andreas Leha
2015-02-19  8:49     ` Sebastien Vauban
2015-02-21 11:06       ` Andreas Leha
2015-02-19 14:10     ` Eric S Fraga
2015-03-21 11:23     ` Marcin Borkowski
2015-03-21 21:41       ` Andreas Leha
2015-02-24  0:01   ` Marcin Borkowski
2015-02-24  8:04     ` Eric S Fraga
2015-02-24 17:00       ` Charles C. Berry
2015-03-05  8:51         ` Sebastien Vauban
2015-03-04 19:19 ` Marcin Borkowski
2015-03-04 19:37   ` Rasmus
2015-03-04 21:22   ` Andreas Leha
2015-03-05  8:12     ` Eric S Fraga

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.