emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
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.

#+caption: Perform inter-sample interpolation.
#+begin_src python
import numpy as np

;; 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}

Run the example with:
emacs -Q --batch -l file.el

Before the patch, you get:
import numpy as np
\caption{(((Perform inter-sample interpolation.)))}

After the patch, you get:
import numpy as np
\caption{Perform inter-sample interpolation.}

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.


[-- 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."
 	    (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) "")))))))

             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:

  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 \


* 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


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).