rNeomy / reader-view

Access Firefox's built in reader view from right click context menu
https://webextension.org/listing/chrome-reader-view.html
Mozilla Public License 2.0
471 stars 74 forks source link

Mathematical equations are not spoken correctly #168

Open hackerb9 opened 1 year ago

hackerb9 commented 1 year ago

The problem

Currently, using reader-view to listen to web pages that have mathematics in them is broken. For example, here is an article which discusses the quadratic equation: https://www.quantamagazine.org/the-symmetry-that-makes-solving-math-equations-easy-20230324

That page uses \frac{-b\pm \sqrt{b^2-4ac}}{2a} as the MathML "plain source" for

\frac{-b\pm \sqrt{b^2-4ac}}{2a}

Unfortunately, depending upon your browser's MathML renderer setting, reader-view may display it as:

−b±√b2−4ac2a

And, even when it doesn't look mangled, it always comes out as gibberish when reader-view passes it to text-to-speech. Although the exact details depend on what voice is chosen, what I'm hearing from reader-view right now is:

Exclamation mark minus exclamation mark b plus minus exclamation mark root exclamation mark b two exclamation mark minus exclamation mark four a c two a

Possible solution

Fortunately, this may be a solved problem. Here is a demo of how one can convert equations into speech:

https://mathjax.github.io/MathJax-demos-web/speech-generator/convert-with-speech.html

For example, pasting in \frac{-b\pm \sqrt{b^2-4ac}}{2a}, gives us the following Clearspeak text that can be sent to TTS:

the fraction with numerator negative b plus or minus the square root of b squared minus 4 a c and denominator 2 a

Of course, that's a bit verbose, so it'd be nice if reader-view had an option to use Mathspeak instead which can be super-brief:

Frac negative b plus or minus Root b squared minus 4 a c EndRoot Over 2 a EndFrac