Hi
Attached is a patch to allow the 'align' and 'align*' environments for
aligned tables.
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 b5b87852017b5209b17f86678791d55bfb43fddb Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <[email protected]>
Date: Mon, 9 Nov 2026 17:38:36 +0100
Subject: [PATCH] ox-latex: New math* mode for tables
* doc/org-manual.org (* Tables in LaTeX export): Document 'math*' mode.
* etc/ORG-NEWS: Announce new 'math*' mode for tables.
* lisp/ox-latex.el (org-latex-default-table-mode): Add 'math-star' for
matrices that are exported unescaped.
(org-latex--wrap-latex-matrices): Add 'math-star' to markup options.
(org-latex-matrices): Implement 'math-star'
(org-latex-table): 'math*' are also math tables.
* testing/lisp/test-ox-latex.el (test-ox-latex/latex-math-star): New
test for math* mode.
(test-ox-latex/pdf-metadata): Fix typo irrelevant to results.
Reported-by: Pedro A. Aranda <[email protected]>
Link: https://list.orgmode.org/[email protected]
---
doc/org-manual.org | 11 +++++++----
etc/ORG-NEWS | 12 +++++++-----
lisp/ox-latex.el | 16 +++++++++++-----
testing/lisp/test-ox-latex.el | 28 +++++++++++++++++++++++++++-
4 files changed, 52 insertions(+), 15 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index 145a7b927..8299b6003 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -15035,13 +15035,16 @@ include:
#+vindex: org-latex-default-table-mode
The LaTeX export backend wraps the table differently depending on
the mode for accurate rendering of math symbols. Mode is either
- =table=, =math=, =inline-math=, =verbatim= or =tabbing=.
+ =table=, =math=, =math*= =inline-math=, =verbatim= or =tabbing=.
For =math= or =inline-math= mode, LaTeX export backend wraps the
table in a math environment, but every cell in it is exported as-is.
- For =tabbing= the LaTeX tabbing environment is used and the correct
- tabbing delimiters =\>= are used.
- The LaTeX export backend determines the default mode from
+ The =math*= mode behaves like similarly, but without wrapping the
+ table in any sort of math environment[fn::This should be used for
+ the =align=, =align*= or other environments, where inlining results
+ in a LaTeX error.]. For =tabbing= the LaTeX tabbing environment is
+ used and the correct tabbing delimiters =\>= are used. The LaTeX
+ export backend determines the default mode from
~org-latex-default-table-mode~. The LaTeX export backend merges
contiguous tables in the same mode into a single environment.
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 50bc9e51f..d2daa4cee 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -114,12 +114,14 @@ the correct ~(FILE . ...)~ cons.
*** When using LaTeX preview for math snippets, =ox-html= embeds equation numbers into images
-Previously, equation numbers were generated in plain HTML, wrapped into ~equation-label~ class.
-Now, this is not longer the case when math snippets are exported with
-LaTeX preview (see ~org-html-with-latex~). The equation numbers are a
-part of the image itself there.
+The multi-line equation environments =align= and =align*= are now usable
+for an equation table, like for example:
-The ~mathml~ processing still produces in-HTML numbering.
+#+begin_src org
+,#+attr_latex: :mode math :environment align*
+| f(x) = | x^2 + 2*x + 1 |
+| = | (x+1)^2 |
+#+end_src
** New features
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index ba8067b5d..4a8bb2dbc 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -871,6 +871,9 @@ (defcustom org-latex-default-table-mode 'table
`inline-math' This mode is almost the same as `math', but the
math environment will be inlined.
+ `math-star' This mode is almost the same as `math', but the
+ math environment neither be wrapped or inlined.
+
`verbatim' The table is exported as it appears in the Org
buffer, within a verbatim environment.
@@ -885,8 +888,9 @@ (defcustom org-latex-default-table-mode 'table
:type '(choice (const :tag "Table" table)
(const :tag "Matrix" math)
(const :tag "Inline matrix" inline-math)
+ (const :tag "Bare matrix" math-star)
(const :tag "Verbatim" verbatim))
- :safe #'(lambda (s) (memq s '(table math inline-math verbatim))))
+ :safe #'(lambda (s) (memq s '(table math inline-math math-star verbatim))))
(defcustom org-latex-tables-centered t
"When non-nil, tables are exported in a center environment."
@@ -4191,8 +4195,8 @@ (defun org-latex-property-drawer (_property-drawer contents _info)
;;;; Pseudo Element: LaTeX Matrices
;; `latex-matrices' elements have the following properties:
-;; `:caption', `:post-blank' and `:markup' (`inline', `equation' or
-;; `math').
+;; `:caption', `:post-blank' and `:markup' (`inline', `equation',
+;; `math' or `math-star').
(defun org-latex--wrap-latex-matrices (data info)
"Merge contiguous tables with the same mode within a pseudo-element.
@@ -4204,7 +4208,7 @@ (defun org-latex--wrap-latex-matrices (data info)
(when (eq (org-element-property :type table) 'org)
(let ((mode (or (org-export-read-attribute :attr_latex table :mode)
(plist-get info :latex-default-table-mode))))
- (when (and (member mode '("inline-math" "math"))
+ (when (and (member mode '("inline-math" "math" "math*"))
;; Do not wrap twice the same table.
(not (org-element-type-p
(org-element-parent table) 'latex-matrices)))
@@ -4222,6 +4226,7 @@ (defun org-latex--wrap-latex-matrices (data info)
:markup
(cond ((string= mode "inline-math") 'inline)
((or caption name) 'equation)
+ ((string= mode "math*") 'math-star)
(t 'math)))))
(previous table)
(next (org-export-get-next-element table info)))
@@ -4260,6 +4265,7 @@ (defun org-latex-matrices (matrices contents info)
channel."
(pcase (org-element-property :markup matrices)
(`inline (format "\\(%s\\)" contents))
+ (`math-star contents)
(`equation
(let ((caption (org-latex--caption/label-string matrices info))
(caption-above? (org-latex--caption-above-p matrices info)))
@@ -4807,7 +4813,7 @@ (defun org-latex-table (table contents info)
(org-trim (org-element-interpret-data
`(table nil ,@(org-element-contents table))))))
;; Case 2: Matrix.
- ((or (string= type "math") (string= type "inline-math"))
+ ((member type '("math" "math*" "inline-math"))
(org-latex--math-table table info))
;; Case 3: Tabbing
((string= type "tabbing")
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 043d379a5..59dd26f6a 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -561,7 +561,7 @@ (ert-deftest test-ox-latex/pdf-metadata ()
'latex
"#+TITLE: PDF Metadata
#+LANGUAGE: en-gb
-#+OTHER_LANGUAGE: es
+#+OTHER_LANGUAGES: es
#+OPTIONS: toc:nil H:3 num:nil
#+LATEX_COMPILER: pdflatex
#+LATEX_DOC_METADATA: tagging = on, lang=%l
@@ -816,6 +816,32 @@ (ert-deftest test-ox-latex/protected-in-sections ()
(search-forward
"\\section{This is a \\texttt{section} with \\texttt{verbatim} and \\underline{underline}}"))))
+(ert-deftest test-ox-latex/latex-math-star ()
+ "Check that the align* environment is NOT surrounded by
+inline math \\[\\] delimiters."
+ (org-test-with-exported-text
+ 'latex
+ "* A multi-line equation using the =math*= mode
+We want a simple way for multiline equations:
+
+#+attr_latex: :mode math* :environment align*
+| f(x) = | x^3 + 3*x^2 + 3*x + 1 |
+| = | (x^2 + 2*x + 1) * (x+1) |
+
+This is a simple way to align multi-line equations. =align*= is provided by
+the ~amsmath~ package.
+"
+ ;; (message "latex-math-star: %s" (buffer-string))
+ (goto-char (point-min))
+ (search-forward "equations:\n")
+ (search-forward "\\begin{align*}\n")
+ (search-forward "f(x) = & x^3 + 3*x^2 + 3*x + 1 \\")
+ (search-forward " = & (x^2 + 2*x + 1) * (x+1) \\")
+ (search-forward "\\end{align*}
+
+This is a simple")
+ ))
+
(ert-deftest test-ox-latex/lualatex-fontspec-default-features ()
"Test that fontspec default features are generated
when fontspec is used in LaTeX document."
--
2.53.0