emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Fix caption format for custom latex src block
@ 2021-12-30  4:05 Matt Huszagh
  2022-06-14  3:51 ` Ihor Radchenko
  2022-07-31  4:03 ` Ihor Radchenko
  0 siblings, 2 replies; 8+ messages in thread
From: Matt Huszagh @ 2021-12-30  4:05 UTC (permalink / raw)
  To: Emacs-Orgmode

[-- Attachment #1: Type: text/plain, Size: 1320 bytes --]

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

[-- Attachment #2: 0001-ox-latex.el-Fix-caption-format-for-custom-latex-src-.patch --]
[-- Type: text/x-patch, Size: 1093 bytes --]

From 5b0601d6d3b8034202c4b9b820c64a719e3129b9 Mon Sep 17 00:00:00 2001
From: Matt Huszagh <huszaghmatt@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  <huszaghmatt@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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-07-31  4:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-30  4:05 [PATCH] Fix caption format for custom latex src block Matt Huszagh
2022-06-14  3:51 ` Ihor Radchenko
2022-06-28  4:07   ` Matt Huszagh
2022-06-29  2:24     ` Ihor Radchenko
2022-06-29 15:20       ` Timothy
2022-06-29 15:26     ` Timothy
2022-07-09  0:23       ` Matt Huszagh
2022-07-31  4:03 ` Ihor Radchenko

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).