From: Matt Huszagh <huszaghmatt@gmail.com>
To: Emacs-Orgmode <emacs-orgmode@gnu.org>
Subject: [PATCH] Fix caption format for custom latex src block
Date: Wed, 29 Dec 2021 20:05:59 -0800 [thread overview]
Message-ID: <CA+X8ke6MkeNz12ZkkvADZXfMtHuQw5Awwi2u-y+X6+4+URkytQ@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2021-12-30 4:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-30 4:05 Matt Huszagh [this message]
2022-06-14 3:51 ` [PATCH] Fix caption format for custom latex src block 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA+X8ke6MkeNz12ZkkvADZXfMtHuQw5Awwi2u-y+X6+4+URkytQ@mail.gmail.com \
--to=huszaghmatt@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public 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).