From 9cb3489e3fe80fb2e3996b737f528aa4db9ba62d Mon Sep 17 00:00:00 2001 From: Leo Butler Date: Thu, 25 Jan 2024 09:48:20 -0600 Subject: [PATCH] lisp/ox-beamer.el: randomize the beamer frame environment * lisp/ox-beamer.el (org-beamer--frame-environment): new variable that contains the name of an environment that serves as an alias for the beamer frame environment. The environment's definition is appended to the set-up for beamer export. (org-beamer--format-frame): Replace the occurrence of \begin{frame} and \end{frame} with the new environment's name. Rationale: Code with \begin{frame} or \end{frame} cannot be embedded in a verbatim environment inside a beamer frame due to a design decision made by the beamer developers [1]. As suggested in that report, defining an alias for the beamer frame environment will allow such verbatim examples to compile correctly [2]. Refs: [1] https://github.com/josephwright/beamer/issues/360 [2] https://github.com/josephwright/beamer/issues/360#issuecomment-708705250 [3] https://list.orgmode.org/orgmode/87le8eg1hs.fsf@localhost/T/ --- lisp/ox-beamer.el | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el index 82c8841aa..be3003835 100644 --- a/lisp/ox-beamer.el +++ b/lisp/ox-beamer.el @@ -36,11 +36,23 @@ (require 'cl-lib) (require 'ox-latex) +;; Needed to set-up Beamer export. +(defconst org-beamer--frame-environment + (concat "orgframe" (org-id-uuid)) + "Name of the beamer frame environment. +This is randomized to prevent collisions.") + ;; Install a default set-up for Beamer export. (unless (assoc "beamer" org-latex-classes) (add-to-list 'org-latex-classes - '("beamer" - "\\documentclass[presentation]{beamer}" + `("beamer" + ,(concat "\\documentclass[presentation]{beamer}\n" + ;; Define an alias for the beamer frame environment + "\\newenvironment<>{" + org-beamer--frame-environment + "}[1][]{\\begin{frame}[environment=" + org-beamer--frame-environment + ",#1]}{\\end{frame}}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))) @@ -414,7 +426,7 @@ used as a communication channel." ;; among `org-beamer-verbatim-elements'. (org-element-map headline org-beamer-verbatim-elements 'identity info 'first-match))) - (concat "\\begin{frame}" + (concat "\\begin{" org-beamer--frame-environment "}" ;; Overlay specification, if any. When surrounded by ;; square brackets, consider it as a default ;; specification. @@ -481,7 +493,7 @@ used as a communication channel." ;; output. (if (not fragilep) contents (replace-regexp-in-string "\\`\n*" "\\& " (or contents ""))) - "\\end{frame}"))) + "\\end{" org-beamer--frame-environment "}"))) (defun org-beamer--format-block (headline contents info) "Format HEADLINE as a block. -- 2.43.0