On Sat, Mar 16 2024, Leo Butler <leo.but...@umanitoba.ca> wrote:

> On Fri, Mar 15 2024, Ihor Radchenko <yanta...@posteo.net> wrote:
>
>> Leo Butler <leo.but...@umanitoba.ca> writes:
>>
>>>> Leo, may you improve the patch to avoid defining
>>>> `org-beamer-frame-environment' when it is not used in all the frames?
>>>
>>> "all the" should be "any of" in that last sentence.
>>
>> Indeed.
>>
>>> How about the attached patch?
>>> ...
>>> +(defvar org-beamer--frame-environment-used nil
>>> +  "Nil unless `org-beamer-frame-environment' is used.
>>> +See `org-beamer--frame-environment'.")
>>
>> I'd prefer to keep this information in the INFO channel.
>> It will be more consistent.

Apologies, I messed up the patch in the previous email.

Attached is a patch that compiles cleanly and uses INFO.

Leo

From 003cf1d417fe8f5d1a9f8fe20980f7f4b7c5d3c4 Mon Sep 17 00:00:00 2001
From: Leo Butler <leo.but...@umanitoba.ca>
Date: Tue, 12 Mar 2024 15:11:27 -0500
Subject: [PATCH] lisp/ox-beamer.el: constrain use of
 org-beamer-frame-environment

* lisp/ox-beamer.el (org-beamer--format-frame, org-beamer-template):
Only use `org-beamer-frame-environment' when a frame is marked as
fragile and the frame's contents include either \begin{frame} or
\end{frame}.  When `org-beamer-frame-environment' is used and not
equal to "frame", add the property :define-frame to INFO and set it to
t.  When that property is t, `org-beamer-template' emits a definition
of the alternative frame environment.

Refs: https://list.orgmode.org/orgmode/87bk7jeik8.fsf@localhost/
https://list.orgmode.org/87a5nux3zr....@t14.reltub.ca/T/
---
 lisp/ox-beamer.el | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 4fad37b59..090d3d9ab 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -429,8 +429,21 @@ used as a communication channel."
 	  ;; among `org-beamer-verbatim-elements'.
 	  (org-element-map headline org-beamer-verbatim-elements 'identity
 			   info 'first-match))
-         (frame (or (and fragilep org-beamer-frame-environment)
-                    "frame")))
+         ;; If FRAGILEP is non-nil and CONTENTS contains an occurrence
+         ;; of \begin{frame} or \end{frame}, then set the FRAME
+         ;; environment to be `org-beamer-frame-environment';
+         ;; otherwise, use "frame". If the selected environment is not
+         ;; "frame", then add the property :define-frame to INFO and
+         ;; set it to t.
+         (frame (let ((selection
+                       (or (and fragilep
+                                (or (string-search "\\begin{frame}" contents)
+                                    (string-search "\\end{frame}" contents))
+                                org-beamer-frame-environment)
+                           "frame")))
+                  (unless (string= selection "frame")
+                    (setq info (plist-put info :define-frame t)))
+                  selection)))
     (concat "\\begin{" frame "}"
 	    ;; Overlay specification, if any. When surrounded by
 	    ;; square brackets, consider it as a default
@@ -851,8 +864,8 @@ holding export options."
      (org-latex--insert-compiler info)
      ;; Document class and packages.
      (org-latex-make-preamble info)
-     ;; Define the alternative frame environment.
-     (unless (equal "frame" org-beamer-frame-environment)
+     ;; Define the alternative frame environment, if needed.
+     (when (plist-get info :define-frame)
        (format "\\newenvironment<>{%s}[1][]{\\begin{frame}#2[environment=%1$s,#1]}{\\end{frame}}\n"
                org-beamer-frame-environment))
      ;; Insert themes.
-- 
2.43.0

Reply via email to