On Tue, Mar 12 2024, Ihor Radchenko <yanta...@posteo.net> wrote:

> Pedro Andres Aranda Gutierrez <paag...@gmail.com> writes:
>
>> Jup, of course. If you look in org-lint.el, one of the cases that would
>> trigger a message is when the frame environment uses "frame" directly and
>> there is a \begin{frame} in the org.
>> Line 1522 onwards in org-lint.el
>
> (1)
> Sure, but we should not demand users to run org-lint. Ideally, exporting
> any valid Org file should work.
> The fact that the presence of \begin{frame} breaks beamer is a technical
> detail users should better not be bothered with. That's why we added the
> orgframe construct.
>
> (2)
> On the other hand, it is clear that Org mode users are unwilling to
> tolerate too much of machine generated latex output. So, going further
> and trying to generate unique orgframe environments might not be ideal.
>
> The current approach is a balance between the above considerations.
>
> AFAIU, what you propose is reverting the orgframe code; that goes
> against the first point.

Current git HEAD allows a user like Pedro to effectively turn off the
orgframe code via

(setq org-beamer-frame-environment "frame")

or an equivalent. 

>
> What I proposed is to reduce the amount of machine-generated code by
> using `org-beamer-frame-environment' only when strictly necessary.

Attached is a patch that limits the use of
`org-beamer-frame-environment' to those frames that contain either
\begin{frame} or \end{frame} in their body.

This has the nice side-effect that one can include example frames
generated by Org without causing an error (previously, Org exported
latex that would not compile). See the attachments.

Leo

From cab7cd149868be86f80d2c7bb52e2c09c028d4b1 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): 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}.

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

diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 4fad37b59..f7e39dde4 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -429,7 +429,10 @@ 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 (or (and fragilep
+                         (or (string-search "\\begin{frame}" contents)
+                             (string-search "\\end{frame}" contents))
+                         org-beamer-frame-environment)
                     "frame")))
     (concat "\\begin{" frame "}"
 	    ;; Overlay specification, if any. When surrounded by
-- 
2.43.0

#+startup: beamer
#+LaTeX_CLASS: beamer

* A frame with =orgframe= sample code
#+begin_example
\begin{orgframe}
  Here is a beamer frame.
\end{orgframe}
#+end_example
This is exported in a =frame= environment, although it is marked as fragile.

* A frame with =frame= sample code
#+begin_example
\begin{frame}
  Here is a beamer frame.
\end{frame}
#+end_example
This is exported in an =orgframe= environment, since contains =\begin{frame}= and =\end{frame}=.

* An ordinary frame
\[ z^n = x^n + y^n \]
This is exported in a =frame= environment.

% Created 2024-03-12 Tue 15:28
% Intended LaTeX compiler: pdflatex
\documentclass[presentation]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\newenvironment<>{orgframe}[1][]{\begin{frame}#2[environment=orgframe,#1]}{\end{frame}}
\usetheme{default}
\date{\today}
\title{}
\hypersetup{
 pdfauthor={},
 pdftitle={},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 29.1 (Org mode 9.7-pre)}, 
 pdflang={English}}
\begin{document}

\begin{frame}{Outline}
\tableofcontents
\end{frame}

\begin{frame}[label={sec:org5fbeeef},fragile]{A frame with \texttt{orgframe} sample code}
 \begin{verbatim}
\begin{orgframe}
  Here is a beamer frame.
\end{orgframe}
\end{verbatim}
This is exported in a \texttt{frame} environment, although it is marked as fragile.
\end{frame}
\begin{orgframe}[label={sec:org500e0c5},fragile]{A frame with \texttt{frame} sample code}
 \begin{verbatim}
\begin{frame}
  Here is a beamer frame.
\end{frame}
\end{verbatim}
This is exported in an \texttt{orgframe} environment, since contains \texttt{\textbackslash{}begin\{frame\}} and \texttt{\textbackslash{}end\{frame\}}.
\end{orgframe}
\begin{frame}[label={sec:orga2d3f31},fragile]{An ordinary frame}
 \[ z^n = x^n + y^n \]
This is exported in a \texttt{frame} environment.
\end{frame}
\end{document}

Attachment: customize-frame.pdf
Description: customize-frame.pdf

Reply via email to