From: Leo Butler <Leo.Butler@umanitoba.ca>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: Ihor Radchenko <yantar92@gmail.com>,
Daniel Fleischer <danflscr@gmail.com>,
Org Mode Mailing List <emacs-orgmode@gnu.org>
Subject: Re: [BUG] beamer export
Date: Mon, 29 Jan 2024 21:36:19 +0000 [thread overview]
Message-ID: <87v87bstyl.fsf@t14.reltub.ca> (raw)
In-Reply-To: <87wmrvlsso.fsf@t14.reltub.ca> (Leo Butler's message of "Fri, 26 Jan 2024 20:54:17 +0000")
[-- Attachment #1: Type: text/plain, Size: 2303 bytes --]
On Fri, Jan 26 2024, Leo Butler <Leo.Butler@umanitoba.ca> wrote:
> On Fri, Jan 26 2024, Ihor Radchenko <yantar92@posteo.net> wrote:
>
>> Leo Butler <Leo.Butler@umanitoba.ca> writes:
>>
>>>> Apparently, LaTeX has really hard time processing verbatim code inside
>>>> beamer frames.
>>>
>>> I looked again at the solution here:
>>> https://tex.stackexchange.com/questions/140719/verbatim-in-beamer-showing-error-file-ended-while-scanning-use-of-xverbatim
>>>
>>> and it errors out with a recent version of pdflatex:
>>>
>>> This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023/Debian) (preloaded format=pdflatex)
>>>
>>> This is, apparently, a known problem:
>>>
>>> https://github.com/josephwright/beamer/issues/360
>>>
>>> The end of that issue report includes a work-around that we might apply
>>> in org. I have attached a patch for your feedback. The example that
>>> stimulated this discussion compiles with the patch and the testsuite
>>> shows no errors related to it.
>>
>> Thanks!
>> I have concerns about your approach though.
>>
>> You are replacing all the frame environments with custom environment
>> unconditionally. However, custom environment has downsides. For example,
>> \againframe will stop working, as pointed earlier in the linked beamer
>> thread
>> https://github.com/josephwright/beamer/issues/360#issuecomment-708705250
>
> The comment that you are citing shows how to define the custom
> environment so that \againframe works correctly. See the attachment
> `beamer-example-againframe.tex' and pdf. You can see that \againframe
> works with the custom environment.
>
>>
>> Since the problem appears only when the frame contents contains
>> \end{frame}, it may be sufficient to replace the standard frame
>> environment with the workaround only in such scenario.
>
> Yes, that might be true. But my feeling is that it would be simpler and
> more robust to use the custom frame environment in most cases.
Replying to self: Attached is a patch that adds a property,
BEAMER_FRAME, that lets the frame environment name be set on a
frame-by-frame basis. In addition, it typesets any fragile frame in the
`orgframe' environment. I am not sure if the latter is really needed,
given the former.
Comments?
Leo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-lisp-ox-beamer.el-customize-the-beamer-frame-environ.patch --]
[-- Type: text/x-diff; name="0002-lisp-ox-beamer.el-customize-the-beamer-frame-environ.patch", Size: 5384 bytes --]
From d0117ca35405654c6adc003252eff5a1f629b67a Mon Sep 17 00:00:00 2001
From: Leo Butler <leo.butler@umanitoba.ca>
Date: Thu, 25 Jan 2024 09:48:20 -0600
Subject: [PATCH] lisp/ox-beamer.el: customize the beamer frame environment
name
* lisp/ox-beamer.el (org-beamer-frame-environment): A new customize
variable that contains the name of an environment that serves as an
alias for the beamer frame environment.
(org-beamer--format-frame): Introduce the new property, :BEAMER_FRAME.
If set in the headline, use that as name of the frame environment.
Otherwise, in frames marked as fragile, the name of the frame
environment is taken from `org-beamer--frame-environment'. In all
other frames, the default name is frame. Unless the frame name is
"frame", the name is added to the list
`org-beamer--frame-environments'.
(org-beamer--frame-environments): New variable and function. The
variable holds a list of names of frame environments found while
formatting frames. The function generates the LaTeX code to define
each new frame environment.
(org-beamer-template): Add a call to `org-beamer--frame-environments'
to insert the environment definitions into the beamer document.
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]. Since the frame
environment name is customize-able, beamer code generated by ox-beamer
can be included inside the verbatim environment, simply by changing
the frame environment name via the :BEAMER_FRAME property.
This solution also works with instances of \againframe.
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 | 44 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 7 deletions(-)
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 82c8841aa..4a1e09b85 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -149,9 +149,17 @@ which is replaced with the subtitle."
:package-version '(Org . "8.3")
:type '(string :tag "Format string"))
+(defcustom org-beamer-frame-environment "orgframe"
+ "Name of the beamer frame environment."
+ :group 'org-export-beamer
+ :type '(string :tag "Beamer frame"))
+
\f
;;; Internal Variables
+(defvar org-beamer--frame-environments '()
+ "List of beamer frame environments.")
+
(defconst org-beamer-column-widths
"0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.0 :ETC"
"The column widths that should be installed as allowed property values.")
@@ -409,12 +417,17 @@ used as a communication channel."
"Format HEADLINE as a frame.
CONTENTS holds the contents of the headline. INFO is a plist
used as a communication channel."
- (let ((fragilep
- ;; FRAGILEP is non-nil when HEADLINE contains an element
- ;; among `org-beamer-verbatim-elements'.
- (org-element-map headline org-beamer-verbatim-elements 'identity
- info 'first-match)))
- (concat "\\begin{frame}"
+ (let* ((fragilep
+ ;; FRAGILEP is non-nil when HEADLINE contains an element
+ ;; among `org-beamer-verbatim-elements'.
+ (org-element-map headline org-beamer-verbatim-elements 'identity
+ info 'first-match))
+ (frame (or (org-element-property :BEAMER_FRAME headline)
+ (and fragilep org-beamer-frame-environment)
+ "frame")))
+ (unless (string= frame "frame")
+ (add-to-list 'org-beamer--frame-environments frame))
+ (concat "\\begin{" frame "}"
;; Overlay specification, if any. When surrounded by
;; square brackets, consider it as a default
;; specification.
@@ -481,7 +494,7 @@ used as a communication channel."
;; output.
(if (not fragilep) contents
(replace-regexp-in-string "\\`\n*" "\\& " (or contents "")))
- "\\end{frame}")))
+ "\\end{" frame "}")))
(defun org-beamer--format-block (headline contents info)
"Format HEADLINE as a block.
@@ -805,6 +818,21 @@ contextual information."
(org-export-get-reference radio-target info)
text))
+;;;; Frame Environments
+;;
+;; Define any needed frame environments.
+
+(defun org-beamer--frame-environments ()
+ "Define beamer frame environments.
+This function is called once from `org-beamer-template'. As a
+side-effect, it resets `org-beamer--frame-environments' to nil."
+ (prog1
+ (string-join
+ (mapcar
+ #'(lambda(frame)
+ (format "\\newenvironment<>{%s}[1][]{\\begin{frame}[environment=%s,#1]}{\\end{frame}}\n" frame frame))
+ org-beamer--frame-environments))
+ (setq org-beamer--frame-environments '())))
;;;; Template
;;
@@ -825,6 +853,8 @@ holding export options."
(org-latex--insert-compiler info)
;; Document class and packages.
(org-latex-make-preamble info)
+ ;; Define the frame environments, if needed.
+ (org-beamer--frame-environments)
;; Insert themes.
(let ((format-theme
(lambda (prop command)
--
2.43.0
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: customize-frame.org --]
[-- Type: text/org; name="customize-frame.org", Size: 625 bytes --]
#+startup: beamer
#+LaTeX_CLASS: beamer
* A frame with =verbatim= contents
#+begin_example
\begin{frame}
Here is a beamer frame.
\end{frame}
#+end_example
This is typeset in an =orgframe= environment, since it is marked as fragile.
* An ordinary frame
\[ z^n = x^n + y^n \]
This is typeset in a =frame= environment.
* A frame with =:BEAMER_FRAME= property set
:PROPERTIES:
:BEAMER_FRAME: special-frame
:END:
#+begin_example
\begin{orgframe}
Here is a beamer orgframe.
\end{orgframe}
#+end_example
This is typeset in a =special-frame= environment, otherwise a LaTeX error will be thrown.
next prev parent reply other threads:[~2024-01-29 21:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-28 19:46 [BUG] beamer export Leo Butler
2022-09-29 2:45 ` Ihor Radchenko
2022-09-29 18:43 ` Daniel Fleischer
2022-12-10 12:49 ` Ihor Radchenko
2024-01-20 14:56 ` Ihor Radchenko
2024-01-23 16:58 ` Leo Butler
2024-01-24 16:06 ` Ihor Radchenko
2024-01-25 16:13 ` Leo Butler
2024-01-26 11:45 ` Ihor Radchenko
2024-01-26 20:54 ` Leo Butler
2024-01-29 21:36 ` Leo Butler [this message]
2024-02-01 15:04 ` Ihor Radchenko
2024-02-14 16:13 ` Leo Butler
2024-02-19 9:42 ` Ihor Radchenko
2024-02-20 20:41 ` Leo Butler
2024-02-21 10:51 ` Ihor Radchenko
2024-01-25 22:29 ` Leo Butler
2024-01-26 13:30 ` 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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
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=87v87bstyl.fsf@t14.reltub.ca \
--to=leo.butler@umanitoba.ca \
--cc=danflscr@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@gmail.com \
--cc=yantar92@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* 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
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).