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

From: Augusto Stoffel <[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?

>From 0d3f0ad219e9cd0c9f79113d137cab5bbdeed2e1 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <[email-masked]>
Date: Sat, 12 Oct 2024 16:20:47 +0200
Subject: [PATCH] shr.el: Define rendering rule for math tag

* lisp/net/shr.el (shr-tag-math): New function, see bug#73641.
---
 lisp/net/shr.el | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index f1062acf7e4..0c37ef67bbb 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -2264,6 +2264,18 @@ shr-tag-bdi
   (shr-generic dom)
   (insert ?\N{POP DIRECTIONAL ISOLATE}))
 
+(defun shr-tag-math (dom)
+  ;; Sometimes a math element contains a plain text annotation
+  ;; (typically TeX notation) in addition to MathML markup.  If we pass
+  ;; that to `dom-generic', the formula is printed twice.  So we select
+  ;; only the annotation if available.
+  (shr-generic
+   (thread-first
+     dom
+     (dom-child-by-tag 'semantics)
+     (dom-child-by-tag 'annotation)
+     (or dom))))
+
 ;;; Outline Support
 (defun shr-outline-search (&optional bound move backward looking-at)
   "A function that can be used as `outline-search-function' for rendered html.
-- 
2.46.2