Version 2 with the requested addition (documented)

Best, /PA

On Sun, 25 Jan 2026 at 14:02, Ihor Radchenko <[email protected]> wrote:

> Pedro Andres Aranda Gutierrez <[email protected]> writes:
>
> > 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.
> > ...
> > +(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)
>
> I have no problem adding such an option, but please add it into
> :options-alist. Something like
> (:latex-use-sans nil "latex-use-sans" org-latex-use-sans)
>
> Then, you can simply
> #+OPTIONS: latex-use-sans:t
> inside the Org file without having to do buffer-locals.
>
> --
> Ihor Radchenko // yantar92,
> Org mode maintainer,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
>


-- 
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 1 of the New Koprocracy
From a1a4df8184989734297867bf7fe3afa54f509d7c Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <[email protected]>
Date: Sun, 25 Jan 2026 19:13:13 +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            | 11 +++++++++++
 etc/ORG-NEWS                  |  7 +++++++
 lisp/ox-latex.el              | 15 ++++++++++++++-
 testing/lisp/test-ox-latex.el | 26 ++++++++++++++++++++++++++
 4 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 8f917a57e..10010f0df 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -14409,6 +14409,17 @@ 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. You can also
+include it in the document options with:
+
+#+begin_example
+#+OPTIONS: latex-use-sans:t
+#+end_example
+
+
 *** 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..9e48c7a16 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -170,6 +170,7 @@
     (:latex-title-command nil nil org-latex-title-command)
     (:latex-toc-command nil nil org-latex-toc-command)
     (:latex-compiler "LATEX_COMPILER" nil org-latex-compiler)
+    (:latex-use-sans nil "latex-use-sans" org-latex-use-sans)
     ;; Redefine regular options.
     (:date "DATE" nil "\\today" parse)))
 
@@ -1559,6 +1560,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 +2042,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.43.0

Reply via email to