emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH]: make ox-beamer obey global export title/author settings
@ 2025-02-03 15:43 Pedro A. Aranda
  2025-02-03 15:59 ` [PATCH]: make ox-latex " Pedro A. Aranda
  0 siblings, 1 reply; 2+ messages in thread
From: Pedro A. Aranda @ 2025-02-03 15:43 UTC (permalink / raw)
  To: Org Mode List; +Cc: Ihor Radchenko

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

Hi,

Attached is the patch for ox-beamer.el for the bug reported in

https://list.orgmode.org/87a5bbwwcz.fsf@antr.me/

Unified patch for ox-latex.el following.

Best, /PA

[-- Attachment #2: 0001-Honour-export-with-in-ox-beamer.patch --]
[-- Type: text/x-patch, Size: 6158 bytes --]

From 2bc2a27b31dc51b66f597f19a076330c35ad7022 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <paaguti@gmail.com>
Date: Mon, 3 Feb 2025 12:47:38 +0100
Subject: [PATCH] Honour export-with in ox-beamer

ox-beamer: Honour `org-export-with-title' and `org-export-with-author'

* lisp/ox-beamer.el (org-beamer--frame-level): Add checks to suppress title or
author when `org-export-with-title' or `org-export-with-author' are `nil'.
* testing/lisp/test-ox-beamer.el (test-ox-beamer-with-author): Test fix when
`org-export-with-author' is `nil'.
(test-ox-beamer-with-author): Test fix when `org-export-with-author' is `nil'.
* etc/ORG-NEWS: Announce bug fix

Reported by: Antero Mejr <mail@antr.me>
Link: https://list.orgmode.org/87a5bbwwcz.fsf@antr.me/

---
 etc/ORG-NEWS                   |  5 ++++
 lisp/ox-beamer.el              | 35 +++++++++++++++-----------
 testing/lisp/test-ox-beamer.el | 45 ++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 14 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index cb2c16da8..7fc85ae79 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -527,6 +527,11 @@ were tangled into a file named =NAME.bibtex=.  Now, they are tangled
 into a file named =FILE.bib=, using the standard extension =.bib=,
 matching the rest of the ecosystem, including BibTeX and LaTeX.

+*** Fixed beamer export control via ~org-export-with-title~ and ~org-export-with-author~
+
+Globat settings controlled by ~org-export-with-title~ and
+~org-export-with-author~ are now honoured when exporting to Beamer.
+
 * Version 9.7

 ** Important announcements and breaking changes
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index e862da99d..56ef91f3d 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -900,30 +900,37 @@ holding export options."
      (let ((sec-num (plist-get info :section-numbers)))
        (when (integerp sec-num)
 	 (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
-     ;; Author.
-     (let ((author (and (plist-get info :with-author)
-			(let ((auth (plist-get info :author)))
-			  (and auth (org-export-data auth info)))))
-	   (email (and (plist-get info :with-email)
-		       (org-export-data (plist-get info :email) info))))
-       (cond ((and author email (not (string= "" email)))
-	      (format "\\author{%s\\thanks{%s}}\n" author email))
-	     ((or author email) (format "\\author{%s}\n" (or author email)))))
+     (when (plist-get info :with-author)
+       ;; Author.
+       (let ((author (and (plist-get info :with-author)
+			  (let ((auth (plist-get info :author)))
+			    (and auth (org-export-data auth info)))))
+	     (email (and (plist-get info :with-email)
+		         (org-export-data (plist-get info :email) info))))
+         (cond ((and author email (not (string= "" email)))
+	        (format "\\author{%s\\thanks{%s}}\n" author email))
+	       ((or author email) (format "\\author{%s}\n" (or author email))))))
      ;; Date.
      (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
        (format "\\date{%s}\n" (org-export-data date info)))
      ;; Title
-     (format "\\title{%s}\n" title)
-     (when (org-string-nw-p subtitle)
-       (concat (format (plist-get info :beamer-subtitle-format) subtitle) "\n"))
+     (when (and (plist-get info :with-title) title)
+       (format "\\title{%s}\n" title)
+       ;; Subtitle only makes sense if title is generated
+       (when (org-string-nw-p subtitle)
+         (concat (format (plist-get info :beamer-subtitle-format) subtitle) "\n")))
      ;; Beamer-header
      (let ((beamer-header (plist-get info :beamer-header)))
        (when beamer-header
 	 (format "%s\n" (plist-get info :beamer-header))))
      ;; 9. Hyperref options.
      (let ((template (plist-get info :latex-hyperref-template)))
-       (and (stringp template)
-	    (format-spec template (org-latex--format-spec info))))
+       (when (stringp template)
+         (unless (plist-get info :with-author) ;; produce empty pdfauthor
+           (setq template (replace-regexp-in-string "%a" "" template)))
+         (unless (plist-get info :with-title)  ;; produce empty pdftitle
+           (setq template (replace-regexp-in-string "%t" "" template)))
+	 (format-spec template (org-latex--format-spec info))))
      ;; engrave-faces-latex preamble
      (when (and (eq (plist-get info :latex-src-block-backend) 'engraved)
                 (org-element-map (plist-get info :parse-tree)
diff --git a/testing/lisp/test-ox-beamer.el b/testing/lisp/test-ox-beamer.el
index f5743409f..5fcfa4a52 100644
--- a/testing/lisp/test-ox-beamer.el
+++ b/testing/lisp/test-ox-beamer.el
@@ -106,5 +106,50 @@ Here is a second example:
      (should (search-forward (concat "\\end{frame}") nil t))
      (should (search-forward (concat "\\end{" org-beamer-frame-environment "}"))))))

+(ert-deftest test-ox-beamer-with-author()
+  "Test that setting `org-export-with-author' to `nil' suppressed the author
+from the generated LaTeX"
+  (let ((org-export-with-author nil))
+    (org-test-with-exported-text
+     'beamer
+     "#+STARTUP: beamer
+#+TITLE: Title
+#+SUBTITLE: SubTitle
+#+AUTHOR: Yo
+#+LATEX_CLASS: beamer
+#+LATEX_CLASS_OPTIONS: [presentation]
+#+BEAMER_THEME: Boadilla
+#+OPTIONS: H:2 toc:t num:t
+
+* Hola
+** Hola 1
+- Hola2"
+     (goto-char (point-min))
+     (should-not (search-forward "\\author{Yo}" nil t))
+     (goto-char (point-min))
+     (should (search-forward " pdfauthor={}," nil t)))))
+
+(ert-deftest test-ox-beamer-with-title()
+  "Test that setting `org-export-with-title' to `nil' suppressed the author
+from the generated LaTeX"
+  (let ((org-export-with-title nil))
+    (org-test-with-exported-text
+     'beamer
+     "#+STARTUP: beamer
+#+TITLE: Title
+#+SUBTITLE: SubTitle
+#+AUTHOR: Yo
+#+LATEX_CLASS: beamer
+#+LATEX_CLASS_OPTIONS: [presentation]
+#+BEAMER_THEME: Boadilla
+#+OPTIONS: H:2 toc:t num:t
+
+* Hola
+** Hola 1
+- Hola2"
+     (goto-char (point-min))
+     (should-not (search-forward "\\title{Title}" nil t))
+     (goto-char (point-min))
+     (should (search-forward " pdftitle={}," nil t)))))
 (provide 'test-ox-beamer)
 ;;; test-ox-beamer.el ends here
--
2.34.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH]: make ox-latex obey global export title/author settings
  2025-02-03 15:43 [PATCH]: make ox-beamer obey global export title/author settings Pedro A. Aranda
@ 2025-02-03 15:59 ` Pedro A. Aranda
  0 siblings, 0 replies; 2+ messages in thread
From: Pedro A. Aranda @ 2025-02-03 15:59 UTC (permalink / raw)
  To: Org Mode List; +Cc: Ihor Radchenko

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

Second patch attached as promised...

Best, /PA

[-- Attachment #2: 0002-ox-latex.el-obey-with-author-and-with-title.patch --]
[-- Type: text/x-patch, Size: 5303 bytes --]

From b6d68bcd626f5f09881893e3f07031517c4bab6b Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <paaguti@gmail.com>
Date: Mon, 3 Feb 2025 16:48:45 +0100
Subject: [PATCH 2/2] ox-latex.el: obey with-author and with-title


* lisp/ox-latex.el (org-latex-template): Add checks to suppress title or
author when `org-export-with-title' or `org-export-with-author' are `nil'.
* testing/lisp/test-ox-latex.el (test-ox-latex/with-title-nil): Check
that title is suppressed when `org-export-with-title' is `nil'.
(test-ox-latex/with-author-nil): Checkthat author is suppressed when
`org-export-with-author' is `nil'.
* etc/ORG-NEWS: Anoounce bug fix

Reported by: Antero Mejr <mail@antr.me>
Link: https://list.orgmode.org/87a5bbwwcz.fsf@antr.me/

---
 etc/ORG-NEWS                  |  7 ++++++
 lisp/ox-latex.el              | 32 ++++++++++++++-----------
 testing/lisp/test-ox-latex.el | 44 +++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 13 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 7fc85ae79..63b5d373b 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -532,6 +532,13 @@ matching the rest of the ecosystem, including BibTeX and LaTeX.
 Globat settings controlled by ~org-export-with-title~ and
 ~org-export-with-author~ are now honoured when exporting to Beamer.

+*** =ox-latex=: fixed =:with-title= and =:with-author= handling
+
+The LaTeX exporter will not include the author in the resulting
+document if the =:with-author= property is ~nil~; the same will happen
+for =:with-title=. These properties are set with the
+~org-export-with-author~ and ~org-export-with-title~ global variables.
+
 * Version 9.7

 ** Important announcements and breaking changes
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index bc31df6f5..061de9835 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2041,21 +2041,27 @@ holding export options."
      (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
        (format "\\date{%s}\n" (org-export-data date info)))
      ;; Title and subtitle.
-     (let* ((subtitle (plist-get info :subtitle))
-	    (formatted-subtitle
-	     (when subtitle
-	       (format (plist-get info :latex-subtitle-format)
-		       (org-export-data subtitle info))))
-	    (separate (plist-get info :latex-subtitle-separate)))
-       (concat
-	(format "\\title{%s%s}\n" title
-		(if separate "" (or formatted-subtitle "")))
-	(when (and separate subtitle)
-	  (concat formatted-subtitle "\n"))))
+     (when (plist-get info :with-title)
+       (let* ((subtitle (plist-get info :subtitle))
+	      (formatted-subtitle
+	       (when subtitle
+	         (format (plist-get info :latex-subtitle-format)
+		         (org-export-data subtitle info))))
+	      (separate (plist-get info :latex-subtitle-separate)))
+         (concat
+	  (format "\\title{%s%s}\n" title
+		  (if separate "" (or formatted-subtitle "")))
+	  (when (and separate subtitle)
+	    (concat formatted-subtitle "\n")))))
      ;; Hyperref options.
      (let ((template (plist-get info :latex-hyperref-template)))
-       (and (stringp template)
-            (format-spec template spec)))
+       (when (stringp template)
+         (unless (plist-get info :with-author)
+           (setq template (replace-regexp-in-string "%a" "" template)))
+         (unless (plist-get info :with-title)
+           ;; Replace title *and* subtitle
+           (setq template (replace-regexp-in-string "%[ts]" "" template)))
+         (format-spec template spec)))
      ;; engrave-faces-latex preamble
      (when (and (eq (plist-get info :latex-src-block-backend) 'engraved)
                 (org-element-map (plist-get info :parse-tree)
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index b75921ae7..a90d9a306 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -154,5 +154,49 @@ Column & Column \\\\
      (search-forward
       "\\href{https://orgmode.org/worg/images/orgmode/org-mode-unicorn.svg}{\\includegraphics[width=.9\\linewidth]{/wallpaper.png}}"))))

+(ert-deftest test-ox-latex/with-title-nil ()
+  "Test suppressing title in exported LaTeX"
+  (let ((org-export-with-title nil))
+    (org-test-with-exported-text
+     'latex
+     "#+AUTHOR: me
+#+TITLE: Supressed
+
+* A test
+A wonderful text"
+     (goto-char (point-min))
+     (should-not
+      (search-forward "\\maketitle" nil t))
+     (goto-char (point-min))
+     (should-not
+      (search-forward "\\title{Suppressed}" nil t))
+     (goto-char (point-min))
+     (should-not
+      (search-forward "pdftitle={Suppressed}," nil t))
+     (goto-char (point-min))
+     (should
+      (search-forward "pdftitle={},"))
+     )))
+
+(ert-deftest test-ox-latex/with-author-nil ()
+  "Test suppressing author in exported LaTeX"
+  (let ((org-export-with-author nil))
+    (org-test-with-exported-text
+     'latex
+     "#+AUTHOR: me
+#+TITLE: Supressed
+
+* A test
+A wonderful text"
+     (goto-char (point-min))
+     (should-not
+      (search-forward "\\author{me}" nil t))
+     (goto-char (point-min))
+     (should-not
+      (search-forward "pdftitle={me}," nil t))
+     (goto-char (point-min))
+     (should
+      (search-forward "pdfauthor={},"))
+     )))
 (provide 'test-ox-latex)
 ;;; test-ox-latex.el ends here
--
2.34.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-03 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-03 15:43 [PATCH]: make ox-beamer obey global export title/author settings Pedro A. Aranda
2025-02-03 15:59 ` [PATCH]: make ox-latex " Pedro A. Aranda

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