From 3cf6b644f2b7d806b15dd5e76914b1547ef77a96 Mon Sep 17 00:00:00 2001
From: thibault
Date: Sat, 2 Nov 2019 02:12:38 -0400
Subject: [PATCH] ox-html: Add equation numbers only for numbered environments
* lisp/ox-html.el (org-html-latex-environment): Add caption to numbered
environments only
(org-html--latex-environment-numbered-p): Determine whether a latex
environment should be numbered.
---
etc/ORG-NEWS | 8 ++++++++
lisp/ox-html.el | 32 ++++++++++++++++++++++----------
2 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index e61b97fa5..f20e4ea98 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -21,6 +21,14 @@ just as if it was at outline level 0. Inheritance for properties will
work also for this level. In other words: defining things in a
property drawer before the first headline will make them "inheritable"
for all headlines.
+
+*** Restrict the addition of a label to LaTeX equations in HTML export to numbered environments only
+
+Prevent the addition of a label to LaTeX math environments in HTML
+export when not in a numbered environment (numbered environment are
+everything but =displaymath= and environments ending with a star
+character, e.g. =equation*=).
+
** New functions
*** ~org-columns-toggle-or-columns-quit~
== bound to ~org-columns-toggle-or-columns-quit~ replaces the
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 83d0fd2e9..2f2210aa1 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2914,19 +2914,31 @@ For instance, change an 'equation' environment to 'equation*'."
latex-frag nil nil 1)
nil nil 1))
+(defun org-html--latex-environment-numbered-p (element)
+ "Non-nil if ELEMENT contains a numbered LaTeX math environment.
+
+Environments with a star (*) character and displaymath are not numbered."
+ (not (string-match-p
+ "\\`[ \t]*\\\\begin{\\(.*\\*\\|displaymath\\)}"
+ (org-element-property :value element))))
+
(defun org-html-latex-environment (latex-environment _contents info)
"Transcode a LATEX-ENVIRONMENT element from Org to HTML.
CONTENTS is nil. INFO is a plist holding contextual information."
- (let ((processing-type (plist-get info :with-latex))
- (latex-frag (org-remove-indentation
- (org-element-property :value latex-environment)))
- (attributes (org-export-read-attribute :attr_html latex-environment))
- (label (and (org-element-property :name latex-environment)
- (org-export-get-reference latex-environment info)))
- (caption (number-to-string
- (org-export-get-ordinal
- latex-environment info nil
- #'org-html--math-environment-p))))
+ (let* ((processing-type (plist-get info :with-latex))
+ (latex-frag (org-remove-indentation
+ (org-element-property :value latex-environment)))
+ (attributes (org-export-read-attribute :attr_html latex-environment))
+ (label (and (org-element-property :name latex-environment)
+ (org-export-get-reference latex-environment info)))
+ (caption (when (org-html--latex-environment-numbered-p
+ latex-environment)
+ (number-to-string
+ (org-export-get-ordinal
+ latex-environment info nil
+ (lambda (l info)
+ (and (org-html--math-environment-p l)
+ (org-html--latex-environment-numbered-p l))))))))
(cond
((memq processing-type '(t mathjax))
(org-html-format-latex
--
2.24.0