Hi Ihor

after the lengthy exchange on the scientific notation in tables for latex export, please find attached a patch with a (hopefully) comprehensive solution.

If you give me the heads up, I'll push to main
Best, /PA
--
Pedro A. Aranda
ox-latex & ox-beamer maintainer

Sagen's Paradeiser! (ORF: Als Radiohören gefährlich war) => write BE!
IA: onomatopeya del rebuzno
2nd year of the New Koprocracy
From 74824dbcabb699ac80a94a57d0ed9fd7587f991f Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <[email protected]>
Date: Thu, 8 Oct 2026 06:54:57 +0200
Subject: [PATCH] ox-latex: safe, keyword, and test for
 org-latex-table-scientific-notation

* etc/ORG-NEWS: Announce new keyword.
* doc/org-manual.org (*** Tables in LaTeX export): Document new keyword
and use of the variable.
* lisp/ox-latex.el (backend): Add keyword LATEX_TABLE_SCI_NOTATION.
(org-latex-table-scientific-notation): Add :safe declaration.
* testing/lisp/test-ox-latex.el (test-ox-latex/sci-notation): Test the
new keyword.

Reported by: Angelo Graziosi
Link: https://list.orgmode.org/[email protected]
---
 doc/org-manual.org            | 16 ++++++++++++----
 etc/ORG-NEWS                  |  6 ++++++
 lisp/ox-latex.el              |  5 +++--
 testing/lisp/test-ox-latex.el | 19 +++++++++++++++++++
 4 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index d4389a281..328361138 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -14838,10 +14838,13 @@ Set the caption with the LaTeX command
 #+vindex: org-latex-packages-alist
 If your table has numbers in scientific notation, you can control how
 they are shown with the variable
-~org-latex-table-scientific-notation~. For example:
+~org-latex-table-scientific-notation~. This variable can be set in the
+document header with the keyword ~#+LATEX_TABLE_SCI_NOTATION:~

-#+begin_src emacs-lisp
-(setq org-latex-table-scientific-notation "\\num{%se%s}")
+For example:
+
+#+begin_src org
+,#+LATEX_TABLE_SCI_NOTATION: \num{%se%s}
 #+end_src

 #+texinfo: @noindent
@@ -14850,7 +14853,12 @@ engineering format =m.mmmEnn=. The first string placeholder(=%s=) in
 ~org-latex-table-scientific-notation~ will be replaced by the mantissa
 and the second by the exponent. *Note* that to use the example above, you
 will need to add the ~siunitx~ package to your
-~org-latex-packages-alist~.
+~org-latex-packages-alist~ or with:
+
+#+begin_src org
+,#+LATEX_HEADER: \usepackage{siunitx}
+#+end_src
+

 *** Images in LaTeX export
 :PROPERTIES:
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 3120f7ed5..b569b13a4 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -470,6 +470,12 @@ It is up to the exporters to use this variable or not. Currently, it
 is used to add language information in the PDF metadata when exporting
 through ox-latex or ox-beamer.

+*** New keyword ~#+LATEX_TABLE_SCI_NOTATION~
+
+This new keyword allows you to set the variable
+~org-latex-table-scientific-notation~ in the document header and
+control how numbers in scientific notation are shown in the document.
+
 ** 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 f9b9981e6..76095d4ff 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -163,7 +163,7 @@ (org-export-define-backend 'latex
     (:latex-prefer-user-labels nil nil org-latex-prefer-user-labels)
     (:latex-subtitle-format nil nil org-latex-subtitle-format)
     (:latex-subtitle-separate nil nil org-latex-subtitle-separate)
-    (:latex-table-scientific-notation nil nil org-latex-table-scientific-notation)
+    (:latex-table-scientific-notation "LATEX_TABLE_SCI_NOTATION" nil org-latex-table-scientific-notation)
     (:latex-tables-booktabs nil nil org-latex-tables-booktabs)
     (:latex-tables-centered nil nil org-latex-tables-centered)
     (:latex-text-markup-alist nil nil org-latex-text-markup-alist)
@@ -928,7 +928,8 @@ (defcustom org-latex-table-scientific-notation nil
   :package-version '(Org . "8.0")
   :type '(choice
 	  (string :tag "Format string")
-	  (const :tag "No formatting" nil)))
+	  (const :tag "No formatting" nil))
+  :safe #'string-or-null-p)

 ;;;; Lists

diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index b2cf44cae..0bd1b7075 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -755,5 +755,24 @@ (ert-deftest test-ox-latex/alt-attribute ()
    (should (search-forward "It has a second line!}" nil t))
    (should (search-forward "]{./image.png}" nil t))))

+(ert-deftest test-ox-latex/sci-notation ()
+  "Test the #+LATEX_TABLE_SCI_NOTATION keyword."
+  (org-test-with-exported-text
+   'latex
+   "#+LATEX_TABLE_SCI_NOTATION: \\num{%se%s}
+
+My table is:
+
+#+attr_latex: :align cccc
+|            r |           F |             q |         n |
+|         3.00 |        68.0 |          2.00 |  3.81e+12 |
+
+Looks nice, doesn't it?
+"
+   ;; (message "sci-notation: %s" (buffer-string))
+   (goto-char (point-min))
+   (should (search-forward "\\begin{tabular}"))
+   (should (search-forward "2.00 & \num{3.81e+12}"))))
+
 (provide 'test-ox-latex)
 ;;; test-ox-latex.el ends here
--
2.53.0

Reply via email to