Thomas S. Dye writes:

> It would be better to have a LaTeX attribute, say :commands, that
> places commands within \begin{figure} ... \end{figure}.

This is a possible solution from the LaTeX side, which would avoid
having to modify the Org code and can also be used to introduce more
complex arbitrary code into the figure environment. It consists of
defining a variable (for arbitrary code) and redefining the figure
environment to include that variable. Something like this:

#+NAME: preamble
#+begin_src latex :exports none
\usepackage{graphicx,xparse}

\def\myfigcode#1{#1}

\let\svfigure\figure
\let\endsvfigure\endfigure

\DeclareDocumentEnvironment{figure}{o}{%
\IfNoValueTF{#1}{%
  \begin{svfigure}}
  {\begin{svfigure}[#1]}
    \myfigcode%
}
{\end{svfigure}}
#+end_src

#+begin_src latex :noweb yes :results raw
,#+LaTeX_HEADER: <<preamble>>
#+end_src

Here I use the dummy images from the graphicx package. Of course, then
it is necessary to apply a zero value to the variable again, or enclose
all in a \begingroup...\endgroup. It's a bit tricky and I haven't tried
it too much:

@@latex:\begingroup\def\myfigcode{{\centering\fbox{\textbf{Hello 
world!!!}}\par\vspace{5ex}}}@@

#+caption: This is a caption
#+ATTR_LaTeX: :placement [h] :width .5\linewidth
[[file:example-image-a.jpg]]

@@latex:\endgroup@@

#+caption: This is a caption
#+ATTR_LaTeX: :placement [h] :width .5\linewidth
[[file:example-image-b.jpg]]

A screenshot:

https://i.imgur.com/8JIU6nX.png

Best regards,

Juan Manuel 

Reply via email to