Hi
this patch automates including
\renewcommand*\familydefault{\sfdefault}
in the LaTeX preamble when you want to typeset with Sans fonts, instead of
having to include
#+LATEX_HEADER: \renewcommand*\familydefault{\sfdefault}
in the Org document.
Cheers, /PA
--
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler
"Sagen's Paradeiser" (ORF: Als Radiohören gefährlich war) => write BE!
Year 2 of the New Koprocracy
From 2ef512cd9bb3e73446aa21b77e31c3ade2a03675 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <[email protected]>
Date: Thu, 15 Jan 2026 12:46:25 +0100
Subject: [PATCH] New option (org-latex-use-sans): Control using Sans as
default font
* lisp/ox-latex.el: (org-latex-use-sans) : new defcustom
(org-latex-make-preamble): add command to typeset using the Sans
family after LATEX_HEADER_EXTRA if not a snippet
and (org-latex-use-sans) is not nil
* testing/lisp/test-ox-latex.el: Two tests for (org-latex-use-sans)
* doc/org-manual.org: document (org-latex-use-sans)
* etc/ORG-NEWS: announce (org-latex-use-sans)
---
doc/org-manual.org | 5 +++++
etc/ORG-NEWS | 7 +++++++
lisp/ox-latex.el | 14 +++++++++++++-
testing/lisp/test-ox-latex.el | 26 ++++++++++++++++++++++++++
4 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index 8f917a57e..707e2f21f 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -14409,6 +14409,11 @@ This would produce in LaTeX (with the actual =polyglossia= syntax):
\setotherlanguage{french}
#+end_example
+The LaTeX backend normally exports using the Roman font family
+specified in the document class or by the user in the
+=LATEX_HEADER=. Setting the option ~org-latex-use-sans~ to =t= will
+force the LaTeX compiler to use the Sans font as default.
+
*** Quoting LaTeX code
:PROPERTIES:
:DESCRIPTION: Incorporating literal @LaTeX{} code.
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 2e1f79f8c..45b0760b2 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -485,6 +485,13 @@ the suffix of =:file= is the primary determinant, and =:file-ext=
secondary. Header arguments =:pdf= and =:eps= are supported for
backwards compatibility. Default output type is still PNG.
+*** New option ~org-latex-use-sans~
+
+This option specifies the PDF should be typeset using the Sans font
+specified in the document class (or the user) instead of the default
+font (i.e. the Roman font).
+
+
** New functions and changes in function arguments
# This also includes changes in function behavior from Elisp perspective.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index a63013adf..803150cb9 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1559,6 +1559,15 @@ property to `toc'"
:type 'boolean
:safe #'booleanp)
+(defcustom org-latex-use-sans nil
+ "Whether to typeset the document with the Sans font family.
+
+The default behaviour is to typeset with the Roman font family."
+ :group 'org-export-latex
+ :package-version '(Org . "9.8")
+ :type 'boolean
+ :safe #'booleanp)
+
;;; Internal Functions
@@ -2032,7 +2041,10 @@ specified in `org-latex-default-packages-alist' or
(mapconcat #'org-element-normalize-string
(list (plist-get info :latex-header)
(and (not snippet?)
- (plist-get info :latex-header-extra)))
+ (plist-get info :latex-header-extra))
+ (and (not snippet?)
+ org-latex-use-sans
+ "\\renewcommand*\\familydefault{\\sfdefault}"))
""))))
info)
info)))
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 64ab7d467..2cf7be0bc 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -272,6 +272,32 @@ is suppressed
(should (search-forward "}
\\addcontentsline{toc}{section}{Section 3}")))))
+(ert-deftest test-ox-latex/use-sans ()
+ "Test `org-latex-use-sans' set to t."
+ (let ((org-latex-use-sans t))
+ (org-test-with-exported-text 'latex
+ "#+TITLE: Test sans fonts
+* Test
+
+Fake test document
+"
+ (goto-char (point-min))
+ (should (search-forward "\\renewcommand*\\familydefault{\\sfdefault}" nil t))
+ (should (search-forward "\\begin{document}" nil t)))))
+
+(ert-deftest test-ox-latex/use-sans-default ()
+ "Test `org-latex-use-sans' default setting."
+ (org-test-with-exported-text 'latex
+ "#+TITLE: Test no sans fonts
+* Test
+
+Fake test document
+"
+ (goto-char (point-min))
+ (should-not (search-forward "\\renewcommand*\\familydefault{\\sfdefault}" nil t))
+ (goto-char (point-min))
+ (should (search-forward "\\begin{document}" nil t))))
+
(ert-deftest test-ox-latex/math-in-alt-title ()
"Test math wrapping in ALT_TITLE properties."
(org-test-with-exported-text
--
2.34.1