emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
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: Thu, 25 Jan 2024 16:13:49 +0000	[thread overview]
Message-ID: <871qa5qtl0.fsf@t14.reltub.ca> (raw)
In-Reply-To: <87le8eg1hs.fsf@localhost> (Ihor Radchenko's message of "Wed, 24 Jan 2024 16:06:07 +0000")

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

On Wed, Jan 24 2024, Ihor Radchenko <yantar92@posteo.net> wrote:

> Leo Butler <Leo.Butler@umanitoba.ca> writes:
>
>>>> 1. ox-latex export bug for src blocks containing direct LaTeX when
>>>>    org-latex-src-block-backend is set to its default 'verbatim value
>>>
>>> This appears to be Beamer-specific problem with verbatim environments:
>>> https://tex.stackexchange.com/questions/140719/verbatim-in-beamer-showing-error-file-ended-while-scanning-use-of-xverbatim
>>>
>>> The solution might be to use [fragile] frame parameter, but that might
>>> have its own drawbacks:
>>> https://tex.stackexchange.com/questions/136240/drawbacks-of-using-fragile-frames-in-beamer
>>
>> Yes, an *automatic* solution may create more problems than it solves.
>> Although, I do note that ox-beamer does mark some frames as fragile already.
>> I wonder how difficult it would be to add a property drawer to frames,
>> so (amongst other things), they could be marked fragile?
>
> Hmm. Actually, that frame is already marked fragile.
> Yet, it is not enough...



> 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.

>
>>>> 2. ox-beamer export bug as described in the attached org file
>>>
>>> This is not a bug. When you specify ignoreheading environment, you imply
>>> that the contents of the heading is to be included as is.
>>> If you want the contents to become a column, you should specify column
>>> environment.
>>
>> I see. That is not now the ignoreheading property is described. It says
>> [1]:
>>
>>     ... As the text in the slide says, the left column is a list and the
>>     right one is an image. The left column's headline text is ignored,
>>     specified by =C-c C-b i= which tells org to *ignore* the headline
>>     text completely.
>>
>> I think the documentation and example needs to be corrected. I have
>> attached a patch.
>
> Thanks! Applied.
> https://git.sr.ht/~bzg/worg/commit/aedea59f

Thanks. I can see the commit on master in git, but the webpage seems to
be unchanged.

https://orgmode.org/worg/exporters/beamer/tutorial.html

Leo


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ox-beamer.el-randomize-the-beamer-frame-environ.patch --]
[-- Type: text/x-diff; name="0001-lisp-ox-beamer.el-randomize-the-beamer-frame-environ.patch", Size: 3216 bytes --]

From 9cb3489e3fe80fb2e3996b737f528aa4db9ba62d 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:  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


  reply	other threads:[~2024-01-25 17:19 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 [this message]
2024-01-26 11:45           ` Ihor Radchenko
2024-01-26 20:54             ` Leo Butler
2024-01-29 21:36               ` Leo Butler
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=871qa5qtl0.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).