Second patch attached as promised...

Best, /PA
From b6d68bcd626f5f09881893e3f07031517c4bab6b Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <paag...@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 <m...@antr.me>
Link: https://list.orgmode.org/87a5bbwwcz....@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

Reply via email to