From: "Pedro A. Aranda" <paaguti@gmail.com>
To: Org Mode List <emacs-orgmode@gnu.org>
Cc: Ihor Radchenko <yantar92@posteo.net>
Subject: [PATCH]: make ox-latex obey global export title/author settings
Date: Mon, 3 Feb 2025 16:59:45 +0100 [thread overview]
Message-ID: <bf256c2d-f7e5-4c33-8f96-0c7aa6eb6e45@gmail.com> (raw)
In-Reply-To: <80e9da5a-4058-4327-8c0b-8d7e9c82d6ac@gmail.com>
[-- 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
prev parent reply other threads:[~2025-02-03 16:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=bf256c2d-f7e5-4c33-8f96-0c7aa6eb6e45@gmail.com \
--to=paaguti@gmail.com \
--cc=emacs-orgmode@gnu.org \
--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).