all messages for Emacs-related lists mirrored at yhetil.org
 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 related	[flat|nested] 8+ messages in thread

* Re: [PATCH] Fix caption format for custom latex src block
  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-07-31  4:03 ` Ihor Radchenko
  1 sibling, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2022-06-14  3:51 UTC (permalink / raw)
  To: Matt Huszagh; +Cc: Emacs-Orgmode

Matt Huszagh <huszaghmatt@gmail.com> writes:

> This patch fixes an issue in which captions for custom listing
> environments are not converted correctly. To illustrate the issue,
> take the following MWE.

Thanks!

> -			   (?c . ,caption)
> +			   (?c . ,(org-export-data (org-export-get-caption src-block)
> +                                                   info))

I think that it will be better if you use
org-latex--caption/label-string instead. It will take care about short
captions as well.

Best,
Ihor


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

* Re: [PATCH] Fix caption format for custom latex src block
  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:26     ` Timothy
  0 siblings, 2 replies; 8+ messages in thread
From: Matt Huszagh @ 2022-06-28  4:07 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Emacs-Orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

> I think that it will be better if you use
> org-latex--caption/label-string instead. It will take care about short
> captions as well.

Changing this to (?c . ,caption-str) yields for the original example

\caption{\caption{Perform inter-sample interpolation.}
}

I could use substring to remove the leading \caption{ and trailing
}. What do you think?

Matt


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

* Re: [PATCH] Fix caption format for custom latex src block
  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
  1 sibling, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2022-06-29  2:24 UTC (permalink / raw)
  To: Matt Huszagh, Timothy; +Cc: Emacs-Orgmode

Matt Huszagh <huszaghmatt@gmail.com> writes:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> I think that it will be better if you use
>> org-latex--caption/label-string instead. It will take care about short
>> captions as well.
>
> Changing this to (?c . ,caption-str) yields for the original example
>
> \caption{\caption{Perform inter-sample interpolation.}
> }
>
> I could use substring to remove the leading \caption{ and trailing
> }. What do you think?

Removing caption does not sound reliable. Also, you need to
update the patch according to recent commit by Timothy.

Timothy, looking at the new implementation of org-latex-src-block, I do
not see custom-env being passed as an argument of
org-latex-src-block--custom. This is likely a bug.

Best,
Ihor


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

* Re: [PATCH] Fix caption format for custom latex src block
  2022-06-29  2:24     ` Ihor Radchenko
@ 2022-06-29 15:20       ` Timothy
  0 siblings, 0 replies; 8+ messages in thread
From: Timothy @ 2022-06-29 15:20 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Matt Huszagh, Emacs-Orgmode

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

Hi Ihor,

> Timothy, looking at the new implementation of org-latex-src-block, I do
> not see custom-env being passed as an argument of
> org-latex-src-block–custom. This is likely a bug.

Ah yes, this was an oversight. Corrected in 30953bd7b701c870152cd60f52f2d484970caeb9.

All the best,
Timothy

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

* Re: [PATCH] Fix caption format for custom latex src block
  2022-06-28  4:07   ` Matt Huszagh
  2022-06-29  2:24     ` Ihor Radchenko
@ 2022-06-29 15:26     ` Timothy
  2022-07-09  0:23       ` Matt Huszagh
  1 sibling, 1 reply; 8+ messages in thread
From: Timothy @ 2022-06-29 15:26 UTC (permalink / raw)
  To: Matt Huszagh; +Cc: Ihor Radchenko, emacs-orgmode

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

Hi Matt,

As mentioned by Ihor, you’ll want to take a look at the curent version of
ox-latex, specifically `org-latex-src-block--custom' which now contains `(?c .
,caption)'. You may want to consider modifying `org-latex--caption/label-string' to
accept the form `(element info &optional content-only)' or reimplementing just the
bits needed for this purpose — which ever works out nicer. Looking at
`org-latex--caption/label-string' a substring approach looks quite fragile, though
you might be able to get away with an application of `replace-regexp-in-string',
though I’d personally consider this a bit of a last resort.

Matt Huszagh <huszaghmatt@gmail.com> writes:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> I think that it will be better if you use
>> org-latex–caption/label-string instead. It will take care about short
>> captions as well.
>
> Changing this to (?c . ,caption-str) yields for the original example
>
> {Perform inter-sample interpolation.
> }
>
> I could use substring to remove the leading { and trailing
> }. What do you think?

All the best,
Timothy

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

* Re: [PATCH] Fix caption format for custom latex src block
  2022-06-29 15:26     ` Timothy
@ 2022-07-09  0:23       ` Matt Huszagh
  0 siblings, 0 replies; 8+ messages in thread
From: Matt Huszagh @ 2022-07-09  0:23 UTC (permalink / raw)
  To: Timothy; +Cc: Ihor Radchenko, emacs-orgmode

Timothy <tecosaur@gmail.com> writes:

> As mentioned by Ihor, you’ll want to take a look at the curent version of
> ox-latex, specifically `org-latex-src-block--custom' which now contains `(?c .
> ,caption)'. You may want to consider modifying `org-latex--caption/label-string' to
> accept the form `(element info &optional content-only)' or reimplementing just the
> bits needed for this purpose — which ever works out nicer. Looking at
> `org-latex--caption/label-string' a substring approach looks quite fragile, though
> you might be able to get away with an application of `replace-regexp-in-string',
> though I’d personally consider this a bit of a last resort.

Thanks for the directions Timothy.

I failed to reproduce the old issue with the latest commit to main, so
it looks like this patch is no longer needed. Nice! I'll post back if I
notice any issues in the future, but otherwise I'd say we can consider
this closed.

Matt


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

* Re: [PATCH] Fix caption format for custom latex src block
  2021-12-30  4:05 [PATCH] Fix caption format for custom latex src block Matt Huszagh
  2022-06-14  3:51 ` Ihor Radchenko
@ 2022-07-31  4:03 ` Ihor Radchenko
  1 sibling, 0 replies; 8+ messages in thread
From: Ihor Radchenko @ 2022-07-31  4:03 UTC (permalink / raw)
  To: Matt Huszagh; +Cc: Emacs-Orgmode

Matt Huszagh <huszaghmatt@gmail.com> writes:

> This patch fixes an issue in which captions for custom listing
> environments are not converted correctly. To illustrate the issue,
> take the following MWE.

Since the original issue cannot be reproduced (see the other email in
the thread) I am closing this.

Canceled.

Best,
Ihor


^ 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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.