This patch fixes an issue in which captions for custom listing environments are not converted correctly. To illustrate the issue, take the following MWE.
file.org: ``` #+caption: Perform inter-sample interpolation. #+begin_src python import numpy as np #+end_src ``` file.el: ``` ;; Loading straight isn't necessary if you don't use it, just need to ;; load org. (load "~/.config/emacs/straight/repos/straight.el/bootstrap.el") (straight-use-package 'org) (find-file "file.org") (setq org-latex-listings 'minted) (setq org-latex-custom-lang-environments '((python "\\begin{listing} \\begin{minted}[%o]{python} %s\\end{minted} \\caption{%c} \\label{%l} \\end{listing}"))) (org-latex-export-to-latex) ``` Run the example with: emacs -Q --batch -l file.el Before the patch, you get: ``` [...] \begin{listing} \begin{minted}[]{python} import numpy as np \end{minted} \caption{(((Perform inter-sample interpolation.)))} \label{nil} \end{listing} [...] ``` After the patch, you get: ``` [...] \begin{listing} \begin{minted}[]{python} import numpy as np \end{minted} \caption{Perform inter-sample interpolation.} \label{nil} \end{listing} [...] ``` I'm not actually 100% confident that the patch is the optimal way to do this. The API wasn't totally clear to me in this case. Any advice here is appreciated. Matt
From 5b0601d6d3b8034202c4b9b820c64a719e3129b9 Mon Sep 17 00:00:00 2001 From: Matt Huszagh <huszaghm...@gmail.com> Date: Wed, 29 Dec 2021 19:35:42 -0800 Subject: [PATCH] ox-latex.el: Fix caption format for custom latex src block 2021-12-29 Matt Huszagh <huszaghm...@gmail.com> * lisp/ox-latex.el (org-latex-src-block): Use `org-export-get-caption' to extract caption from element. Otherwise, the full caption contains a large number of unnecessary parentheses. --- lisp/ox-latex.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 8187119ec..a9c6a4b5c 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -3021,7 +3021,8 @@ contextual information." custom-env) (format-spec custom-env `((?s . ,formatted-src) - (?c . ,caption) + (?c . ,(org-export-data (org-export-get-caption src-block) + info)) (?f . ,float) (?l . ,(org-latex--label src-block info)) (?o . ,(or (plist-get attributes :options) ""))))))) -- 2.31.1