emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Gustaf Waldemarson <gustaf.waldemarson@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [BUG] Wrap LaTeX Fragments in a Span [9.6.2 (release_9.6.2)]
Date: Thu, 11 May 2023 11:19:49 +0200	[thread overview]
Message-ID: <CABehr5feupHR=dub8s0U=J9R_dr5sW3ddsm_BzBKZKs6xRwqag@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 2523 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 2964 bytes --]

[-- Attachment #2: 0001-ox-html-Wrap-LaTeX-fragments-in-a-span.patch --]
[-- Type: text/x-patch, Size: 979 bytes --]

From 4827ab1faca73ea9fba1031bfc5713c100f23bd3 Mon Sep 17 00:00:00 2001
From: Gustaf Waldemarson <gustaf.waldemarson@gmail.com>
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


             reply	other threads:[~2023-05-11  9:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-11  9:19 Gustaf Waldemarson [this message]
2023-05-11 15:04 ` [BUG] Wrap LaTeX Fragments in a Span [9.6.2 (release_9.6.2)] Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABehr5feupHR=dub8s0U=J9R_dr5sW3ddsm_BzBKZKs6xRwqag@mail.gmail.com' \
    --to=gustaf.waldemarson@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).