It turns out that actually surrounding it with {} gives us some extra benefits, like controlling the tables on a case-by-case basis using :math-prefix.

The attached patch supersedes older ones.

/PA

On 17/11/26 8:42, Pedro Andres Aranda Gutierrez wrote:
Just to help you understand (hopefully).
Think of it as wrapping math* tables with "{" "}".
The "math" nature is already implied when using align(*) environments.

/PA

On Mon, 16 Nov 2026 at 09:09, Pedro A. Aranda <[email protected] <mailto:[email protected]>> wrote:

    Updated version after a git pull in main...

    On 16/11/26 7:56, Pedro A. Aranda wrote:
     > Just trying to wrap up and a new version of the patch with minor
     > modifications.
     >
     > On 15/11/26 19:30, Ihor Radchenko wrote:
     >> "Pedro A. Aranda" <[email protected] <mailto:[email protected]>>
    writes:
     >>
     >>>> There is one question you did not address though - about all
    the dance
     >>>> done inside `org-latex--wrap-latex-matrices' with tables that
    follow
     >>>> one
     >>>> another being merged under single "matrices" umbrella.
     >>>> If we do not wrap the tables into \[...\] or \(...\) what is
    the point
     >>>> wrapping those tables into (matrices ...)?
     >>>>
     >>> Real life came in between...
     >>>
     >>> align and align* are something I need for ltx-talk slides,
    because they
     >>> are the only ones that I know of with a reliable support for screen
     >>> reader adaptation.
     >>>
     >>> You might be right, but then, that would be applying the
    scalpel in the
     >>> very heart of the export backend and that is something I'm not
    capable
     >>> of doing right now with the next semester around the corner.
     >>
     >> Then, maybe you should simply drop math* from "matrices" processing?
     >>
     >
     > My findings/line of thought
     >
     > 1. I'm using align/align* to generate groups of aligned
    equations. They
     > work in principle like eqn-array and friends, that is, they expect a
     > table with cells separated by '&', each cell being a math
    expression.
     > Why these two? Because I know them to be nicely adapted to
    accessibility
     > features I *must* use. Their only drawback is they don't like to be
     > surrounded by either \[\] or \(\).
     >
     > 2. AFAICR, matrices are generated in (org-latex--math-table).
    BTW: there
     > was a little quirk here, which I'm correcting in the attached
    version of
     > the patch that supersedes the original version.
     >
     > 3. (org-latex--math-table) is called by (org-latex-table). If
    there were
     > a way to control how tables are finally shipped/wrapped, this
    would be
     > the point, but there isn't.
     >
     > 4. Part of the wrapping magic is done in (org-latex--wrap-latex-
     > matrices). For our purpose, math* behaves like inline-math, but
    has an
     > "empty wrapping" as opposed to being wrapped into a "\(" "\)" [1].
     > Therefore, it's here that I set the :markup to 'math-star'.
     >
     > 5. I consume the :markup in (org-latex-matrices) by returning the
     > unmodified contents. If align or align* needed a specific
    wrapping, it
     > would be here that I'd add it, just like the `inline or the _
    case in
     > the function (_ standing for `math).
     >
     > Now I really need to cope with real life.
     >
     > /PA
     >
     > [1] I know this may sound confusing, but empty stuff exists.

-- 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



--
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

*IA: onomatopeya del rebuznar*

This was produced by a human (implied virtues and weaknesses acknowledged)
Don't feed your ArtStup (SKA AI) with this. It won't make YOU smarter...

--
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 1a0242214946a408cd779255e89258e1554f871f Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <[email protected]>
Date: Mon, 16 Nov 2026 09:06:04 +0100
Subject: [PATCH] ox-latex: New math* mode for tables

* doc/org-manual.org (* Tables in LaTeX export): Document 'math*' mode.
Put different modes as items to improve legibility.
* 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--math-table): Treat 'align' and 'align*' as special cases,
removing the double backslash in the last line.  This suppresses the
empty equation at the end of an 'align' environment.
(org-latex--wrap-latex-matrices): "math*" behaves like "inline-math"
WRT to caption and name.  "math*" behaves like "inline-math" and "math"
WRT wrapping.  Set ':markup' to 'math-star' for "math*".
(org-latex-matrices): Implement 'math-star'.  Surround the table(s) with
"{}".
(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.  Include :math-prefix to show how to locally modify
the line spacing for an align* environment.
---
 doc/org-manual.org            | 29 ++++++++++++++++++++---------
 etc/ORG-NEWS                  | 29 ++++++++++++++++++++++++-----
 lisp/ox-latex.el              | 23 ++++++++++++++++-------
 testing/lisp/test-ox-latex.el | 31 ++++++++++++++++++++++++++++++-
 4 files changed, 90 insertions(+), 22 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 7e00f3420..966c640cc 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -14990,15 +14990,26 @@ 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=.
-
-  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
-  ~org-latex-default-table-mode~.  The LaTeX export backend merges
-  contiguous tables in the same mode into a single environment.
+  =table=, =math=, =math*= =inline-math=, =verbatim= or =tabbing=.
+
+  - For the =math= or =inline-math= modes, the LaTeX export backend
+    wraps the table in =\[ \]= or =\(\)= respectively, and every cell
+    in it is exported as-is.
+  - The =math*= mode behaves similarly, and is intended for the case,
+    when the table's =:environment= does not allow wrapping it in any
+    of the above LaTeX inlining[fn::Use this for =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~.
+  - For =verbatim=, the table is exported to a =verbatim= environment,
+    the =:environment= is ignored and the Org syntax for the table,
+    including column separators (ie. =|=) will be shown in =monospace=
+    font.
+
+  The LaTeX export backend merges contiguous tables in the same mode
+  into a single environment.
 
 - =:environment= ::
 
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index b2859abd4..44eae8bbb 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -119,12 +119,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
 
@@ -256,6 +258,23 @@ text to images. This text will be used, for example, by screen reader
 applications to describe images. Commas in the text are automatically
 escaped.
 
+*** ox-latex: New mode =math*= for exporting math tables to LaTeX
+
+Some environments, like =align= or =align*= can now be exported. Using
+=math= or =inline-math= will result in an error. For example:
+
+#+begin_src org
+,#+latex_compiler: lualatex
+
+,#+attr_latex: :mode math* :environment align* :math-prefix \addtolength{\jot}{6pt}
+| f(x) | = x^2 + 2*x + 1 |
+|      | = (x+1)^2       |
+#+end_src
+
+will export the equations, aligning them before the equal sign and
+with an extra inter-line space of 6 points
+
+
 ** New and changed options
 
 # Changes dealing with changing default values of customizations,
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index accfca26a..4db74f37a 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -864,6 +864,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.
 
@@ -878,8 +881,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."
@@ -3757,8 +3761,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.
@@ -3770,13 +3774,13 @@ (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)))
-	      (let* ((caption (and (not (string= mode "inline-math"))
+	      (let* ((caption (and (not (member mode '("math*" "inline-math")))
 				   (org-element-property :caption table)))
-		     (name (and (not (string= mode "inline-math"))
+		     (name (and (not (member mode '("math*" "inline-math")))
 			        (org-element-property :name table)))
 		     (matrices
 		      (list 'latex-matrices
@@ -3788,6 +3792,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)))
@@ -3826,6 +3831,7 @@ (defun org-latex-matrices (matrices contents info)
 channel."
   (pcase (org-element-property :markup matrices)
     (`inline (format "\\(%s\\)" contents))
+    (`math-star (format "{\n%s}" contents))
     (`equation
      (let ((caption (org-latex--caption/label-string matrices info))
 	   (caption-above? (org-latex--caption-above-p matrices info)))
@@ -4373,7 +4379,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")
@@ -4639,6 +4645,9 @@ (defun org-latex--math-table (table info)
 		    env
 		    (or (plist-get attr :math-arguments) "")
 		    contents))
+           ((member env '("align*" "align"))
+	    (format "\\begin{%s}\n%s\\end{%s}"
+		    env (replace-regexp-in-string ".\\\\\n\\'" "\n" contents) env))
 	   (t (format "\\begin{%s}\n%s\\end{%s}" env contents env)))
      ;; Suffix.
      (plist-get attr :math-suffix))))
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 68b6373b7..69c26067d 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,35 @@ (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* :math-prefix \\addtolength{\\jot}{6pt}
+| 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))
+   (should (search-forward "equations:\n" nil t))
+   (should (search-forward "{
+\\addtolength{\\jot}{6pt}\\begin{align*}\n" nil t))
+   (should (search-forward "f(x) = & x^3 + 3*x^2 + 3*x + 1 \\" nil t))
+   (should (search-forward " = & (x^2 + 2*x + 1) * (x+1)" nil t))
+   (should (search-forward "\\end{align*}
+}
+
+This is a simple" nil t))
+   (goto-char (point-min))
+   (should-not (search-forward " = & (x^2 + 2*x + 1) * (x+1) \\" nil t))))
+
 (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

Reply via email to