Mathew Moore <[email protected]> writes:
> I'm having some trouble exporting captions for images generated by
> source code blocks within an Org document (Emacs 30.2, Org mode
> version 9.7.11). The following small example uses the "by-backend"
> macro from the Org documentation to support HTML and PDF exports.
>
> (A complete example is appended at the end of this message.)
>
> #+name: tikz-basic-picture
> #+header: :headers '("\\usepackage{tikz}" "\\usetikzlibrary{shapes}")
> #+header: :file-ext (by-backend ('latex 'nil) (_ "svg"))
> #+header: :results (by-backend ('latex "latex") (_ "raw file"))
> #+begin_src latex
> \begin{tikzpicture}
> \node[fill=green, minimum size=2em] {};
> \end{tikzpicture}
> #+end_src
>
> #+name: results--tikz-basic-picture
> #+caption: Image created by the LaTeX source code block.
> #+results: tikz-basic-picture
When exporting to latex, you end up with
#+name: results--tikz-basic-picture
#+caption: Image created by the LaTeX source code block.
#+results: tikz-basic-picture
#+begin_export latex
\begin{tikzpicture}
\node[fill=green, minimum size=2em] {};
\end{tikzpicture}
#+end_export
Caption for export blocks is not meaningful. So, Org ignores it.
> Is there an idiomatic approach to solving this conflict? I've tried
> adding "#+attr_latex: :float t" to the results block header in lieu of
> the :wrap source code block argument, but that looks like it only
> applies to images.
Use special block.
#+name: tikz-basic-picture
#+header: :headers '("\\usepackage{tikz}" "\\usetikzlibrary{shapes}")
#+header: :file-ext (by-backend ('latex 'nil) (_ "svg"))
#+header: :results (by-backend ('latex "value") (_ "raw file"))
#+header: :wrap (by-backend ('latex "figure") (_ nil))
#+begin_src latex
\begin{tikzpicture}
\node[fill=green, minimum size=2em] {};
\end{tikzpicture}
#+end_src
#+name: results--tikz-basic-picture
#+caption: Image created by the LaTeX source code block.
#+results: tikz-basic-picture
--
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>