Hello,
The other day I wanted to do some additional styling of LaTeX (MathJax)
elements, however, I noticed that none of them were actually captured in any
HTML tag or CSS class, making this a bit cumbersome.
So I spent a bit of time to look things up and see if this could be fixed
and
came up with the attached patch, which wraps all LaTeX fragments in a <span
class="equation"> tag. Ideally, one should probably have separate CSS
classes
for inline fragments and full environments, but I wasn't really able to
figure
out how to separate those.
Also, I don't know if this interferes with anything else, but it seems to
work
fine in some pretty big org-mode files for me at least.
Below is also a simple test org-mode file, in case someone wants to try it
out
or add more test cases.
#+TITLE: LaTeX to HTML Math Tests
#+OPTIONS:
* Environments
This section should contain some supported MathJax environments.
\begin{equation}
e = mc^{2}
\end{equation}
\begin{equation*}
f = ma
\end{equation*}
* Inline
In this section we are talking about inline math, such as the
equations \(e = mc^{2}\) or $f = ma$, which were proposed by some
famous person.
Best regards,
Gustaf
Emacs : GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.20, cairo version 1.16.0)
of 2023-04-04
Package: Org mode version 9.6.2 (release_9.6.2 @
/home/guswal01/.local/share/emacs/30.0.50/lisp/org/)
current state:
==============
(setq
org-link-elisp-confirm-function 'yes-or-no-p
org-directory "/home/guswal01/.config/emacs/org/"
org-bibtex-headline-format-function #[257 "\300 \236A\207" [:title] 3
"\n\n(fn ENTRY)"]
org-log-into-drawer t
org-latex-images-centered nil
org-persist-after-read-hook '(org-element--cache-persist-after-read)
org-export-before-parsing-hook '(org-attach-expand-links)
org-cycle-tab-first-hook '(org-babel-hide-result-toggle-maybe
org-babel-header-arg-expand)
org-archive-hook '(org-attach-archive-delete-maybe)
org-odt-format-inlinetask-function
'org-odt-format-inlinetask-default-function
org-ascii-format-drawer-function #[771 " \207" [] 4 "\n\n(fn NAME CONTENTS
WIDTH)"]
org-cycle-hook '(org-cycle-hide-archived-subtrees
org-cycle-show-empty-lines
org-cycle-optimize-window-after-visibility-change
org-cycle-display-inline-images)
org-persist-before-read-hook '(org-element--cache-persist-before-read)
org-modules '(org-tempo ol-w3m ol-bbdb ol-bibtex ol-docview ol-gnus
ol-info ol-irc ol-mhe ol-rmail
ol-eww)
org-mode-hook '(#[0 " \205
From 4827ab1faca73ea9fba1031bfc5713c100f23bd3 Mon Sep 17 00:00:00 2001
From: Gustaf Waldemarson <[email protected]>
Date: Thu, 11 May 2023 10:49:57 +0200
Subject: [PATCH] ox-html: Wrap LaTeX fragments in a span.
It is sometimes useful to control the styling or post-processing of
LaTeX environments.
---
lisp/ox-html.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index b519402b1..504c49213 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -3012,7 +3012,7 @@ INFO is a plist containing export properties."
:to-buffer (get-buffer-create " *Org HTML Export LaTeX*")
:drop-visibility t :drop-narrowing t :drop-contents t
(erase-buffer)
- (insert latex-frag)
+ (insert (format "<span class=\"equation\">%s</span>" latex-frag))
(org-format-latex cache-relpath nil nil cache-dir nil
"Creating LaTeX Image..." nil processing-type)
(buffer-string))))
--
2.25.1