Subject: bug#73641: closed (Re: bug#73641: 30.0.90; Math in EWW/shr)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 31 Oct 2024 10:22:02 +0000

Your bug report

#73641: 30.0.90; Math in EWW/shr

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
73641: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=73641
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#73641: 30.0.90; Math in EWW/shr
From: Eli Zaretskii <[email-masked]>
To: Augusto Stoffel <[email-masked]>
Cc: [email-masked], [email-masked], [email-masked]
Date: Thu, 31 Oct 2024 12:21:11 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Augusto Stoffel <[email-masked]>
> Cc: [email-masked],  [email-masked],  [email-masked]
> Date: Tue, 29 Oct 2024 07:44:42 +0100
> 
> On Sun, 27 Oct 2024 at 12:25, Eli Zaretskii wrote:
> 
> >> From: Augusto Stoffel <[email-masked]>
> >> Cc: [email-masked],  [email-masked],  [email-masked]
> >> Date: Sat, 12 Oct 2024 19:13:48 +0200
> >> 
> >> On Sat, 12 Oct 2024 at 18:07, Eli Zaretskii wrote:
> >> 
> >> > Thanks, but can we please have a comment here explaining why we do
> >> > that?
> >> 
> >> How about this?
> >
> > As I said, this LGTM, but I'm unsure how you'd like to proceed.
> > Should I install this, and you will follow up with some code which
> > uses this new function?
> 
> >From my perspective it can be installed, and no follow up code is
> needed.  At some point shr calls (intern (format "shr-tag-%s" ...)), so
> the code that uses the new function is already there.

Thanks, installed on master, and closing the bug.

Subject: 30.0.90; Math in EWW/shr
From: Augusto Stoffel <[email-masked]>
To: [email-masked]
Date: Sat, 05 Oct 2024 16:01:36 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

shr has a tendency to display garbled math formulas.  For example
opening https://developer.mozilla.org/en-US/docs/Web/MathML/Examples/MathML_Pythagorean_Theorem
in EWW shows this:

> if a and b are the legs and c is the hypotenuse, then a2+b2=c2a^2 +
> b^2 = c^2.

This happens because <math> HTML elements tend to contain a MathML
description of the formula and possibly some "annotations", so what we
see above is "a2+b2=c2", the naive rendering of the MathML, concatenated
with "a^2 + b^2 = c^2" which is an annotation saying what the formula is
in TeX notation.

So in as a first improvement I would like to suggest adding this
definition:

  (defun shr-tag-math (dom)
    (shr-generic (thread-first
                   dom
                   (dom-child-by-tag 'semantics)
                   (dom-child-by-tag 'annotation)
                   (or dom))))

The above page then gets rendered like this:

> Specifically, if a and b are the legs and c is the hypotenuse, then
> a^2 + b^2 = c^2.

In other words, only the TeX annotation is displayed, which is as good
as it gets when trying to show math as plain text, IMO.

It is possible for the <math> element to include a SVG rendition of the
formula.  We could consider displaying that if available (not sure how
common it is, though).  Also, we might consider including infrastructure
to render MathML, but this would require external programs (there is no
reason to reinvent MathJax).  I've done that in one of my packages, see
this commit for the relevant code:

https://github.com/astoff/devdocs.el/commit/04a8793072f1fc7c23f115e2c7ee83ce669b6fa4

(Actually, I added a version of the above to two of my packages already,
so I think it's pretty clear Emacs should have some general
math-rendering infrastructure.)