Ihor Radchenko <yanta...@posteo.net> writes:

> I agree that obeying :with-creator in hyperref template makes sense.

Great, can Pedro's and my patches be merged then? I re-attached them
here.

>From adbd4d4d14659fd8930ed9947ffb97696c4289da Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <paag...@gmail.com>
Date: Tue, 28 Jan 2025 10:16:20 +0100
Subject: [PATCH 1/2] obet with-title and with-author

---

lisp/ox-latex.el: Obey :with-author and :with-title when exporting

* lisp/ox-latex.el (org-latex-template) Do not generate `\title{}'
and related when :with-title is nil. Do not generate `\author{}' and
related when :with-author is nil. Fix `\hypersetup{}' accordingly.

 lisp/ox-latex.el | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

Reported-by: "Antero Mejr"
Link: https://lists.gnu.org/archive/html/emacs-orgmode/2025-01/msg00313.html

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 16f8f5af2..409fa98cb 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)
-- 
2.34.1

>From 46eedaf8c71446c2d12f5484ecced491ae7ae760 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <paag...@gmail.com>
Date: Tue, 28 Jan 2025 10:59:12 +0100
Subject: [PATCH 2/2] Test last patch and announce it in ORG-NEWS

---

etc/ORG-NEWS: Announce fix for :with-title and :with-author
testing/lisp/test-ox-latex.el: Add to tests for fixed behaviour

* etc/ORG-NEWS: Announce fix for :with-title and :with-author
* testing/lisp/test-ox-latex.el: (test-ox-latex/with-title-nil)
Make sure the title is not included in the generated LaTeX if
:with-title is nil
(test-ox-latex/with-author-nil)
Make sure the author is not included in the generated LaTeX if
:with-author is nil

 etc/ORG-NEWS                  |  7 ++++++
 testing/lisp/test-ox-latex.el | 44 +++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

Reported-by: "Antero Mejr"
Link: https://lists.gnu.org/archive/html/emacs-orgmode/2025-01/msg00313.html

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index cb2c16da8..7fa30223f 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -527,6 +527,13 @@ 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.
 
+*** =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/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 892ac4437..be107f510 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -127,5 +127,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

>From 81106718ffd0c5341a5de03d0f0a615832d7d504 Mon Sep 17 00:00:00 2001
From: Antero Mejr <m...@antr.me>
Date: Tue, 28 Jan 2025 14:13:35 -0500
Subject: [PATCH] lisp/ox-latex.el: Obey :with-creator when exporting

* lisp/ox-latex.el (org-latex-template) Do not fill pdfcreator
hypersetup field when :with-creator is nil.
---
 lisp/ox-latex.el | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 409fa98cb..8884cf786 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2061,6 +2061,9 @@ holding export options."
          (unless (plist-get info :with-title)
            ;; Replace title *and* subtitle
            (setq template (replace-regexp-in-string "%[ts]" "" template)))
+         (unless (plist-get info :with-creator)
+           ;; Replace creator
+           (setq template (replace-regexp-in-string "%c" "" template)))
          (format-spec template spec)))
      ;; engrave-faces-latex preamble
      (when (and (eq (plist-get info :latex-src-block-backend) 'engraved)
-- 
2.43.0

Reply via email to