emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* MathJax extension does not work
@ 2021-10-10  9:14 Rudolf Adamkovič
  2021-10-10 17:40 ` Daniel Fleischer
  2023-03-28  4:34 ` chris
  0 siblings, 2 replies; 5+ messages in thread
From: Rudolf Adamkovič @ 2021-10-10  9:14 UTC (permalink / raw)
  To: emacs-orgmode

I would like to use the "\mathclap" command from the "mathtools" package in my Org document. In LaTeX, it works. For HTML, I visited the Org manual [1] where I saw the following example:

#+HTML_MATHJAX: cancel.js noErrors.js

with a comment "it loads the two MathJax extensions ‘cancel.js’ and ‘noErrors.js’ [132]." (As a side-note, the first link in [132] points to 404.) Thus, I put the following into my Org file

#+HTML_MATHJAX: mathtools.js

but it seems to do nothing; the exported HTML code not even contain the word "mathtools".

A file that demonstrates the problem:

#+LATEX_HEADER: \usepackage{mathtools}
#+HTML_MATHJAX: mathtools.js

\begin{equation*}
\begin{aligned}
\lim_{R\to0}F_1
=\lim_{R\to0}\frac{2PR}{P+R}
=\lim_{R\to0}\frac{2\cdot0\cdot{}R}{0+R}
=\lim_{R\to0}\frac{0}{R},
=\underbrace{\lim_{R\to0}\frac{0}{1}}_{\mathclap{\text{by L'Hôpital's Rule with $\frac{d}{dR}R=1$}}}
=\lim_{R\to0}0
=0.
\end{aligned}
\end{equation*}

Rudy

[1] https://orgmode.org/manual/Math-formatting-in-HTML-export.html

-- 
"Logic is a science of the necessary laws of thought, without which no employment of the understanding and the reason takes place." -- Immanuel Kant, 1785

Rudolf Adamkovič <salutis@me.com>
Studenohorská 25
84103 Bratislava
Slovakia

[he/him]


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

* Re: MathJax extension does not work
  2021-10-10  9:14 MathJax extension does not work Rudolf Adamkovič
@ 2021-10-10 17:40 ` Daniel Fleischer
  2021-10-10 18:11   ` Daniel Fleischer
  2021-10-10 19:39   ` Rudolf Adamkovič
  2023-03-28  4:34 ` chris
  1 sibling, 2 replies; 5+ messages in thread
From: Daniel Fleischer @ 2021-10-10 17:40 UTC (permalink / raw)
  To: Rudolf Adamkovič; +Cc: emacs-orgmode

Rudolf Adamkovič <salutis@me.com> writes:

> I would like to use the "\mathclap" command from the "mathtools" package in my Org document. In LaTeX, it works. For

Hi, there are 2 problems: first the mathtools.js library was introduced in
mathjax 3.2 but org provided version 2.7 as can be seen in the HTML

#+begin_src html
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
#+end_src

One can use the newer mathjax by replacing this with
#+begin_src html
<script type="text/javascript" id="MathJax-script" async
  src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>
#+end_src

as seen in https://docs.mathjax.org/en/latest/web/start.html.

You can just change the "path" in 'org-html-mathjax-options'.


Secondly, mathtools is not autoloaded so you need to call it; for
example you can put it in org using "export" block. 

#+begin_src HTML
<script>
window.MathJax = {
  loader: {load: ['[tex]/mathtools']},
  tex: {packages: {'[+]': ['mathtools']}}
};
</script>
#+end_src

After that it worked.

Not sure why the "#+HTML_MATHJAX: mathtools.js" doesn't do anything.
Need further investigation. 

-- 

Daniel Fleischer


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

* Re: MathJax extension does not work
  2021-10-10 17:40 ` Daniel Fleischer
@ 2021-10-10 18:11   ` Daniel Fleischer
  2021-10-10 19:39   ` Rudolf Adamkovič
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Fleischer @ 2021-10-10 18:11 UTC (permalink / raw)
  To: Rudolf Adamkovič; +Cc: emacs-orgmode

Daniel Fleischer <danflscr@gmail.com> writes:

> Not sure why the "#+HTML_MATHJAX: mathtools.js" doesn't do anything.
> Need further investigation. 

After examining the function 'org-html--build-mathjax-config' in
'ox-html.el' and also looking at the default values of

- 'org-html-mathjax-options'
- 'org-html-mathjax-template'

I don't see any code that loads mathjax extensions; which means
the documentation in

https://orgmode.org/manual/Math-formatting-in-HTML-export.html

is not accurate. That's my understanding.

-- 

Daniel Fleischer


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

* Re: MathJax extension does not work
  2021-10-10 17:40 ` Daniel Fleischer
  2021-10-10 18:11   ` Daniel Fleischer
@ 2021-10-10 19:39   ` Rudolf Adamkovič
  1 sibling, 0 replies; 5+ messages in thread
From: Rudolf Adamkovič @ 2021-10-10 19:39 UTC (permalink / raw)
  To: emacs-orgmode

Daniel Fleischer <danflscr@gmail.com> writes:

> […] the mathtools.js library was introduced in mathjax 3.2 but org provided version 2.7 […]
> You can just change the "path" in 'org-html-mathjax-options'.

I see. I tried the following and it worked:

(with-eval-after-load 'ox-html
  (add-to-list 'org-html-mathjax-options
               '(path "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js")))

> Secondly, mathtools is not autoloaded so you need to call it; for
> example you can put it in org using "export" block.
>
> #+begin_src HTML

The "export" blocks did not work for me, but the following did:

(setq-default org-html-head "
  <script>
  window.MathJax = {
    loader: {load: ['[tex]/mathtools']},
    tex: {packages: {'[+]': ['mathtools']}}
  };
  </script>")

> After that it worked.
> Not sure why the "#+HTML_MATHJAX: mathtools.js" doesn't do anything.

All the above makes using MathJax extensions impractical. I would have to include HTML hacks in my Org documents or tie the documents to my Emacs configuration, if I understand everything. Neither sounds right, and thus I will avoid using "modern" MathJax until Org switches to it and HTML_MATHJAX actually works.

P.S. I wonder why Org uses MathJax 2.x when other popular tools, such as Pandoc, use the latest one.

Thank you for your help!

Rudy

-- 
"'Contrariwise,' continued Tweedledee, 'if it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic.'" -- Lewis Carroll, Through the Looking Glass

Rudolf Adamkovič <salutis@me.com>
Studenohorská 25
84103 Bratislava
Slovakia

[he/him]


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

* Re: MathJax extension does not work
  2021-10-10  9:14 MathJax extension does not work Rudolf Adamkovič
  2021-10-10 17:40 ` Daniel Fleischer
@ 2023-03-28  4:34 ` chris
  1 sibling, 0 replies; 5+ messages in thread
From: chris @ 2023-03-28  4:34 UTC (permalink / raw)
  To: emacs-orgmode

On Sunday, 10 October 2021 11:14:24 CEST Rudolf Adamkovič wrote:
> I would like to use the "\mathclap" command from the "mathtools" package in my Org document. In LaTeX, it works. For HTML, I visited the Org manual [1] where I saw the following example:
> 
> #+HTML_MATHJAX: cancel.js noErrors.js
> 
> with a comment "it loads the two MathJax extensions ‘cancel.js’ and ‘noErrors.js’ [132]." (As a side-note, the first link in [132] points to 404.) Thus, I put the following into my Org file
> 
> #+HTML_MATHJAX: mathtools.js
> 

With similar scenario I ended up with:
(and `mathjax` extensions work very well)

```org-mode
#+STARTUP: latexpreview

#+BEGIN_EXPORT html
<script>
window.MathJax = {
  loader: {
    paths: {unicodeMath:
            'https://cdn.jsdelivr.net/npm/@amermathsoc/mathjax-unicode-math@1/browser'},
    load: ['[tex]/mathtools', '[unicodeMath]/unicode-math.js']},
    tex: {packages: {'[+]': ['mathtools', 'unicode-math']}}};
</script>
#+END_EXPORT

\begin{array}{ccc}
  \underset{\longrightarrow}{\lim}^f(\alpha_1 \circ p_1)
  &\overset{\underset{\longrightarrow}{\lim}^f \phi}{\longrightarrow}&
  \underset{\longrightarrow}{\lim}^f(\alpha_2 \circ p_2)
  \\
    {}^{\mathllap{\simeq}}\downarrow
    &&
    \downarrow^{\mathrlap{\simeq}}
    \\
    \underset{\longrightarrow}{\lim}^f \alpha_1
    &\underset{f}{\longrightarrow}&
    \underset{\longrightarrow}{\lim}^f \alpha_2
\end{array}

(diagram above from: [[https://ncatlab.org/nlab/show/ind-object][ind-object in nLab]])

\(\Bbbc\)

This above uses the other extension, unicode-math.
```

It works when exporting to `latex` and then `pdf`,
it works very well when exporting to `html` via `org-html-export-to-html`,
it almost works with `org-latex-preview`.

Here the relevant part of my `config.org`:

```org-mode
#+begin_src emacs-lisp
  (with-eval-after-load 'org
      (add-to-list 'org-latex-packages-alist '("" "stmaryrd" t))
      (add-to-list 'org-latex-packages-alist '("" "tikz-cd" t))
      (add-to-list 'org-latex-packages-alist '("" "amscd" t))
      (add-to-list 'org-latex-packages-alist '("" "mathtools" t))
      (add-to-list 'org-latex-packages-alist '("" "unicode-math" t))
      ;; (add-to-list 'org-latex-packages-alist '("" "breqn" t))
      (add-to-list 'org-latex-packages-alist '("" "thisisastupidtestfile" t))
      (setq org-latex-create-formula-image-program 'dvisvgm)
      (setq org-format-latex-options
            (plist-put org-format-latex-options :scale 0.80)))
#+end_src
```

`thisisastupidtestfile.sty` contains a few straightforward macro of the sort of `\newcommand{\calT}{\mathcal{T}}`.

Everything works save `unicode-math` which doesn't work with anything `dvi`.

I use `dvisvgm` because it allows `tikz` to work with `org-latex-preview`.

Cheers,
Chris


> but it seems to do nothing; the exported HTML code not even contain the word "mathtools".
> 
> A file that demonstrates the problem:
> 
> #+LATEX_HEADER: \usepackage{mathtools}
> #+HTML_MATHJAX: mathtools.js
> 
> \begin{equation*}
> \begin{aligned}
> \lim_{R\to0}F_1
> =\lim_{R\to0}\frac{2PR}{P+R}
> =\lim_{R\to0}\frac{2\cdot0\cdot{}R}{0+R}
> =\lim_{R\to0}\frac{0}{R},
> =\underbrace{\lim_{R\to0}\frac{0}{1}}_{\mathclap{\text{by L'Hôpital's Rule with $\frac{d}{dR}R=1$}}}
> =\lim_{R\to0}0
> =0.
> \end{aligned}
> \end{equation*}
> 
> Rudy
> 
> [1] https://orgmode.org/manual/Math-formatting-in-HTML-export.html
> 
> 






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

end of thread, other threads:[~2023-03-28  4:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-10  9:14 MathJax extension does not work Rudolf Adamkovič
2021-10-10 17:40 ` Daniel Fleischer
2021-10-10 18:11   ` Daniel Fleischer
2021-10-10 19:39   ` Rudolf Adamkovič
2023-03-28  4:34 ` chris

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