How to export ditaa or dot blocks as captioned figures (LaTeX)?
emacs, export, latex, org-mode
Solution
To get it to work you need to have a `#+RESULTS:` section under the `#+BEGIN_SRC` block and caption that instead:
* Plain source code
#+CAPTION: This works
#+LABEL: fig:works
#+BEGIN_SRC
this is a test
#+END_SRC
See Figure [[fig:works]].
* Ditaa
#+BEGIN_SRC ditaa :file foo.png :cmdline -E
/-----\
----------------------------->| foo |<-----------------------------
\-----/
#+END_SRC
#+CAPTION: Foo
#+LABEL: fig:foo
#+RESULTS:
[[file:foo.png]]
See Figure [[fig:foo]].
* Dot
#+BEGIN_SRC dot :file bar.png
digraph foo {
asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf -> b;
}
#+END_SRC
#+CAPTION: Bar
#+LABEL: fig:bar
#+RESULTS:
[[file:bar.png]]
See Figure [[fig:bar]].
#+OPTIONS: toc:nil author:nil
#+TITLE:
#+DATE:
Problem
I have an org-mode document with captioned ditaa and dot figures. When I export to LaTeX, the resulting images are not placed inside a `figure` environment, not given a `\caption`, and not given a `\label`. Other source code blocks export fine. How can I fix this? Here is an example org-mode document: ``` * Plain source code works #+CAPTION: This works #+LABEL: fig:works #+BEGIN_SRC this is a test #+END_SRC The above (Figure [[fig:works]]) is a figure with some source code. When exported to LaTeX, it is placed inside a ~figure~ environment and given a caption and label as expected. * Ditaa doesn't work #+CAPTION: Foo #+LABEL: fig:foo #+BEGIN_SRC ditaa :file foo.png :cmdline -E /-----\ ----------------------------->| foo |<----------------------------- \-----/ #+END_SRC The above (Figure [[fig:foo]]) is a ditaa figure. When exported to LaTeX, the image is not inside a ~figure~ environment, it is missing the caption, and there is no ~\label~. * Dot doesn't work #+CAPTION: Bar #+LABEL: fig:bar #+BEGIN_SRC dot :file bar.png digraph foo { asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf -> b; } #+END_SRC The above (Figure [[fig:bar]]) is a dot figure. When exported to LaTeX, the image is not inside a ~figure~ environment, it is missing the caption, and there is no ~\label~. #+OPTIONS: toc:nil author:nil #+TITLE: #+DATE: ``` I'm using org-mode 8.2.10 on Emacs 24.3.1.