# Adding extra "\source{something}" command inside table and figure latex environments exported from org-mode

I'm writing a large document in org that I export to PDF through latex. The latex class that I'm using (set in org-latex-classes) defines a \source command that can be used inside table and figure environments to indicate the source of that material. Something like the code below in latex

\begin{figure}[htbp]
\centering
\includegraphics[width=\textwidth]{figure.pdf}
\caption{\label{thelabel}The caption.}}
\source{Modified from~\cite{bibkey}.}
\end{figure}


In org-mode we can include the figure as (without the \source command)

#+NAME: thelabel
#+ATTR_LATEX: :width \textwidth
#+CAPTION: \caption{The caption.}
[[figure.pdf]]


My question is: How can I tell org-mode to add \source{whatever} inside the exported figure environment? Is there something I can pass to #+ATTR_LATEX: ??? to add what I need inside the environment?

Note: Unfortunately the \source command cannot be put inside the caption.

Edit: After more research I found this question on stackoverflow which is the same question as this one. Essentially, it comes down to either NickD's answer, or creating a filter, but with the filter solution there does not allow specifying what comes inside the \source command and this using :caption seems like the only way to go.

Try the :caption attribute in #+ATTR_LATEX: instead:

#+NAME: thelabel
#+ATTR_LATEX: :width \textwidth :caption \caption{The caption.}\source{the Source}
[[figure.pdf]]


The LaTeX file I get reads in part:

\begin{figure}[htbp]
\centering
\includegraphics[width=\textwidth]{/path/to/figure.jpg}
\caption{The caption.}\source{The Source}
\end{figure}


which should work as expected.

• That's ingenious and it works. The problem with this solution is that #+NAME is ignored and thus I need to repeat the label inside \caption. Furthermore, I also want to export to HTML (although in that case I don't care about the \source) and thus I need to keep both #+ATTR_LATEX: :caption ... and #+CAPTION. If I do any change in one of them I have to remember also change the other. Nov 6 '20 at 21:16
• That's a different question which you should ask separately. Nov 6 '20 at 23:09