all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [BUG] Wrap LaTeX Fragments in a Span [9.6.2 (release_9.6.2)]
@ 2023-05-11  9:19 Gustaf Waldemarson
  2023-05-11 15:04 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Gustaf Waldemarson @ 2023-05-11  9:19 UTC (permalink / raw)
  To: emacs-orgmode


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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [BUG] Wrap LaTeX Fragments in a Span [9.6.2 (release_9.6.2)]
  2023-05-11  9:19 [BUG] Wrap LaTeX Fragments in a Span [9.6.2 (release_9.6.2)] Gustaf Waldemarson
@ 2023-05-11 15:04 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2023-05-11 15:04 UTC (permalink / raw)
  To: Gustaf Waldemarson; +Cc: emacs-orgmode, Timothy

Gustaf Waldemarson <gustaf.waldemarson@gmail.com> writes:

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

See `org-html--wrap-latex-environment'.
`org-html-latex-environment' does wrap latex environments into equation
class, but not for mathjax processing type.

CCing the maintainer.

It looks reasonable to wrap Mathjax fragments as well. But there might
be non-obvious pitfalls.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-11 15:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-11  9:19 [BUG] Wrap LaTeX Fragments in a Span [9.6.2 (release_9.6.2)] Gustaf Waldemarson
2023-05-11 15:04 ` Ihor Radchenko

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.