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]> 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
From db15291372a9f0ad12f01d97125974f4e6b67f51 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--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'.
(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 | 23 ++++++++++++++++-------
testing/lisp/test-ox-latex.el | 28 +++++++++++++++++++++++++++-
4 files changed, 57 insertions(+), 17 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index cd902079e..3e52515dc 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -14990,13 +14990,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 fe61de9df..be0cf1a33 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 f669885a0..454ac9e88 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."
@@ -3749,8 +3753,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.
@@ -3762,13 +3766,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
@@ -3780,6 +3784,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)))
@@ -3818,6 +3823,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)))
@@ -4365,7 +4371,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")
@@ -4631,6 +4637,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..46f2d76f4 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